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

# Chat completions

> Create OpenAI-compatible chat completions and streams.

<Info>
  Base URL: `https://api.freemodel.app/v1`
</Info>

Create a model response from a list of chat messages.

## Create a completion

`POST /chat/completions`

```bash theme={null}
curl https://api.freemodel.app/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
  }'
```

```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
  }
}
```

## Request body

| Field         | Type    | Required | Description                                                                 |
| ------------- | ------- | -------- | --------------------------------------------------------------------------- |
| `model`       | string  | Yes      | A model ID available to your API key. Use `GET /v1/models` to discover IDs. |
| `messages`    | array   | Yes      | Ordered chat messages. Each message includes a `role` and `content`.        |
| `stream`      | boolean | No       | Set to `true` to receive server-sent events. Defaults to `false`.           |
| `temperature` | number  | No       | Controls sampling variation. Lower values are more deterministic.           |
| `max_tokens`  | integer | No       | Caps generated tokens when supported by the selected model.                 |

## Stream a response

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

```bash theme={null}
curl -N https://api.freemodel.app/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 FreeModel"},"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>
