Source: https://ailoot.ai/docs/en/api/messages/
Canonical: https://ailoot.ai/docs/en/api/messages/
Language: en

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

# Messages

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

The Anthropic Messages format. Used by Claude Code, the Anthropic SDK, and many agents.

POST`https://api.ailoot.ai/v1/messages`

Messages

```bash
curl https://api.ailoot.ai/v1/messages \
  -H "x-api-key: $AILOOT_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello! What can you do?"}]
  }' 
```

```python
import anthropic
import os

client = anthropic.Anthropic(max_retries=0, 
    base_url="https://api.ailoot.ai",   # without /v1: the SDK adds /v1/messages itself
    api_key=os.environ["AILOOT_API_KEY"],
)

msg = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain what an API is in two sentences."}],
)
print(msg.content[0].text)
```

```js
import Anthropic from "@anthropic-ai/sdk";

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

const msg = await client.messages.create({
  model: "claude-sonnet-5-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Explain what an API is in two sentences." }],
});
console.log(msg.content[0].type === "text" ? msg.content[0].text : msg.content);
```

200 OK

```json
{
  "id": "msg_01H…",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5-5",
  "content": [
    { "type": "text", "text": "Hello! I can write and explain code, answer questions…" }
  ],
  "stop_reason": "end_turn",
  "usage": { "input_tokens": 14, "output_tokens": 52 }
}
```

## Authentication

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `x-api-key` | header | required | Key `sk-…`. You can also use `Authorization: Bearer sk-…` — this is what Claude Code uses with `ANTHROPIC_AUTH_TOKEN`. |
| `anthropic-version` | header | optional | API version, for example `2023-06-01`. SDKs send it automatically. |

## Request body

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `model` | string | required | Model ID that supports the Messages format — 776 IDs: Claude, as well as GPT, Gemini, DeepSeek, Qwen, and others. |
| `messages` | array | required | Messages `user` and `assistant`; `content` — a string or blocks (`text`, `image`, `tool_use`, `tool_result`). |
| `max_tokens` | integer | required | Maximum number of response tokens. Included in the reserve; if your balance is too low for the full limit, Ailoot reduces it, but never below 256 (1025 with thinking enabled), and reports the new limit in the header `X-Ailoot-Max-Tokens-Capped`. |
| `system` | string \| array | optional | System instruction. |
| `stream` | boolean | optional | SSE event stream (`message_start`, `content_block_delta`, …, `message_stop`). Billable text is delivered in a single block after the cost is calculated. |
| `temperature` | number | optional | Response randomness, from 0 to 1. |
| `tools` | array | optional | Tools: `name`, `description`, `input_schema`. |
| `tool_choice` | object | optional | `auto`, `any`, `tool` or `none`. |
| `thinking` | object | optional | `{"type": "enabled", "budget_tokens": N}` — thinking for models that support it. |
| `stop_sequences` | array | optional | Strings that stop generation. |

## Response

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `content` | array |  | Response blocks: `text`, `thinking`, `tool_use`. |
| `stop_reason` | string |  | `end_turn`, `max_tokens`, `stop_sequence` or `tool_use`. |
| `usage` | object |  | `input_tokens`, `output_tokens`, for caching — `cache_read_input_tokens` and `cache_creation_input_tokens`. |

Token counting (`POST /v1/messages/count_tokens`) is currently unavailable for models in the catalog.

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.
