# Messages API

> POST /api/v1/messages — Anthropic-compatible Messages API passthrough. Use any Anthropic SDK or Claude Code against AnyRouter by swapping the base URL.


# Messages API

The Messages API is an Anthropic-compatible endpoint. Any tool that speaks the Anthropic Messages protocol — including Claude Code and the official `@anthropic-ai/sdk` — works against AnyRouter by changing the base URL.

```text
POST https://anyrouter.dev/api/v1/messages
```

## Headers

Unlike the OpenAI-compatible endpoints, the Messages API expects Anthropic's auth scheme:

| Header | Required | Description |
|---|---|---|
| `x-api-key` | yes | Your AnyRouter API key (prefixed `ar-`). |
| `anthropic-version` | yes | Anthropic API version — `2023-06-01` is stable. |
| `Content-Type` | yes | `application/json`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `model` | string | yes | `anthropic/*` model id. |
| `messages` | array | yes | `[{role, content}]` — `content` can be a string or rich blocks. |
| `max_tokens` | integer | yes | Required by the Messages API. |
| `system` | string | no | System prompt (Anthropic splits this out of `messages`). |
| `temperature` | number | no | 0–1. |
| `stream` | boolean | no | SSE streaming. |
| `stop_sequences` | string[] | no | Stop sequences. |
| `tools` | array | no | Tool definitions in Anthropic's schema. |

## Example

```bash
curl https://anyrouter.dev/api/v1/messages \
  -H "x-api-key: ar-your-key" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-haiku-4.5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Say hi in 5 words"}
    ]
  }'
```

## Using the Anthropic SDK

```typescript
import Anthropic from "@anthropic-ai/sdk"

const client = new Anthropic({
  baseURL: "https://anyrouter.dev/api",
  apiKey: "ar-your-key",
})

const response = await client.messages.create({
  model: "anthropic/claude-sonnet-4.6",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello!" }],
})
```

:::note
The base URL is `https://anyrouter.dev/api` — the SDK appends `/v1/messages` itself.
:::

## Response

```json
{
  "id": "msg_01XY...",
  "type": "message",
  "role": "assistant",
  "model": "anthropic/claude-sonnet-4.6",
  "content": [{ "type": "text", "text": "Hello there." }],
  "stop_reason": "end_turn",
  "usage": { "input_tokens": 10, "output_tokens": 4 }
}
```

## Supported models

The Messages endpoint currently supports every `anthropic/*` model in the catalog as a native passthrough. Non-Anthropic models are not routable through `/messages` — use [chat completions](/docs/api-reference/chat-completions) instead.

## Related

- [Use Claude Code with AnyRouter](/docs/claude-code) — the canonical Messages API client setup
