# Claude Native API (Anthropic Messages)

> Official docs: [Create a Message](https://platform.claude.com/docs/en/api/messages/create) | [Streaming](https://platform.claude.com/docs/en/build-with-claude/streaming) | [Thinking](https://platform.claude.com/docs/en/build-with-claude/thinking) | [Prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) | [Errors](https://platform.claude.com/docs/en/api/errors)

## 📝 Introduction

The Messages API is Anthropic's official conversation endpoint: you send a structured list of input messages (text, images, PDFs, tool results, and so on), and the model generates the next message in the conversation. The API is stateless, so multi-turn conversations must resend the full history on every request. BeeRoute relays this endpoint in Anthropic's native format, so the official SDKs and tools such as Claude Code work by simply pointing their base URL at BeeRoute.

This page covers the most common fields and usage. For the exhaustive field list, see the [official reference](https://platform.claude.com/docs/en/api/messages/create).

### Quick Notes

| Item | Details |
| --- | --- |
| Endpoint | `POST https://beeroute.ai/v1/messages` |
| Base URL | `https://beeroute.ai` (the Anthropic base URL to enter in SDKs, Claude Code and similar tools; do not append `/v1`) |
| Authentication | `x-api-key: $API_KEY` or `Authorization: Bearer $API_KEY` (either one) |
| Version header | `anthropic-version: 2023-06-01` (required; see the version notes below) |
| Content type | `content-type: application/json` |
| Get a key | [https://beeroute.ai/keys](https://beeroute.ai/keys) |
| Models and prices | [https://beeroute.ai/modellist/](https://beeroute.ai/modellist/) |

All curl examples below read the key from the `$API_KEY` environment variable. Set it first:

```bash
export API_KEY=sk-xxx
```

?> For direct API calls, use a key in the `default` group. Keys in the `ClaudeCode` group are meant for the Claude Code client only.

!> BeeRoute does not offer the token counting endpoint (`POST /v1/messages/count_tokens` returns 404), the Files API, or the Message Batches API.

**About API versions:** Anthropic's newest API version is `2026-10-21`; the earlier `2023-06-01` is still widely used. BeeRoute forwards your `anthropic-version` header unchanged. The examples on this page use `2023-06-01`, which has the broadest compatibility (it is also what Claude Code sends). Whether `2026-10-21` works depends on the upstream channel; if you get an error, switch back to `2023-06-01`. Breaking changes in `2026-10-21` compared with `2023-06-01` ([migration guide](https://platform.claude.com/docs/en/api/migration-2026-10-21)):

- `temperature`, `top_p`, and `top_k` are removed: sending any of them returns a 400 on every model, even at the default value;
- a `document` block placed directly in an `assistant` message returns a 400;
- a `text` block with a non-empty `citations` array in a `user` message (including inside a `search_result` block) returns a 400.

Also note that the new major versions of the official SDKs (Python `anthropic` 2.0.0 and later, TypeScript `@anthropic-ai/sdk` 1.0.0 and later) send `2026-10-21` by default and send the key as `Authorization: Bearer`. See the "Python SDK" section below.

### Available Models

Claude models currently available on BeeRoute:

`claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, `claude-fable-5-2`, `claude-opus-5`, `claude-sonnet-5`

Older versions (`claude-fable-5-1`, `claude-fable-5`, `claude-opus-4-8`, `claude-opus-4-7`, `claude-opus-4-6`, `claude-sonnet-4-6`, `claude-haiku-4-5-20251001`) can still be called for existing integrations. New projects should use the models above.

The examples on this page use `claude-sonnet-5-5`. Models differ in their support for thinking, sampling parameters, prefill, forced tool use, and so on; each difference is noted below.

## 💡 Request Examples

### Basic Text Conversation ✅

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $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, please introduce yourself in one sentence."}
    ]
  }'
```

**Response example:**

```json
{
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5-5",
  "content": [
    {
      "type": "text",
      "text": "Hi! I'm Claude, an AI assistant made by Anthropic that can help with writing, coding, analysis, and answering all kinds of questions."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "stop_details": null,
  "usage": {
    "input_tokens": 19,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0},
    "output_tokens": 32,
    "service_tier": "standard"
  }
}
```

?> `Authorization: Bearer $API_KEY` works the same as `x-api-key: $API_KEY`; the remaining examples do not repeat this. Response fields may be added as the upstream API evolves, so read fields by name and do not rely on their order.

### System Prompt ✅

Put the system prompt in the top-level `system` field. It can be a string or an array of `text` blocks (the array form is required if you want to put `cache_control` on the system prompt).

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "system": "You are a senior technical editor. Answer concisely and accurately.",
    "messages": [
      {"role": "user", "content": "Explain what idempotency means."}
    ]
  }'
```

### Multi-turn Conversation ✅

The API is stateless: every request must include the full history, with `user` and `assistant` turns alternating and the last message from `user`.

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $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 there."},
      {"role": "assistant", "content": "Hi! How can I help you today?"},
      {"role": "user", "content": "Can you explain large language models in plain English?"}
    ]
  }'
```

!> Ending the conversation with an `assistant` message (prefill, which pre-writes the start of the reply) returns a 400 on Claude 4.6 and later models. Among BeeRoute models, only `claude-haiku-4-5-20251001` supports prefill. On other models, constrain the format with the system prompt or with structured outputs (see "Structured Output" below).

### Image Understanding ✅

Images are sent as `image` content blocks with either a `base64` or a `url` source. Supported formats: `image/jpeg`, `image/png`, `image/gif`, `image/webp`. Anthropic recommends placing images before the text.

**Base64 image:**

```bash
IMG_B64=$(base64 < image.jpg | tr -d '\n')

cat > request.json <<EOF
{
  "model": "claude-sonnet-5-5",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image",
          "source": {"type": "base64", "media_type": "image/jpeg", "data": "$IMG_B64"}
        },
        {"type": "text", "text": "What is in this image?"}
      ]
    }
  ]
}
EOF

curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  --data @request.json
```

**URL image:**

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $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": [
          {
            "type": "image",
            "source": {"type": "url", "url": "https://platform.claude.com/docs/images/vision-example.jpg"}
          },
          {"type": "text", "text": "Describe this image."}
        ]
      }
    ]
  }'
