1. Get a credential
For a server, ask a Mayfair administrator for a service key (it starts mfk_live_ and is shown once). Keep it in an environment variable:
export ARTEMII_KEY="mfk_live_..."For a browser app, use the signed-in person's Mayfair ID access token instead. See Authentication.
2. Send a request
curl
curl https://mayfair-ai.crelloo.workers.dev/v1/chat/completions \
-H "Authorization: Bearer $ARTEMII_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"arlo","messages":[{"role":"system","content":"Answer in one sentence."},{"role":"user","content":"What is Mayfair?"}]}'The answer is the OpenAI chat completion shape:
{
"id": "chatcmpl-...", "object": "chat.completion", "created": 1762257600, "model": "arlo",
"choices": [{ "index": 0, "message": { "role": "assistant", "content": "Hello!" }, "finish_reason": "stop" }],
"usage": { "prompt_tokens": 120, "completion_tokens": 12, "total_tokens": 132 }
}JavaScript
Use the SDK (a single file, no dependencies), or plain fetch.
import { createClient } from './artemii.js';
const ai = createClient({ baseUrl: 'https://mayfair-ai.crelloo.workers.dev', apiKey: process.env.ARTEMII_KEY });
const reply = await ai.chat({ model: 'arlo', messages: [{ role: 'user', content: 'Hello' }] });
console.log(reply.choices[0].message.content);Python
Use the OpenAI client library against the Artemii base URL. Set base_url to the gateway with /v1 on the end.
import os
from openai import OpenAI
client = OpenAI(base_url="https://mayfair-ai.crelloo.workers.dev/v1", api_key=os.environ["ARTEMII_KEY"])
reply = client.chat.completions.create(model="arlo", messages=[{"role": "user", "content": "Hello"}])
print(reply.choices[0].message.content)3. Stream the answer
curl -N https://mayfair-ai.crelloo.workers.dev/v1/chat/completions \
-H "Authorization: Bearer $ARTEMII_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"arlo","stream":true,"messages":[{"role":"user","content":"Hello"}]}'With the SDK:
import { createClient } from './artemii.js';
const ai = createClient({ baseUrl: 'https://mayfair-ai.crelloo.workers.dev', apiKey: process.env.ARTEMII_KEY });
for await (const part of ai.chat({ model: 'arlo', stream: true, messages: [{ role: 'user', content: 'Tell me a story' }] })) {
process.stdout.write(part.choices[0]?.delta?.content ?? '');
}
// or collect the whole text and render each piece as it arrives
const text = await ai.chatText({ model: 'arlo', messages: [{ role: 'user', content: 'Hello' }] }, (piece) => process.stdout.write(piece));
console.log('\n' + text.length + ' characters');With Python:
import os
from openai import OpenAI
client = OpenAI(base_url="https://mayfair-ai.crelloo.workers.dev/v1", api_key=os.environ["ARTEMII_KEY"])
stream = client.chat.completions.create(model="arlo", stream=True, messages=[{"role": "user", "content": "Hello"}])
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="")
print()The wire format is described on the Streaming page.
4. Check what you can use
curl https://mayfair-ai.crelloo.workers.dev/v1/models \
-H "Authorization: Bearer $ARTEMII_KEY"curl https://mayfair-ai.crelloo.workers.dev/v1/me \
-H "Authorization: Bearer $ARTEMII_KEY"/v1/models lists only the models your credential may use. /v1/me says who the credential is and what is left of its allowance.
The first request after a quiet period can be slow
If the model is asleep, the first call can take a while. A streamed request stays open while it starts (up to 8 minutes). A non-streamed request waits up to the gateway limit and then answers 503 model_starting with a Retry-After header. Retry after that time.