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

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

HeaderDescription
x-api-keyYour API key (Authorization: Bearer also works)
anthropic-versionRequired. Use 2023-06-01
anthropic-betaOptional. For beta features; forwarded as is

Request parameters

ParameterTypeDescription
modelstringRequired. A Claude model ID such as claude-opus-5-5, claude-sonnet-5-5 or claude-haiku-5-5
max_tokensintegerRequired. Maximum tokens to generate; stream when it's large
messagesarrayRequired. Alternating user and assistant messages; content can be text or an array of content blocks
systemstring / arraySystem prompt; the array form accepts cache_control
streambooleanStream the response; see Streaming
thinkingobjectReasoning. Newer models use {"type": "adaptive"}; see Reasoning
output_configobjecteffort (reasoning depth) and format (structured output)
tools / tool_choicearray / objectTool calling
cache_controlobjectAutomatically adds a cache breakpoint on the last cacheable block; see Prompt caching
stop_sequencesarrayStop generating at these strings
metadataobjectFor 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:

ValueMeaning
end_turnFinished normally
max_tokensCut off at max_tokens; raise it and retry
tool_useThe model wants to call a tool; run it and send back a tool_result
refusalThe 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).

FlyRouter

One key, every top AI model