Chat completions
Region
POST /v1/chat/completions. The request and response follow the OpenAI shape.
Request fields
| Field | Meaning |
|---|---|
| model | A model id from Models. Required. |
| messages | Messages with role and content. Roles: system, user, assistant, tool. Required. |
| stream | Send the response as server-sent events. Default false. |
| temperature | 0 to 2. Default 1. |
| max_tokens | Cap on output tokens. Default is the model's limit. |
| response_format | {"type": "json_object"} for JSON mode. |
| tools | Function definitions. See Tools. |
| tool_choice | auto, none, or a named function. |
| stop | Up to 4 sequences that end the output. |
| user | Your own id for the end user. Kept in the usage record. Not a prompt. |
Example
POST /v1/chat/completions
curl https://au.api.safeailabs.ai/v1/chat/completions \
-H "Authorization: Bearer $SAFE_AI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-flash",
"messages": [
{"role": "system", "content": "Answer in one sentence."},
{"role": "user", "content": "What is a token?"}
],
"temperature": 0.2,
"max_tokens": 200
}'200
{
"id": "req_01J8Z5",
"object": "chat.completion",
"created": 1789516931,
"model": "deepseek-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "A token is the unit of text a model reads and writes, roughly three quarters of a word."
},
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 21, "completion_tokens": 22, "total_tokens": 43 }
}DeepSeek Reasoner returns its thinking as reasoning_content on the message, before content. Thinking tokens are counted in completion_tokens and charged at the output rate.