```

?> Base64 data must not contain line breaks and must not include a `data:image/jpeg;base64,` prefix. Official limits: at most 8000x8000 px and 10 MB (base64-encoded) per image; a request with more than 20 images applies a stricter per-image dimension limit. URL sources must be publicly reachable. Some upstream channels accept only base64 sources, so switch to base64 if a URL source is rejected.

### PDF Documents ✅

PDFs are sent as `document` content blocks with a `url` or `base64` source (`media_type` is `application/pdf`). Official limits: at most 600 pages per request (100 pages for models with a context window under 1M tokens); the first-party Anthropic API caps the request body at 128 MB, and other platforms and upstream channels may be lower.

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 2048,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "document",
            "source": {
              "type": "url",
              "url": "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
            }
          },
          {"type": "text", "text": "Summarize the main points of this document in three bullets."}
        ]
      }
    ]
  }'
```

The base64 form (use it the same way as the image heredoc example above):

```json
{
  "type": "document",
  "source": {
    "type": "base64",
    "media_type": "application/pdf",
    "data": "JVBERi0xLjQK..."
  },
  "title": "Quarterly report",
  "citations": {"enabled": true}
}
```

`title`, `context`, and `citations` are optional. With `citations` enabled, the answer is split into multiple `text` blocks that carry citation locations. `citations` cannot be combined with `output_config.format`.

### Tool Use ✅

**Step 1: send a request with tool definitions**

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "tools": [
      {
        "name": "get_weather",
        "description": "Get the current weather for a given city",
        "input_schema": {
          "type": "object",
          "properties": {
            "location": {"type": "string", "description": "City name, e.g. San Francisco"}
          },
          "required": ["location"]
        }
      }
    ],
    "messages": [
      {"role": "user", "content": "What is the weather like in San Francisco today?"}
    ]
  }'
```

**Response example:** when the model decides to call a tool, `stop_reason` is `tool_use`. `claude-sonnet-5-5` has adaptive thinking on by default, so the response may contain a `thinking` block (thinking text is hidden by default: the `thinking` field is an empty string, but a `signature` is present).

```json
{
  "id": "msg_01Aq9w938a90dw8q",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5-5",
  "content": [
    {"type": "thinking", "thinking": "", "signature": "EqQBCgIYAhIM1gbcDa9GJwZA2b3hGgxBdjrkzLoky3dl1pkiMOYds..."},
    {"type": "tool_use", "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV", "name": "get_weather", "input": {"location": "San Francisco"}}
  ],
  "stop_reason": "tool_use",
  "stop_sequence": null,
  "stop_details": null,
  "usage": {
    "input_tokens": 598,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 84
  }
}
```

**Step 2: run the tool and send the result back as `tool_result`**

Append the previous assistant `content` to the history **unchanged** (including the `thinking` block), then append a `user` message containing the `tool_result`, whose `tool_use_id` matches the `tool_use.id` from the previous step:

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "tools": [
      {"name": "get_weather", "description": "Get the current weather for a given city", "input_schema": {"type": "object", "properties": {"location": {"type": "string", "description": "City name, e.g. San Francisco"}}, "required": ["location"]}}
    ],
    "messages": [
      {"role": "user", "content": "What is the weather like in San Francisco today?"},
      {
        "role": "assistant",
        "content": [
          {"type": "thinking", "thinking": "", "signature": "EqQBCgIYAhIM1gbcDa9GJwZA2b3hGgxBdjrkzLoky3dl1pkiMOYds..."},
          {"type": "tool_use", "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV", "name": "get_weather", "input": {"location": "San Francisco"}}
        ]
      },
      {
        "role": "user",
        "content": [
          {"type": "tool_result", "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV", "content": "San Francisco: sunny, 18°C, light westerly wind"}
        ]
      }
    ]
  }'
```

