Source: https://ailoot.ai/docs/en/api/chat-completions/
Canonical: https://ailoot.ai/docs/en/api/chat-completions/
Language: en

[API](https://ailoot.ai/docs/en/) 

# Chat Completions

[Markdown](https://ailoot.ai/docs/en/api/chat-completions/index.md)

A model's response to a conversation in the OpenAI format. The most widely used format: almost all clients support it.

POST`https://api.ailoot.ai/v1/chat/completions`

Chat Completions

```bash
curl https://api.ailoot.ai/v1/chat/completions \
  -H "Authorization: Bearer $AILOOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "messages": [
      {"role": "user", "content": "Explain what an API is in two sentences."}
    ]
  }' 
```

```python
from openai import OpenAI
import os

client = OpenAI(max_retries=0, 
    base_url="https://api.ailoot.ai/v1",
    api_key=os.environ["AILOOT_API_KEY"],
)

resp = client.chat.completions.create(
    model="claude-sonnet-5-5",
    messages=[{"role": "user", "content": "Explain what an API is in two sentences."}],
)
print(resp.choices[0].message.content)
```

```js
import OpenAI from "openai";

const client = new OpenAI({ maxRetries: 0,
  baseURL: "https://api.ailoot.ai/v1",
  apiKey: process.env.AILOOT_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "claude-sonnet-5-5",
  messages: [{ role: "user", content: "Explain what an API is in two sentences." }],
});
console.log(resp.choices[0].message.content);
```

200 OK

```json
{
  "id": "chatcmpl-8f2c…",
  "object": "chat.completion",
  "created": 1790812800,
  "model": "claude-sonnet-5-5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "An API is an agreement on how one program asks another to do something…"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 21,
    "completion_tokens": 48,
    "total_tokens": 69
  }
}
```

## Authentication

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `Authorization` | header | required | The key in the format `Bearer sk-…`. The following headers also work: `x-api-key` or `x-goog-api-key`. |

## Request body

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `model` | string | required | Model ID from the [catalog](https://ailoot.ai/models/en/), for example `claude-sonnet-5-5`. The model must support the OpenAI Chat format. |
| `messages` | array | required | Conversation history: objects with `role` (`system`, `developer`, `user`, `assistant`, `tool`) and `content` — a string or an array of parts (text, `image_url`). |
| `stream` | boolean | optional | A response in the Server-Sent Events format. Defaults to `false`. Billable text is delivered in a single block after the cost is calculated, rather than word by word. |
| `stream_options` | object | optional | `{"include_usage": true}` — include the final `usage` as the last event in the stream. |
| `max_tokens` | integer | optional | Maximum response tokens. The newer name is `max_completion_tokens`. If no limit is set, Ailoot uses 4096 (or less if the model's response limit is lower; Grok has its own limit). For longer responses, set the limit explicitly; otherwise, the response stops at 4096 tokens with `finish_reason: "length"`. The limit is included in the reserve: the higher it is, the more available balance you need. |
| `temperature` | number | optional | Response randomness, usually from 0 to 2. Reasoning models may ignore it. |
| `top_p` | number | optional | An alternative to temperature: the fraction of probability mass used to select tokens. |
| `stop` | string \| array | optional | Strings that stop generation. |
| `tools` | array | optional | Definitions of functions the model can call. Uses the OpenAI format: `{"type": "function", "function": {...}}`. |
| `tool_choice` | string \| object | optional | `auto`, `none`, `required` or a specific function. |
| `response_format` | object | optional | `{"type": "json_object"}` or `{"type": "json_schema", ...}` for a structured response, if the model supports it. |
| `reasoning_effort` | string | optional | Reasoning depth for reasoning models: `low`, `medium`, `high`. |

Other OpenAI parameters are passed through unchanged; support for each parameter is determined by the model's developer.

## Response

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `choices[].message` | object |  | Model response: `content`, or for tool calls — `tool_calls`. |
| `choices[].finish_reason` | string |  | `stop` — the response is complete; `length` — reached `max_tokens` (the response is still considered complete and billed for actual usage); `tool_calls` — the model is calling a tool. |
| `usage` | object |  | `prompt_tokens`, `completion_tokens`, `total_tokens` — these are used to calculate the charge. |

Still have questions? Send your Request ID and a description — we'll help you troubleshoot.[Contact support](mailto:support@ailoot.ai)

## Ailoot · The company and its project portfolio





Ailoot combines established operating experience, a large client base, stable service and ongoing KPI control.





The company and its project portfolio: millions of customers; monthly sales in the billions.





Ailoot brings that operating experience to API access for AI features in customer products, agents, applications and automations.
