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

# Chat completions

> POST /chat/completions — OpenAI-compatible streaming and non-streaming chat.

## Endpoint

```
POST /api/v1/chat/completions
```

OpenAI-compatible chat. Supports streaming and non-streaming responses.

## Request body

| Field                | Type    | Description                                                      |
| -------------------- | ------- | ---------------------------------------------------------------- |
| `model`              | string  | Model id from `GET /models`                                      |
| `messages`           | array   | OpenAI-style message objects                                     |
| `stream`             | boolean | Default `false` for pure OpenAI clients; set `true` for SSE      |
| `temperature`        | number  | Optional sampling                                                |
| `top_p`              | number  | Optional nucleus sampling                                        |
| `max_tokens`         | integer | Optional max output tokens                                       |
| `icelake_parameters` | object  | Optional [Icelake extensions](/api-reference/icelake-parameters) |

## Example

<CodeGroup>
  ```bash cURL theme={null}
  curl https://chat.icelake.io/api/v1/chat/completions \
    -H "Authorization: Bearer $ICELAKE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "zai-org-glm-5-2",
      "messages": [{"role": "user", "content": "Hello"}],
      "stream": false,
      "max_tokens": 256
    }'
  ```

  ```ts TypeScript theme={null}
  const res = await client.chat.completions.create({
    model: "zai-org-glm-5-2",
    messages: [{ role: "user", content: "Hello" }],
    stream: false,
    max_tokens: 256,
  });
  ```

  ```python Python theme={null}
  res = client.chat.completions.create(
      model="zai-org-glm-5-2",
      messages=[{"role": "user", "content": "Hello"}],
      stream=False,
      max_tokens=256,
  )
  ```
</CodeGroup>

## Streaming

Set `stream: true`. Response is `text/event-stream` with OpenAI-style chunks, ending with:

```
data: [DONE]
```

## Response headers

| Header                       | Meaning                             |
| ---------------------------- | ----------------------------------- |
| `x-request-id`               | Support / debugging id              |
| `x-icelake-model-id`         | Resolved public model id            |
| `x-icelake-balance-credits`  | Wallet balance after reserve/charge |
| `x-ratelimit-limit-requests` | Configured RPM for the key          |

## Billing

API key chat usage is metered in **credits** (not free daily chat quotas used by the web app).
