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

# Chat Completions protocol

> Common OpenAI-compatible chat request, response, and streaming rules.

Create a model response from a list of chat messages. Choose an exact model page under **Text Series** for pricing and the recommended model ID.

<ParamField body="model" type="string" required>
  A text model ID available to your API key. Use
  [`GET /v1/models`](/api-reference/list-models) to discover IDs, then open its
  individual model page for current pricing.
</ParamField>

<ParamField body="messages" type="array" required>
  Ordered chat messages. Each message includes a `role` and `content`.
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  Set to `true` to receive server-sent events.
</ParamField>

<ParamField body="temperature" type="number">
  Controls sampling variation. Lower values are more deterministic.
</ParamField>

<ParamField body="max_tokens" type="integer">
  Caps generated tokens when supported by the selected model.
</ParamField>

## Stream a response

Set `stream` to `true`. The response uses server-sent events (SSE).

```bash theme={null}
curl -N https://api.snapgen.org/v1/chat/completions \
  -H "Authorization: Bearer sk-xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4-mini",
    "messages": [
      {"role": "user", "content": "Say hello in three words."}
    ],
    "stream": true
  }'
```

Each event begins with `data:`. Read events until the `data: [DONE]` marker.

```text theme={null}
data: {"id":"chatcmpl_01HXYZ","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl_01HXYZ","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" from SnapGen"},"finish_reason":null}]}

data: [DONE]
```

<Tip>
  Concatenate `choices[0].delta.content` values as they arrive. A delta can omit `content`, especially in the first or final event.
</Tip>

<RequestExample>
  ```bash Curl theme={null}
  curl https://api.snapgen.org/v1/chat/completions \
    -H "Authorization: Bearer sk-xxxx" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-5.4-mini",
      "messages": [
        {
          "role": "system",
          "content": "You answer in one concise sentence."
        },
        {
          "role": "user",
          "content": "What is an API gateway?"
        }
      ],
      "temperature": 0.2,
      "max_tokens": 100
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "chatcmpl_01HXYZ",
    "object": "chat.completion",
    "created": 1730000000,
    "model": "gpt-5.4-mini",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "An API gateway is a service that provides one interface for routing requests to one or more APIs."
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 25,
      "completion_tokens": 19,
      "total_tokens": 44
    }
  }
  ```
</ResponseExample>
