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
text
POST https://anyrouter.dev/api/v1/messages

Headers

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

HeaderRequiredDescription
x-api-keyyesYour AnyRouter API key (prefixed ar-).
anthropic-versionyesAnthropic API version — 2023-06-01 is stable.
Content-Typeyesapplication/json.

Request body

FieldTypeRequiredDescription
modelstringyesanthropic/* model id.
messagesarrayyes[{role, content}]content can be a string or rich blocks.
max_tokensintegeryesRequired by the Messages API.
systemstringnoSystem prompt (Anthropic splits this out of messages).
temperaturenumberno0–1.
streambooleannoSSE streaming.
stop_sequencesstring[]noStop sequences.
toolsarraynoTool definitions in Anthropic's schema.

Example

BASH
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
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
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 instead.