The model then returns the final answer (`stop_reason` is `end_turn`), for example `"It is sunny in San Francisco today, around 18°C with a light westerly wind."`.

!> The `signature` in this example is a placeholder. A real request must send back the `thinking` / `redacted_thinking` blocks from the previous response exactly as received; modifying or reordering them returns a 400.

?> Tool use rules: the `user` message with the `tool_result` must come right after the matching `tool_use`; `tool_result` blocks go first in the `content` array, with any text after them; when the model returns several `tool_use` blocks at once, put all the `tool_result` blocks in a single `user` message; when a tool fails, return `"is_error": true` and describe the failure in `content`.

### Streaming ✅

With `"stream": true`, the API returns the response incrementally as SSE (Server-Sent Events).

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "stream": true,
    "messages": [
      {"role": "user", "content": "Hello"}
    ]
  }'
```

**Response example:**

```text
event: message_start
data: {"type": "message_start", "message": {"id": "msg_01DsBEzYqFX4Xk3jvP4aSVGm", "type": "message", "role": "assistant", "content": [], "model": "claude-sonnet-5-5", "stop_reason": null, "stop_sequence": null, "usage": {"input_tokens": 8, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "output_tokens": 1}}}

event: content_block_start
data: {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "Hello!"}}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": " How can I help you today?"}}

event: content_block_stop
data: {"type": "content_block_stop", "index": 0}

event: message_delta
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null}, "usage": {"output_tokens": 12}}

event: message_stop
data: {"type": "message_stop"}
```

For the event order and delta types, see "Streaming Events" below. The `usage` in `message_delta` is **cumulative**, not incremental.

### Thinking (Adaptive Thinking) ✅

Claude 5 family models have adaptive thinking on by default: the model decides whether and how deeply to think, and `output_config.effort` controls the overall effort. These models hide the thinking text by default (`display` defaults to `"omitted"`); set `"display": "summarized"` to receive a thinking summary.

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 16000,
    "thinking": {"type": "adaptive", "display": "summarized"},
    "output_config": {"effort": "high"},
    "messages": [
      {"role": "user", "content": "What is the greatest common divisor of 1071 and 462?"}
    ]
  }'
```

**Response example:**

```json
{
  "id": "msg_01QmTqXkV8sJZ3nF4b2yR9cH",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5-5",
  "content": [
    {
      "type": "thinking",
      "thinking": "Use the Euclidean algorithm: 1071 = 2 * 462 + 147; 462 = 3 * 147 + 21; 147 = 7 * 21. GCD = 21.",
      "signature": "WaUjzkypQ2mUEVM36O2Txu..."
    },
    {
      "type": "text",
      "text": "The greatest common divisor of 1071 and 462 is **21**."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "stop_details": null,
  "usage": {
    "input_tokens": 24,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 398,
    "output_tokens_details": {"thinking_tokens": 345}
  }
}
```

- Thinking tokens are billed as output tokens and count toward `max_tokens`, even when the thinking text is not returned;
- the returned thinking text is a summary, not the raw reasoning;
- for each model's support of the `thinking` values, see the `thinking` table in the "Request" section below. The older `claude-haiku-4-5-20251001` does not support `adaptive` and needs `{"type": "enabled", "budget_tokens": 2048}` (`budget_tokens` is at least 1024 and less than `max_tokens`); on Claude 4.7 and later models, `enabled` returns a 400.

### Prompt Caching ✅

Add `cache_control` to a content block, and the prefix up to and including that block (in the order `tools` → `system` → `messages`) is cached. Later requests that hit the cache are billed at the lower cache-read price; see the [pricing page](https://beeroute.ai/modellist/).

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "system": [
      {"type": "text", "text": "You are an assistant that analyzes legal documents."},
      {
        "type": "text",
        "text": "(Put the long text you reuse across requests here, for example the full text of a contract...)",
        "cache_control": {"type": "ephemeral"}
      }
    ],
    "messages": [
      {"role": "user", "content": "What are the breach-of-contract clauses in this contract?"}
    ]
  }'
