Skip to content

API

Anthropic Messages

POST /v1/messages speaks Anthropic's Messages format for every text model on sale.

POST /v1/messages takes Anthropic's Messages request and returns Anthropic's response and stream events.

It's the route Claude Code and the Anthropic SDKs use.

The gateway converts the request for the model you name, so every text model on sale answers here, not only Claude models.

POST/v1/messages

Base URL: https://api.azrouter.dev (no /v1; the client adds /v1/messages).

Claude models

Every Claude model listed on the Models page is on sale here, for example anthropic/claude-opus-5.5 or anthropic/claude-haiku-5.5; any other text model's slug works in model too.

The prompt cache TTL is 5 minutes: a "ttl": "1h" marker is served and billed as a 5-minute cache write.

Only cache_control markers on content blocks are cached: see Prompt caching.

Headers

Fields
ParameterDetails
x-api-key
stringheader

Your API key.

Send it here or as Authorization: Bearer <key>; one of the two is required.

anthropic-version
stringheader

2023-06-01.

Request body

Fields
ParameterDetails
model
stringrequired

A slug from the model list.

Any text model on sale answers here, not only Claude models.

max_tokens
integerrequired

Upper bound on output tokens, a reasoning model's thinking included.

messages
object[]required

The conversation so far, as Anthropic { role, content } objects.

Show child attributes

rolestringrequired

user or assistant.

contentstring or object[]required

Text, or content blocks: text, and the tool_use and tool_result blocks of tool calls.

A cache_control marker on a block caches it: see Prompt caching.

system
string or object[]

Instructions for the model, as text or text blocks.

A cache_control marker on a block caches it.

stream
boolean

Send Anthropic's server-sent events.

See Streaming.

tools
object[]

Your own tools, converted in both directions, streamed or not.

Server tools such as web search are refused with 400 invalid_request.

Show child attributes

namestringrequired

The tool's name.

descriptionstring

What the tool does.

input_schemaobjectrequired

Its input as a JSON Schema.

Response

Anthropic's response shape.

Fields
ParameterDetails
type
string

message.

role
string

assistant.

content
object[]

The reply as blocks.

A reasoning model's thinking arrives as a thinking block before the text block; a tool call is a tool_use block.

stop_reason
string

end_turn, or tool_use when the model calls one of your tools.

model
string

The model that answered.

usage
object

input_tokens, output_tokens, cache_creation_input_tokens and cache_read_input_tokens.

Anthropic SDK

Point the SDK at the base URL without /v1:

Python
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.azrouter.dev",
    api_key=os.environ["AZROUTER_API_KEY"],
)

message = client.messages.create(
    model="qwen/qwen3.8-flash",
    max_tokens=200,
    messages=[{"role": "user", "content": "Reply with exactly: Hello from AZRouter"}],
)
print(next(block.text for block in message.content if block.type == "text"))

Streaming

Add "stream": true to get Anthropic's server-sent events: message_start, content_block_start, content_block_delta, content_block_stop, message_delta and message_stop.

Tools

Tool definitions (tools with input_schema) and tool_use / tool_result blocks are converted in both directions, streamed or not.

As on Chat Completions, only your own tools are accepted; server tools such as web search are refused with 400 invalid_request.

Token counting is not available

POST /v1/messages/count_tokens returns 404:

Shell
curl -i https://api.azrouter.dev/v1/messages/count_tokens \
  -H "x-api-key: $AZROUTER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen/qwen3.8-flash", "messages": [{"role": "user", "content": "Hello"}]}'

Claude Code treats this endpoint as optional and estimates token counts itself, so its context meter is approximate.

The bill uses the token counts the model reports.