Chat Completions
OpenAI-compatible chat completions via POST /v1/chat/completions.
Authentication
POST /v1/chat/completions requires Authorization: Bearer <API_KEY>. Gateway base URL: https://api.misar.dev.
The gateway accepts the standard OpenAI chat completions request and returns an OpenAI-shaped response, so the stock OpenAI SDK works with only a changed base URL. Under the hood, requests are routed through the cascading MoE engine.
/v1/chat/completionsGenerate a chat completion. Set stream: true for an incremental text/event-stream; otherwise a single JSON object is returned.
Request body
modelstringbodyModel id to route to. Defaults to the gateway's configured DEFAULT_MODEL (e.g. qwen3:8b) when omitted.
messagesArray<{role, content, name?}>bodyrequiredConversation messages. content is a string, or an array of content parts (text, image_url, file) for multimodal input. image_url accepts a data: URI or a remote URL; file accepts { filename, data (base64), mime_type }.
max_tokensintegerbodyMaximum tokens to generate. Defaults to the gateway OPENAI_MAX_TOKENS (4096).
temperaturenumberbodyAccepted for compatibility. Routing does not force a temperature — each provider applies its own default.
streambooleanbodydefault: falseWhen true, responses stream as OpenAI SSE chunks ending with data: [DONE].
toolsArray<object>bodyOpenAI-format tool/function definitions.
tool_choicestring | objectbodyControls tool selection, forwarded to the router.
reasoning_effortstringbodyReasoning-effort knob: none, minimal, low, medium, high, or xhigh. When unset, the effort is auto-derived from the last user message (floored at medium). A nested reasoning: { "effort": "..." } object is also accepted; the top-level field wins.
Response fields (non-streaming)
idstringCompletion id, e.g. chatcmpl-....
objectstringchat.completion (non-streaming) or chat.completion.chunk (streaming).
modelstringThe model actually used to serve the request.
choicesArray<{index, message, finish_reason}>The generated choice(s). message is { role: "assistant", content }.
usage{ prompt_tokens, completion_tokens, total_tokens }Token accounting for the request.
curl https://api.misar.dev/v1/chat/completions \
-H "Authorization: Bearer $MISARCODER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3:8b",
"messages": [{ "role": "user", "content": "Write a haiku about caching." }],
"reasoning_effort": "low"
}'{
"id": "chatcmpl-8f2a1c9d4e6b7a3f9c1d2e5b",
"object": "chat.completion",
"created": 1753900000,
"model": "qwen3:8b",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Bytes rest in warm store..." },
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 14, "completion_tokens": 17, "total_tokens": 31 }
}data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Bytes"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]Tool calls
When the model calls a tool, streaming chunks carry delta.tool_calls (with the function name, then streamed arguments fragments) and the stream ends with finish_reason: "tool_calls".
Status codes
200— Completion returned (or stream opened).401— Missing or invalid API key.502— Upstream model error.503— Model router not initialized.504— Request timed out.