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

# Chat Completions

> Generate a chat response from a model.

## Request body

<ParamField body="model" type="string" required>
  Model ID to use. See [available models](/models/overview).
</ParamField>

<ParamField body="messages" type="array" required>
  Array of message objects with `role` and `content`.

  * `role`: `"system"`, `"user"`, or `"assistant"`
  * `content`: The message text
</ParamField>

<ParamField body="temperature" type="number" default="1">
  Sampling temperature (0-2). Lower = more focused, higher = more creative.
</ParamField>

<ParamField body="max_tokens" type="number">
  Maximum tokens to generate in the response.
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  Stream response tokens as server-sent events.
</ParamField>

<ParamField body="top_p" type="number" default="1">
  Nucleus sampling parameter (0-1).
</ParamField>

## Response

```json theme={null}
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "llama-3.3-70b-versatile",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 10,
    "total_tokens": 30
  }
}
```

<RequestExample>
  ```bash cURL theme={null}
  curl https://kymaapi.com/v1/chat/completions \
    -H "Authorization: Bearer ky-your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "llama-3.3-70b",
      "messages": [
        {"role": "user", "content": "Hello!"}
      ]
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI
  client = OpenAI(base_url="https://kymaapi.com/v1", api_key="ky-your-api-key")
  response = client.chat.completions.create(
      model="llama-3.3-70b",
      messages=[{"role": "user", "content": "Hello!"}]
  )
  ```
</RequestExample>
