Chat Completions
The workhorse route. One request shape, JSON or streamed, with token accounting written to your ledger.
| Field | Type | Notes |
|---|---|---|
model | string, required | Model id from GET /v1/models. |
messages | array, required | Ordered list of { role, content }. Roles: system, user, assistant, tool. |
stream | boolean | true returns text/event-stream chunks ending in data: [DONE]. |
temperature | number | Sampling randomness. Lower for extraction, higher for ideation. |
max_tokens | number | Caps completion length. The gateway validates the value before dispatch. |
tools | array | Function definitions: { type: "function", function: { name, description?, parameters? } }. Rejected if the model cannot call tools. |
tool_choice | string | object | Lets the model pick, forces a specific function, or disables tools entirely. |
Response
{
"id": "chatcmpl-8f2…",
"object": "chat.completion",
"created": 1757000123,
"model": "YOUR_MODEL_ID",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "Because short wavelengths scatter more." },
"finish_reason": "stop"
}],
"usage": { "prompt_tokens": 42, "completion_tokens": 18, "total_tokens": 60 }
}Tool calls
{
"model": "YOUR_MODEL_ID",
"messages": [{ "role": "user", "content": "What is the weather in Berlin?" }],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
}
}]
}The assistant reply then contains tool_calls. Execute them, append a role: "tool" message with the result, and call the endpoint again — the standard loop every OpenAI-compatible client already implements.