Back to Docs

API Reference

Complete reference for the POST /v1/chat/completions endpoint.

POST/v1/chat/completions

Message roles

Each object in the "messages" array has a "role" that defines who is speaking.

system

Sets the behavior and personality of the assistant.

user

The human message input.

assistant

The AI response. Used for conversation history.

tool

Response from a tool/function call.

Parameters

modelstringRequired

The model ID to use. See /docs/models for available models.

Example: "qwen3.8-max"
messagesarrayRequired

Array of message objects. Each has a "role" (system, user, assistant, tool) and "content".

Example: [{"role":"user","content":"Hi"}]
streambooleanOptional

If true, the response is streamed via server-sent events. Default: false.

Example: true
temperaturenumberOptional

Sampling temperature between 0 and 2. Higher values = more random. Default: 1.

Example: 0.7
max_tokensintegerOptional

Maximum tokens to generate in the response.

Example: 1024
toolsarrayOptional

Array of tool definitions in OpenAI function-calling format.

Example: [{"type":"function","function":{...}}]
tool_choicestring | objectOptional

"auto", "none", or {"type":"function","function":{"name":"..."}} to force a specific tool.

Example: "auto"
enable_thinkingbooleanOptional

If true, skips the reasoning/thinking step on models that support it (e.g., DeepSeek R1).

Example: true
sizestringOptional

Aspect ratio for image/video generation models (e.g., "1024x1024", "16:9").

Example: "1024x1024"
watermarkboolean | stringOptional

false removes the watermark from image models. A string replaces the default watermark text.

Example: false

Response format

The response follows the standard OpenAI format. The "usage" field contains actual token counts reported by the model.

json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "qwen3.8-max",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "A closure is a function that retains access to variables from its enclosing scope..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 248,
    "total_tokens": 260
  }
}
choices[0].message.content— The response text.
choices[0].finish_reason— "stop" if completed normally, "length" if hit max_tokens.
usage.total_tokens— Total tokens consumed (prompt + completion).