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

# Chat Completions

> Generate text completions using 40+ LLMs. OpenAI-compatible request and response format.

## Request

```bash theme={null}
POST https://api.euron.one/api/v1/euri/chat/completions
```

### Headers

| Header          | Required | Description                |
| --------------- | -------- | -------------------------- |
| `Authorization` | Yes      | `Bearer YOUR_EURI_API_KEY` |
| `Content-Type`  | Yes      | `application/json`         |

### Body parameters

<ParamField body="model" type="string" required>
  Model ID to use. See [Models](/models) for the full list.
</ParamField>

<ParamField body="messages" type="array" required>
  Array of message objects representing the conversation.

  Each message has:

  * `role` — `"system"`, `"user"`, or `"assistant"`
  * `content` — The message text (string)
</ParamField>

<ParamField body="max_tokens" type="integer">
  Maximum number of tokens to generate. Defaults to model maximum.
</ParamField>

<ParamField body="temperature" type="number">
  Sampling temperature between 0 and 2. Lower = more deterministic. Default: `0.7`.
</ParamField>

<ParamField body="stream" type="boolean">
  If `true`, returns a stream of Server-Sent Events (SSE). Default: `false`.
</ParamField>

<ParamField body="top_p" type="number">
  Nucleus sampling. Default: `1`.
</ParamField>

<ParamField body="frequency_penalty" type="number">
  Penalize repeated tokens. Range: -2.0 to 2.0. Default: `0`.
</ParamField>

<ParamField body="presence_penalty" type="number">
  Penalize tokens already present. Range: -2.0 to 2.0. Default: `0`.
</ParamField>

<ParamField body="stop" type="string | array">
  Up to 4 sequences where the API will stop generating.
</ParamField>

<ParamField body="n" type="integer">
  Number of completions to generate. Default: `1`.
</ParamField>

<ParamField body="tools" type="array">
  List of tools (functions) the model can call. OpenAI function-calling format.
</ParamField>

<ParamField body="tool_choice" type="string | object">
  Controls tool usage: `"auto"`, `"none"`, or a specific tool object.
</ParamField>

<ParamField body="response_format" type="object">
  Force output format. Example: `{"type": "json_object"}` for JSON mode.
</ParamField>

<ParamField body="seed" type="integer">
  Seed for deterministic sampling (best-effort).
</ParamField>

***

## Examples

### Basic chat

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.euron.one/api/v1/euri/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer YOUR_EURI_API_KEY" \
    -d '{
      "model": "gpt-4o-mini",
      "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain AGI in 2 simple lines."}
      ],
      "max_tokens": 200,
      "temperature": 0.7
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_EURI_API_KEY",
      base_url="https://api.euron.one/api/v1/euri"
  )

  response = client.chat.completions.create(
      model="gpt-4o-mini",
      messages=[
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Explain AGI in 2 simple lines."}
      ],
      max_tokens=200,
      temperature=0.7
  )

  print(response.choices[0].message.content)
  ```

  ```javascript JavaScript theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    apiKey: 'YOUR_EURI_API_KEY',
    baseURL: 'https://api.euron.one/api/v1/euri',
  });

  const response = await client.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [
      { role: 'system', content: 'You are a helpful assistant.' },
      { role: 'user', content: 'Explain AGI in 2 simple lines.' },
    ],
    max_tokens: 200,
    temperature: 0.7,
  });

  console.log(response.choices[0].message.content);
  ```
</CodeGroup>

### Streaming

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.euron.one/api/v1/euri/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer YOUR_EURI_API_KEY" \
    -d '{
      "model": "gemini-2.5-flash",
      "messages": [{"role": "user", "content": "Write a haiku about code."}],
      "stream": true
    }'
  ```

  ```python Python theme={null}
  stream = client.chat.completions.create(
      model="gemini-2.5-flash",
      messages=[{"role": "user", "content": "Write a haiku about code."}],
      stream=True
  )

  for chunk in stream:
      if chunk.choices[0].delta.content:
          print(chunk.choices[0].delta.content, end="")
  ```
</CodeGroup>

### Using Claude

```bash theme={null}
curl -X POST https://api.euron.one/api/v1/euri/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_EURI_API_KEY" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [{"role": "user", "content": "Compare REST and GraphQL."}],
    "max_tokens": 500
  }'
```

### Using Llama

```bash theme={null}
curl -X POST https://api.euron.one/api/v1/euri/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_EURI_API_KEY" \
  -d '{
    "model": "llama-4-scout-17b-16e-instruct",
    "messages": [{"role": "user", "content": "What is Rust good for?"}],
    "max_tokens": 300
  }'
```

***

## Response

```json theme={null}
{
  "id": "chatcmpl-58e31942-784a-4075-bfa9-0aad20692061",
  "object": "chat.completion",
  "created": 1744998577,
  "model": "gpt-4o-mini",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "AGI stands for Artificial General Intelligence..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 272,
    "completion_tokens": 145,
    "total_tokens": 417
  }
}
```

### Stream response

When `stream: true`, the response is a series of SSE events:

```
data: {"id":"chatcmpl-...","choices":[{"delta":{"content":"AGI"},"index":0}]}

data: {"id":"chatcmpl-...","choices":[{"delta":{"content":" stands"},"index":0}]}

data: [DONE]
```

***

## Errors

| Code  | Meaning                                                  |
| ----- | -------------------------------------------------------- |
| `400` | Missing `messages` or `model`, invalid parameters        |
| `401` | Invalid or missing API key                               |
| `403` | Daily token limit reached or insufficient wallet balance |
| `429` | Rate limited                                             |
| `500` | Upstream model error                                     |
