Docs / API
Chat Completions
POST /v1/chat/completions in the OpenAI format, with streaming, tools and JSON mode.
Last updated
Your setup
Fills in YOUR_API_KEY in the code on this page. The key stays in this tab: it is never sent and never saved.
Endpoint
POST https://api.cent-ai.dev/v1/chat/completions
Authorization: Bearer cai_<secret>
Content-Type: application/json
The endpoint follows the OpenAI Chat Completions format. Point any OpenAI SDK or tool at the base URL https://api.cent-ai.dev/v1.
Request
| Field | Required | What Cent AI does with it |
|---|---|---|
model | yes | Picks the model and its prices. An unknown name returns 404 model_not_found |
messages | yes | Sent to the model as is |
stream | no | true returns server-sent events, see Long streaming |
stream_options.include_usage | no | true adds the final usage chunk, with usage.cost, to the stream |
max_tokens, max_completion_tokens | no | Sent as is |
tools, tool_choice, response_format, reasoning_effort and others | no | Sent as is |
Parameters are passed to the model unchanged. A parameter the model does not support comes back as the model's error, with the HTTP status it returned.
Example
curl https://api.cent-ai.dev/v1/chat/completions \
-H "Authorization: Bearer $CENT_AI_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"glm-5.3","messages":[{"role":"user","content":"Hello"}]}'
Response
{
"id": "chatcmpl-9f2c1a",
"object": "chat.completion",
"created": 1792051200,
"model": "glm-5.3",
"choices": [{
"index": 0,
"message": {"role": "assistant", "content": "Hello!"},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 10000,
"prompt_tokens_details": {"cached_tokens": 9000},
"completion_tokens": 800,
"total_tokens": 10800,
"cost": "0.000363000"
}
}
prompt_tokens includes cached tokens; cached_tokens is the part read from the cache and charged at the cache read rate. usage.cost is the amount charged, see Request cost.
Streaming
With stream: true, the response is text/event-stream. Chunks follow the OpenAI format and the stream ends with data: [DONE]:
: keepalive
data: {"id":"chatcmpl-9f2c1a","object":"chat.completion.chunk","created":1792051200,"model":"glm-5.3","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-9f2c1a","object":"chat.completion.chunk","created":1792051200,"model":"glm-5.3","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-9f2c1a","object":"chat.completion.chunk","created":1792051200,"model":"glm-5.3","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-9f2c1a","object":"chat.completion.chunk","created":1792051200,"model":"glm-5.3","choices":[],"usage":{"prompt_tokens":10000,"prompt_tokens_details":{"cached_tokens":9000},"completion_tokens":800,"total_tokens":10800,"cost":"0.000363000"}}
data: [DONE]
The usage chunk is sent only when stream_options.include_usage is true.
Status codes
| Status | When |
|---|---|
| 200 | Success, streamed or not |
| 400 | The request body is not valid (invalid_request) |
| 401, 402, 403, 404, 413, 429 | See 4xx errors |
| 503 | The model failed before the first byte was sent, see 5xx errors |
Contract
POST/v1/chat/completions
Chat completions (OpenAI format)
Auth · API key (Bearer or x-api-key)
Request body
max_completion_tokensintegeroptionalmax_tokensintegeroptionalmessagesobject[]requiredmodelstringrequiredstreambooleanoptionalstream_optionsobjectoptionalstream_options.include_usagebooleanoptionalSends the final usage chunk, with usage.cost, to the client.
Responses
- 200Completion, or an SSE stream of
chat.completion.chunkframes ending withdata: [DONE]. - 400Error in the OpenAI shape.
- 401Error in the OpenAI shape.
- 402Error in the OpenAI shape.
- 403Error in the OpenAI shape.
- 404Error in the OpenAI shape.
- 413Error in the OpenAI shape.
- 429Error in the OpenAI shape that may be retried after Retry-After.retry
- 500Error in the OpenAI shape.
- 503Error in the OpenAI shape that may be retried after Retry-After.retry
Response headers
Retry-Afterx-ratelimit-limitx-ratelimit-remainingx-ratelimit-resetx-request-id
Generated from the OpenAPI contract.