```

The first request writes the cache, so `usage.cache_creation_input_tokens` is greater than 0. A request with the same prefix sent within 5 minutes reads the cache, so `usage.cache_read_input_tokens` is greater than 0:

```json
{
  "usage": {
    "input_tokens": 16,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 3842,
    "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0},
    "output_tokens": 287
  }
}
```

**Automatic caching:** you can also add a single top-level `cache_control`, and the system places the cache breakpoint on the last cacheable block automatically. This suits multi-turn conversations:

```json
{
  "model": "claude-sonnet-5-5",
  "max_tokens": 1024,
  "cache_control": {"type": "ephemeral", "ttl": "1h"},
  "system": "You are a helpful assistant.",
  "messages": [
    {"role": "user", "content": "Let us continue where we left off."}
  ]
}
```

- `ttl` is `"5m"` (default) or `"1h"`; 1-hour cache writes cost more;
- a request can have at most 4 cache breakpoints (top-level automatic caching uses one of them);
- prefixes shorter than the minimum length are not cached, and no error is returned: 512 tokens for `claude-opus-5-5`, `claude-opus-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, and the Fable models; 1024 for `claude-opus-4-8`, `claude-sonnet-5`, `claude-sonnet-4-6`; 2048 for `claude-opus-4-7`; 4096 for `claude-opus-4-6` and `claude-haiku-4-5-20251001`;
- any byte change in the prefix (including changes to the tool list, the thinking configuration, or effort) invalidates the cache after that point.

### Structured Output ✅

Pass a JSON Schema in `output_config.format`, and the `text` block in the response is guaranteed to be JSON that matches the schema. The official supported-model list covers every Claude model on BeeRoute.

```bash
curl https://beeroute.ai/v1/messages \
  -H "x-api-key: $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": "Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."}
    ],
    "output_config": {
      "format": {
        "type": "json_schema",
        "schema": {
          "type": "object",
          "properties": {
            "name": {"type": "string"},
            "email": {"type": "string"},
            "plan_interest": {"type": "string"},
            "demo_requested": {"type": "boolean"}
          },
          "required": ["name", "email", "plan_interest", "demo_requested"],
          "additionalProperties": false
        }
      }
    }
  }'
```

**`content` in the response:**

```json
[
  {
    "type": "text",
    "text": "{\"name\": \"John Smith\", \"email\": \"john@example.com\", \"plan_interest\": \"Enterprise\", \"demo_requested\": true}"
  }
]
```

?> Objects in the schema must set `"additionalProperties": false`. Recursive schemas, `oneOf`, and numeric and string-length constraints are not supported, among others. When `stop_reason` is `refusal` or `max_tokens`, the output may not match the schema. See [Structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) for the full limits. The old top-level `output_format` parameter is deprecated.

### Python SDK ✅

```bash
pip install anthropic
```

```python
import anthropic

client = anthropic.Anthropic(
    api_key="sk-xxx",                 # your BeeRoute key
    base_url="https://beeroute.ai",   # do not append /v1
)

message = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello, Claude"}],
)
for block in message.content:  # with thinking on, a thinking block may come first
    if block.type == "text":
        print(block.text)

# Streaming
with client.messages.stream(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a short poem about autumn"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
```

- Instead of passing arguments in code, you can set the environment variables `ANTHROPIC_API_KEY` and `ANTHROPIC_BASE_URL=https://beeroute.ai`;
- `anthropic` 2.0.0 and later send `anthropic-version: 2026-10-21` by default and no longer offer the `temperature` / `top_p` / `top_k` parameters. If the upstream channel does not accept `2026-10-21`, add `default_headers={"anthropic-version": "2023-06-01"}` when constructing the client;
- the SDK requires streaming when `max_tokens` is large (above roughly 21,333). This is a client-side check; use `client.messages.stream(...)` with `stream.get_final_message()` to get the complete message.

## 📮 Request

### Endpoint

```text
POST https://beeroute.ai/v1/messages
```

### Headers

| Header | Required | Description |
| --- | --- | --- |
| `x-api-key` | One of the two | Your BeeRoute key. Anthropic now lists it as a legacy fallback for `Authorization`; it still works |
| `Authorization` | One of the two | `Bearer $API_KEY`, the form Anthropic currently lists first |
| `anthropic-version` | Yes | API version. `2023-06-01` is recommended; whether the newest version `2026-10-21` works depends on the upstream channel |
| `content-type` | Yes | `application/json` |
| `anthropic-beta` | No | Enables beta features. Put multiple betas in a **single** header, separated by commas, for example `anthropic-beta: beta1,beta2`; do not send the header more than once. Whether a beta takes effect depends on the upstream channel |

