> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trustqai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat completions

> POST /v1/chat/completions generates a reply to a conversation.

`POST /v1/chat/completions` sends a conversation to a model and returns its reply, in the OpenAI chat completions format. The cost of each request comes off your [credit](https://docs.trustqai.com/platform/credit.md).

## Request

```bash theme={null}
curl https://api.trustqai.com/v1/chat/completions \
  -H "Authorization: Bearer $QAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qai/qwen3.8-27b",
    "messages": [
      {"role": "system", "content": "You answer in one sentence."},
      {"role": "user", "content": "What is a context window?"}
    ],
    "max_tokens": 1024
  }'
```

### Body

**model** `string` *required*

The model name, as listed by [GET /models](https://docs.trustqai.com/api-reference/list-models.md).

**messages** `array` *required*

The conversation so far: objects with a `role` (`system`, `user` or `assistant`) and `content`.

**max\_tokens** `integer`

The most tokens the reply can use. For models that think, this includes the thinking.

**temperature** `number`

Sampling temperature. Higher values give more varied replies.

**top\_p** `number`

Nucleus sampling: only tokens within this cumulative probability are considered.

**stream** `boolean`

Return the reply as server-sent events while it is generated. See [Streaming](#streaming).

**stream\_options** `object`

With `stream`, set `include_usage` to `true` to receive token usage in the final event.

**tools** `array`

Functions the model may call, in the OpenAI tools format.

**tool\_choice** `string | object`

Whether and which tool the model must call.

**chat\_template\_kwargs** `object`

Model-specific options. For Qwen models, `{"enable_thinking": false}` turns thinking off. See [Models](https://docs.trustqai.com/platform/models.md#thinking).

> [!NOTE]
>
> Which options a model honours depends on the model. Fields not listed here are passed to the model unchanged.

## Response

```json theme={null}
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "qai/qwen3.8-27b",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "A context window is the amount of text a model can consider at once.",
        "reasoning_content": "..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 27,
    "completion_tokens": 148,
    "total_tokens": 175
  }
}
```

**choices\[].message.content** `string`

The reply.

**choices\[].message.reasoning\_content** `string`

The model's thinking, for models that think. Absent when thinking is off.

**choices\[].finish\_reason** `string`

`stop` when the model finished, `length` when it reached `max_tokens`.

**usage** `object`

Prompt, completion and total tokens: what the request is charged for.

## Streaming

With `"stream": true`, the response is a stream of server-sent events. Each event is a `data:` line with a JSON chunk whose `choices[0].delta` holds the next piece of the reply (`content`) or of the thinking (`reasoning_content`). The stream ends with `data: [DONE]`.

```bash theme={null}
curl https://api.trustqai.com/v1/chat/completions \
  -H "Authorization: Bearer $QAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qai/qwen3.8-27b",
    "messages": [{"role": "user", "content": "Count to five."}],
    "stream": true,
    "stream_options": {"include_usage": true}
  }'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.