API reference
Messages
POST https://api.flyrouter.ai/v1/messages
Anthropic's native Messages API and the recommended way to call Claude: prompt caching, reasoning, tool use, images and structured output all work in full. Claude Code uses this endpoint too.
Example request
Terminal
curl https://api.flyrouter.ai/v1/messages \
-H "x-api-key: $FLYROUTER_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 2048,
"system": "You are a senior code reviewer.",
"messages": [
{"role": "user", "content": "What is wrong with this code?\nfor i in range(len(xs)): print(xs[i])"}
]
}'Set the Anthropic SDK base_url to https://api.flyrouter.ai without /v1. The SDK appends /v1/messages itself.
Headers
| Header | Description |
|---|---|
x-api-key | Your API key (Authorization: Bearer also works) |
anthropic-version | Required. Use 2023-06-01 |
anthropic-beta | Optional. For beta features; forwarded as is |
Request parameters
| Parameter | Type | Description |
|---|---|---|
model | string | Required. A Claude model ID such as claude-opus-5-5, claude-sonnet-5-5 or claude-haiku-5-5 |
max_tokens | integer | Required. Maximum tokens to generate; stream when it's large |
messages | array | Required. Alternating user and assistant messages; content can be text or an array of content blocks |
system | string / array | System prompt; the array form accepts cache_control |
stream | boolean | Stream the response; see Streaming |
thinking | object | Reasoning. Newer models use {"type": "adaptive"}; see Reasoning |
output_config | object | effort (reasoning depth) and format (structured output) |
tools / tool_choice | array / object | Tool calling |
cache_control | object | Automatically adds a cache breakpoint on the last cacheable block; see Prompt caching |
stop_sequences | array | Stop generating at these strings |
metadata | object | For example {"user_id": "..."} |
Response
json
{
"id": "msg_...",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-5-5",
"content": [{ "type": "text", "text": "This code could be more Pythonic..." }],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 41,
"output_tokens": 156,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0
}
}Common stop_reason values:
| Value | Meaning |
|---|---|
end_turn | Finished normally |
max_tokens | Cut off at max_tokens; raise it and retry |
tool_use | The model wants to call a tool; run it and send back a tool_result |
refusal | The model declined for safety reasons |
Check stop_reason before reading the reply, then walk the content array and pick blocks by type (text, thinking, tool_use and so on).