### Body Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `model` | string | Yes | Model name; see "Available Models" above |
| `max_tokens` | integer | Yes | Maximum number of tokens to generate; minimum 0, maximum varies by model |
| `messages` | array | Yes | Input messages, up to 100,000 per request |
| `system` | string or array | No | System prompt |
| `thinking` | object | No | Thinking configuration |
| `output_config` | object | No | Output configuration: `effort`, `format` |
| `tools` | array | No | Tool definitions |
| `tool_choice` | object | No | How the model should use tools |
| `cache_control` | object | No | Top-level automatic caching |
| `stop_sequences` | array of string | No | Custom stop sequences |
| `stream` | boolean | No | Whether to stream the response as SSE |
| `metadata` | object | No | Request metadata |
| `temperature` / `top_p` / `top_k` | number / number / integer | No | Sampling parameters, strictly limited on newer models; see below |

#### `model`

The model ID, for example `claude-sonnet-5-5`. A model name that BeeRoute does not offer returns an error.

#### `max_tokens`

The maximum number of tokens to generate; the model may stop naturally before reaching it. The official minimum is 0: `max_tokens: 0` writes the prompt cache without generating anything (cache pre-warming).

The maximum varies by model: 64K for `claude-haiku-4-5-20251001` and 128K for the other BeeRoute models. When thinking is on, thinking tokens also count toward `max_tokens`.

!> BeeRoute replaces a missing or zero `max_tokens` with a per-model default, so cache pre-warming with `max_tokens: 0` is not guaranteed to work here. Always set `max_tokens` explicitly to a value greater than 0.

#### `messages`

An array of input messages, each with a `role` and `content`.

**`role`** values:

- `user`: user messages, also used to send `tool_result` blocks back;
- `assistant`: earlier replies from the model. Consecutive messages with the same role are merged into one turn. Ending with an `assistant` message is prefill, which only `claude-haiku-4-5-20251001` supports; other models return a 400;
- `system`: a system instruction added partway through the conversation (it does not invalidate the cached prefix above it). Only some models support it: `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, the Fable models, `claude-opus-5`, and `claude-opus-4-8`; on `claude-sonnet-5` and the other models, use the top-level `system` field. Constraints: it cannot be the first message; it must come right after a `user` message (or an `assistant` message that ends in a server tool result) and before an `assistant` message, or be the last message; it cannot sit between a `tool_use` and its `tool_result`. Do not put untrusted text such as tool output or web content in a `system` message.

**`content`** is either a string or an array of content blocks. A string is shorthand for a single `text` block, so these two are equivalent:

```json
{"role": "user", "content": "Hello, Claude"}
```

```json
{"role": "user", "content": [{"type": "text", "text": "Hello, Claude"}]}
```

For the available content blocks, see "Content Block Types" below.

#### `system`

The system prompt, which sets Claude's role, context, and rules. It can be a string or an array of `text` blocks:

```json
{
  "system": [
    {
      "type": "text",
      "text": "You are a customer support assistant.",
      "cache_control": {"type": "ephemeral"}
    }
  ]
}
```

#### `thinking`

Controls the model's thinking. Available types:

| Value | Description |
| --- | --- |
| `{"type": "adaptive"}` | Adaptive thinking: the model decides when and how much to think. Recommended. Optional `display`: `"summarized"` (returns a thinking summary) or `"omitted"` (the `thinking` field is an empty string; only the `signature` is kept) |
| `{"type": "enabled", "budget_tokens": 2048}` | Manual extended thinking. `budget_tokens` is at least 1024 and less than `max_tokens`; `display` can be set too. Returns a 400 on Claude 4.7 and later models |
| `{"type": "disabled"}` | Turns thinking off; some models reject it |
| `{"type": "between_tools"}` | `claude-sonnet-5-5` only: turns off up-front thinking, leaving only progress updates between tool calls. Only allowed at effort `high` or below, and accepts no other field |

Support on BeeRoute models (from the official [Thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#configuring-thinking) docs; "≤high" means it works at effort `low`/`medium`/`high` and returns a 400 at `xhigh`/`max`):

| Model | No `thinking` field | `adaptive` | `enabled` | `disabled` |
| --- | --- | --- | --- | --- |
| `claude-opus-5-5`, Fable models | Adaptive thinking | Supported | 400 | 400 |
| `claude-sonnet-5-5` | Adaptive thinking | Supported | 400 | 400 (use `between_tools`, ≤high) |
| `claude-haiku-5-5`, `claude-opus-5` | Adaptive thinking | Supported | 400 | Thinking off (≤high) |
| `claude-sonnet-5` | Adaptive thinking | Supported | 400 | Thinking off |
| `claude-opus-4-8`, `claude-opus-4-7` | No thinking | Supported | 400 | Thinking off |
| `claude-opus-4-6`, `claude-sonnet-4-6` | No thinking | Supported | Supported (deprecated) | Thinking off |
| `claude-haiku-4-5-20251001` | No thinking | 400 | Supported | Thinking off |

`display` defaults: `"summarized"` on `claude-opus-4-6`, `claude-sonnet-4-6`, and `claude-haiku-4-5-20251001`; `"omitted"` on the other models. `display` only controls whether thinking text is returned; it does not affect billing.

In multi-turn conversations and tool use, send the `thinking` / `redacted_thinking` blocks from responses back **exactly as received** (including `signature`); do not modify, drop, or reorder them. Also note:

- keep sending them back when you switch models; thinking blocks the target model cannot read are ignored automatically and not billed;
- `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, `claude-fable-5-2`, and `claude-fable-5-1` check the conversation prefix before each thinking block: if you change `system`, `tools`, or an earlier message, the thinking blocks after the change can cause a 400, so maintain the history append-only;
- thinking blocks from `claude-fable-5-2`, `claude-sonnet-5-5`, and `claude-haiku-5-5` only work in the upstream account that produced them. If a later request in the same conversation is handled by a different upstream account, those blocks are dropped silently (no error, but the model no longer sees its earlier reasoning).

