API
Chat completions
POST /chat/completions, OpenAI-compatible, with server-sent event streaming.
Request
`POST /chat/completions` takes the OpenAI request body. Allwit uses `model`, `messages` (string content, or text parts), `temperature`, `max_tokens` (or `max_completion_tokens`) and `stream`; other fields are accepted and ignored. Only `n: 1` is supported. Messages with the `developer` role are treated as `system`.
The whole conversation travels in `messages` every time: Allwit keeps no thread between requests. Send a `max_tokens` that fits your use; it is what gets reserved. Without it the model's default budget applies.
{
"id": "chatcmpl-…",
"object": "chat.completion",
"created": 1794300000,
"model": "qwen/qwen3.8-27b",
"choices": [{ "index": 0, "message": { "role": "assistant", "content": "…" }, "finish_reason": "stop" }],
"usage": { "prompt_tokens": 21, "completion_tokens": 48, "total_tokens": 69 },
"allwit": { "wit_charged": 1, "privacy_tier": "blind", "source": "provider_api" }
}Streaming
With `stream: true` the response is `text/event-stream`: `data:` lines carrying `chat.completion.chunk` objects, then `data: [DONE]`. The chunk before `[DONE]` has an empty `choices` array and carries `usage` and `allwit.wit_charged`, whether or not you ask for `stream_options.include_usage`. Moderation and the WIT reservation happen before the first byte, so 400, 402 and 429 arrive as plain JSON; a failure after streaming has started is a final `{"error": …}` event before `[DONE]`.
from openai import OpenAI
client = OpenAI(
base_url="https://www.allwit.ai/api/v1",
api_key="aw_live_…", # from /app/account/api-keys
)
stream = client.chat.completions.create(
model="qwen/qwen3.8-27b",
messages=[{"role": "user", "content": "Write a haiku about keys."}],
max_tokens=120,
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://www.allwit.ai/api/v1",
apiKey: process.env.ALLWIT_API_KEY, // aw_live_…
});
const stream = await client.chat.completions.create({
model: "qwen/qwen3.8-27b",
messages: [{ role: "user", content: "Write a haiku about keys." }],
max_tokens: 120,
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}curl -N https://www.allwit.ai/api/v1/chat/completions \
-H "Authorization: Bearer $ALLWIT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "qwen/qwen3.8-27b", "messages": [{"role": "user", "content": "Hello"}], "stream": true}'