Contents

Chat completions

Region

POST /v1/chat/completions. The request and response follow the OpenAI shape.

Request fields

FieldMeaning
modelA model id from Models. Required.
messagesMessages with role and content. Roles: system, user, assistant, tool. Required.
streamSend the response as server-sent events. Default false.
temperature0 to 2. Default 1.
max_tokensCap on output tokens. Default is the model's limit.
response_format{"type": "json_object"} for JSON mode.
toolsFunction definitions. See Tools.
tool_choiceauto, none, or a named function.
stopUp to 4 sequences that end the output.
userYour 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.