#### `output_config`

| Field | Description |
| --- | --- |
| `effort` | Effort level: `low`, `medium`, `high`, `xhigh`, `max`. Applies to all output tokens (text, tool calls, and thinking). Defaults to `high`; `claude-opus-5-5` and `claude-haiku-5-5` default to `medium`. `xhigh` is not supported on `claude-opus-4-6` or `claude-sonnet-4-6`; `claude-haiku-4-5-20251001` does not support `effort` |
| `format` | Structured output: `{"type": "json_schema", "schema": {...}}`; see the "Structured Output" example above |

#### `tools`

An array of tool definitions. Fields of a custom tool:

| Field | Required | Description |
| --- | --- | --- |
| `name` | Yes | Tool name, 1 to 128 characters, must match `^[a-zA-Z0-9_-]{1,128}$` |
| `description` | No | Tool description; strongly recommended, explaining what the tool does and what each parameter means |
| `input_schema` | Yes | JSON Schema for the tool input, with `type` set to `object` |
| `strict` | No | When `true`, guarantees that the tool name and input generated by the model strictly match the schema |
| `cache_control` | No | Sets a cache breakpoint at this tool |
| `type` | No | `"custom"` for custom tools, or omit it |

?> Anthropic-defined tools (web search, web fetch, code execution, computer use, bash, text editor, and so on) change versions frequently, and their availability depends on the upstream channel, so this page does not list them. See the official [Tool use docs](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview).

#### `tool_choice`

| Value | Description |
| --- | --- |
| `{"type": "auto"}` | Default. The model decides whether to call a tool |
| `{"type": "any"}` | The model must call one of the tools |
| `{"type": "tool", "name": "get_weather"}` | The model must call the named tool |
| `{"type": "none"}` | The model may not call tools |

`auto`, `any`, and `tool` accept `"disable_parallel_tool_use": true`: with `auto`, the model calls at most one tool; with `any` / `tool`, exactly one.

!> `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-fable-5-2`, and `claude-fable-5-1` do not support forced tool use: `any` and `tool` return a 400. Use `auto` with prompt instructions, `strict: true`, or structured outputs instead. With manual extended thinking (`thinking.type` is `enabled`), only `auto` and `none` are allowed.

#### `cache_control`

A cache breakpoint. It can be set at the top level of the request (automatic caching) or on a specific content block in `tools`, `system`, or `messages`:

```json
{"type": "ephemeral", "ttl": "5m"}
```

`type` must be `ephemeral`; `ttl` is `"5m"` (default) or `"1h"`. For usage and limits, see the "Prompt Caching" example above. Thinking blocks cannot carry `cache_control` directly.

#### `stop_sequences`

Custom stop sequences (an array of strings). When the model generates one of them, it stops, the response `stop_reason` is `stop_sequence`, and the `stop_sequence` field holds the matched sequence.

#### `stream`

When `true`, the response is streamed as SSE; see "Streaming Events" below. Streaming is recommended for long-running requests (large `max_tokens`, thinking on) to avoid timeouts.

#### `metadata`

| Field | Description |
| --- | --- |
| `user_id` | External identifier of the end user, up to 512 characters. Use an opaque identifier such as a UUID or hash; do not include names, email addresses, phone numbers, or other personal information |

#### `temperature` / `top_p` / `top_k`

Sampling parameters. `temperature` defaults to 1.0 and ranges from 0.0 to 1.0 (lower is more deterministic, higher is more varied); `top_p` is the nucleus sampling threshold; `top_k` samples only from the K most likely tokens.

!> On `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, the Fable models, `claude-opus-5`, `claude-sonnet-5`, `claude-opus-4-8`, and `claude-opus-4-7`, any non-default value returns a 400; sending both `temperature` and `top_p` also returns a 400 (even at their defaults); and since the `top_p` default on these models is 0.99, `top_p: 1` fails too. Do not send these three parameters to these models at all.

`claude-opus-4-6`, `claude-sonnet-4-6`, and `claude-haiku-4-5-20251001` still accept sampling adjustments with version `2023-06-01`, but with thinking on, `temperature` and `top_k` cannot be used and `top_p` must be between 0.95 and 1. With `anthropic-version: 2026-10-21`, sending any of the three parameters returns a 400 on every model.

#### Other Parameters

The official API also supports `container`, `diagnostics`, `service_tier`, `speed`, `inference_geo`, and other parameters, plus features that require the `anthropic-beta` header. BeeRoute does not forward `service_tier`, `speed`, or `inference_geo` by default; whether the others take effect depends on the upstream channel, so do not rely on them.

### Content Block Types

The main content blocks available in `messages[].content`:

| `type` | Purpose | Main fields |
| --- | --- | --- |
| `text` | Text | `text` (at least 1 character), `cache_control`, `citations` |
| `image` | Image | `source`: `{"type": "base64", "media_type": "image/jpeg", "data": "..."}` or `{"type": "url", "url": "..."}`; `cache_control` |
| `document` | Document | `source`: PDF as `base64` (`media_type` is `application/pdf`) or `url`, plain text `{"type": "text", "media_type": "text/plain", "data": "..."}`, or custom content `{"type": "content", "content": [...]}`; optional `title`, `context`, `citations`, `cache_control` |
| `search_result` | Search result (for citations) | `source`, `title`, `content` (array of `text` blocks), `citations` |
| `tool_use` | A tool call made by the model, sent back as history | `id`, `name`, `input` |
| `tool_result` | Tool output, placed in a `user` message | `tool_use_id` (required), `content` (optional: a string or an array of `text` / `image` / `search_result` / `document` blocks), `is_error` |
| `thinking` | A thinking block, sent back as history | `thinking`, `signature`; must be sent back unchanged |
| `redacted_thinking` | An encrypted thinking block, sent back as history | `data`; must be sent back unchanged |

?> `image` and `document` also accept a `{"type": "file", "file_id": "..."}` source, but it requires the Files API, which BeeRoute does not offer.

## 📥 Response

### Message Object

A successful non-streaming request returns a `message` object:

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Unique message ID; the format may change |
| `type` | string | Always `message` |
| `role` | string | Always `assistant` |
| `model` | string | The model that handled the request |
| `content` | array | Content blocks generated by the model |
| `stop_reason` | string or null | Why generation stopped; see below |
| `stop_sequence` | string or null | The matched custom stop sequence, otherwise null |
| `stop_details` | object or null | Set only when `stop_reason` is `refusal`: `type` (`refusal`), `category` (such as `cyber`, `bio`, `frontier_llm`, `reasoning_extraction`, `general_harms`, or null), `explanation` |
| `usage` | object | Token usage; see below |

Common block types in `content`:

- `text`: text in the `text` field; carries a `citations` array when citations are enabled;
- `thinking`: a thinking block; `thinking` holds the summary (an empty string when `display` is `omitted`), and `signature` is used to verify the block when it is sent back;
- `redacted_thinking`: a thinking block encrypted by the safety system; the `data` field is not readable and must be sent back unchanged;
- `tool_use`: a tool call with `id`, `name`, and `input` (an object); parse `input` with a JSON parser rather than matching strings;
- `server_tool_use`, `web_search_tool_result`, and similar: appear when Anthropic server tools are used.

### `stop_reason`

| Value | Meaning |
| --- | --- |
| `end_turn` | The model reached a natural stopping point |
| `max_tokens` | Hit `max_tokens` or the model maximum; the output may be truncated |
| `stop_sequence` | One of the `stop_sequences` was generated |
| `tool_use` | The model called one or more tools; run them and send back `tool_result` blocks |
| `pause_turn` | A long-running turn was paused (common with server tools); send the response back as-is as an assistant message to let the model continue |
| `refusal` | A safety classifier declined the request (the HTTP status is still 200); see `stop_details`. `content` may be incomplete |
| `model_context_window_exceeded` | The model context window was exceeded |

In non-streaming responses, `stop_reason` is always non-null; in streaming responses, it is null in `message_start`, and the final value arrives in `message_delta`.

### `usage`

| Field | Description |
| --- | --- |
| `input_tokens` | Input tokens that were neither read from nor written to the cache (the part after the last cache breakpoint) |
| `cache_creation_input_tokens` | Input tokens written to the cache by this request |
| `cache_read_input_tokens` | Input tokens read from the cache by this request |
| `cache_creation.ephemeral_5m_input_tokens` | Tokens written to the 5-minute cache |
| `cache_creation.ephemeral_1h_input_tokens` | Tokens written to the 1-hour cache |
| `output_tokens` | Output tokens, including thinking tokens (what Anthropic bills) |
| `output_tokens_details.thinking_tokens` | The portion spent on thinking (for observability only) |
| `server_tool_use` | Server tool request counts, such as `web_search_requests` and `web_fetch_requests` |
| `service_tier` | The service tier used: `standard`, `priority`, or `batch` |

Total input tokens = `input_tokens` + `cache_creation_input_tokens` + `cache_read_input_tokens`. Because the API transforms requests internally, token counts do not map one-to-one to the visible content; for example, `output_tokens` is non-zero even for an empty string response.

### Streaming Events

With `stream` enabled, every SSE event has an event name (`event: ...`) and matching JSON data (`data: {...}`, whose `type` equals the event name). Event order:

1. `message_start`: a `message` object with an empty `content` array and a null `stop_reason`, plus the initial `usage`;
2. each content block in turn: `content_block_start` → any number of `content_block_delta` → `content_block_stop`; `index` is the block's position in the final `content` array;
3. one or more `message_delta` events: `delta` carries `stop_reason` and `stop_sequence`, and the `usage` next to `delta` holds **cumulative** token counts;
4. `message_stop`: end of the stream.

`ping` events may appear anywhere in the stream, and new event types may be added in the future, so clients should ignore events they do not recognize.

`delta` types in `content_block_delta`:

| `delta.type` | Block | Field | Description |
| --- | --- | --- | --- |
| `text_delta` | `text` | `text` | Text increment |
| `input_json_delta` | `tool_use` | `partial_json` | Partial JSON string of the tool input; concatenate the pieces and parse at `content_block_stop` |
| `thinking_delta` | `thinking` | `thinking` | Thinking text increment; a single empty string when `display` is `omitted` |
| `signature_delta` | `thinking` | `signature` | Signature of the thinking block, sent just before the block's `content_block_stop` |
| `citations_delta` | `text` | `citation` | Citation information |

`redacted_thinking` blocks and server tool result blocks arrive whole in `content_block_start`, with no deltas.

If an error occurs after the stream has started (the HTTP status is already 200), it arrives as an `error` event:

```text
event: error
data: {"type": "error", "error": {"type": "overloaded_error", "message": "Overloaded"}}
```

### Error Responses

Failed requests return a 4XX / 5XX status. Errors from the Anthropic upstream use this shape:

```json
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "This model does not support assistant message prefill. The conversation must end with a user message."
  },
  "request_id": "req_011CSHoEeqs5C35K2UUqR7Fy"
}
```

Some errors also carry a more specific code in `error.details.error_code`.

| HTTP status | `error.type` | Meaning |
| --- | --- | --- |
| 400 | `invalid_request_error` | Problem with the request format or content (invalid parameter, feature not supported by the model, and so on) |
| 401 | `authentication_error` | Problem with the API key |
| 402 | `billing_error` | Billing or payment problem |
| 403 | `permission_error` | The key lacks permission for the resource |
| 404 | `not_found_error` | Resource not found |
| 409 | `conflict_error` | The request conflicts with the current state of a resource |
| 413 | `request_too_large` | The request body exceeds the size limit |
| 429 | `rate_limit_error` | Rate limit reached |
| 500 | `api_error` | Internal upstream error |
| 504 | `timeout_error` | Processing timed out; use streaming for long requests |
| 529 | `overloaded_error` | The upstream is temporarily overloaded |

?> Gateway-level errors from BeeRoute (such as an invalid key, insufficient balance, or no available channel) may come back in OpenAI style, for example `{"error": {"code": "", "message": "error description", "type": "new_api_error"}}`. Handle both shapes when parsing errors: read `error.message` first, then act on the HTTP status.

Common 400 errors and fixes:

| Error message (excerpt) | Cause and fix |
| --- | --- |
| `This model does not support assistant message prefill` | The model does not support prefill; remove the trailing `assistant` message |
| `"thinking.type.enabled" is not supported for this model` | On Claude 4.7 and later models, use `{"type": "adaptive"}` with `output_config.effort` instead |
| `"thinking.type.disabled" is not supported for this model` | Thinking cannot be turned off on this model; remove the `thinking` field or lower the effort |
| `tool_choice: type "tool" and "any" are not supported for this model` | Use `tool_choice: {"type": "auto"}` instead |
| `` `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified `` | A thinking block was modified; send it back unchanged |
