Anthropic SDK and Claude Code
POST /v1/messages takes a request in Anthropic Messages form and answers in it, whole or streamed, so the Anthropic SDK and Claude Code work with a new address and key. The model comes from the same catalogue as on the OpenAI wire and is chosen by the same provider and models (see Routing and caching).
Address and key
The Anthropic SDK and Claude Code append /v1/messages themselves, so they take the address without a path: https://api.samreshuuu.ru. The Anthropic SDK sends the Model API key in x-api-key, Claude Code in Authorization: Bearer; both are accepted. The key is issued in the developer console.
Claude Code
Besides ANTHROPIC_MODEL, Claude Code calls the Opus, Sonnet and Haiku tiers itself (Haiku for background tasks) by their Anthropic names. Our catalogue has no such ids, so the snippet sets ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL to a catalogue model id; without them background calls get model_not_found. Any of them can be another model from the Models page, a cheap one for the Haiku tier for example.
Claude Code sends the x-claude-code-session-id header: it keeps the calls of one session in one cache.
Messages fields
| Field | What happens to it | Note |
|---|---|---|
messages | passed to the host as sent | |
system | passed to the host as sent | |
tools | passed to the host as sent | |
tool_choice | passed to the host as sent | |
temperature | passed to the host as sent | |
top_p | passed to the host as sent | |
top_k | passed to the host as sent | |
stop_sequences | passed to the host as sent | |
thinking | passed to the host as sent | |
output_config | passed to the host as sent | |
output_format | passed to the host as sent | |
cache_control | passed to the host as sent | |
context_management | passed to the host as sent | |
model | replaced: read by this API, the host gets this API's value | |
max_tokens | replaced: read by this API, the host gets this API's value | |
stream | replaced: read by this API, the host gets this API's value | |
metadata | replaced: read by this API, the host gets this API's value | |
models | replaced: read by this API, the host gets this API's value | |
provider | replaced: read by this API, the host gets this API's value | |
plugins | replaced: read by this API, the host gets this API's value | |
service_tier | accepted and dropped | |
mcp_servers | refused with 400 | mcp_servers and container run on Anthropic's own servers, which this API does not reach. |
container | refused with 400 | mcp_servers and container run on Anthropic's own servers, which this API does not reach. |
extra_body | refused with 400 | extra_body, extra_headers, extra_query and timeout are SDK request options, merged by the SDK before the request is sent; send their fields at the top level of the body. |
extra_headers | refused with 400 | extra_body, extra_headers, extra_query and timeout are SDK request options, merged by the SDK before the request is sent; send their fields at the top level of the body. |
extra_query | refused with 400 | extra_body, extra_headers, extra_query and timeout are SDK request options, merged by the SDK before the request is sent; send their fields at the top level of the body. |
timeout | refused with 400 | extra_body, extra_headers, extra_query and timeout are SDK request options, merged by the SDK before the request is sent; send their fields at the top level of the body. |
How the body travels depends on the host that answers (the host's wires in GET /v1/models):
- The host speaks Messages itself (
messagesinwires). It gets the body fields this API knows, with ourmodel,max_tokensand conversation key inmetadata.user_id.cache_controlmarks go through as they are, less thettlandscopekeys. - The host speaks only Chat Completions. The body is translated. On top of the table,
top_k, a top-levelcache_control,context_management,citationson text blocks,signatureof thinking blocks andredacted_thinkingblocks are not applied, anddocument,search_resultandcontainer_uploadblocks and an image with afilesource are refused with400. The text blocks of one message are joined with a blank line, and the thinking of an assistant turn goes before its text and tool calls, the only order a Chat Completions message has.
tools and tool_choice travel as Anthropic tools (tool_use, tool_result). You run the tools. Anthropic server tools (web_search, bash, text_editor, computer and others), mcp_servers and container run on Anthropic's servers, which this API does not reach, and are refused with 400.
The anthropic-beta header
An anthropic-beta value is either passed to a host that speaks Messages or dropped. An unknown value is dropped, not refused: Claude Code adds betas with every release, and a call must not break on them.
| anthropic-beta value | What happens to it |
|---|---|
claude-code-20250219 | passed to the host as sent |
interleaved-thinking-2025-05-14 | passed to the host as sent |
fine-grained-tool-streaming-2025-05-14 | passed to the host as sent |
token-efficient-tools-2025-02-19 | passed to the host as sent |
prompt-caching-2024-07-31 | passed to the host as sent |
context-management-2025-06-27 | passed to the host as sent |
effort-2025-11-24 | passed to the host as sent |
structured-outputs-2025-11-13 | passed to the host as sent |
context-1m-2025-08-07 | accepted and dropped |
extended-cache-ttl-2025-04-11 | accepted and dropped |
fast-mode-2026-02-01 | accepted and dropped |
output-128k-2025-02-19 | accepted and dropped |
output-300k-2026-03-24 | accepted and dropped |
oauth-2025-04-20 | accepted and dropped |
prompt-caching-scope-2026-01-05 | accepted and dropped |
advanced-tool-use-2025-11-20 | accepted and dropped |
files-api-2025-04-14 | accepted and dropped |
mcp-client-2025-11-20 | accepted and dropped |
code-execution-2025-08-25 | accepted and dropped |
web-search-2025-03-05 | accepted and dropped |
web-fetch-2025-09-10 | accepted and dropped |
computer-use-2025-11-24 | accepted and dropped |
skills-2025-10-02 | accepted and dropped |
advisor-tool-2026-03-01 | accepted and dropped |
The betas dropped are those that change the price (the long window, the one-hour cache, fast mode, larger output) and the capabilities of Anthropic's servers (files, MCP, code execution, web search, computer use, skills).
Answer and cost
The answer's id reads msg_…, as at Anthropic. usage has Anthropic's shape: input_tokens (only what was not read from the cache), output_tokens, cache_read_input_tokens, cache_creation_input_tokens and the write split by tier in cache_creation, without cost. The call id gen-… comes in the x-request-id header, and with it GET /v1/generation returns the cost (see Accounting and cost).
Besides the minute's x-ratelimit-* headers, the answer carries Anthropic's anthropic-ratelimit-requests-* and anthropic-ratelimit-tokens-* with the reset in RFC 3339 (see Rate limits). An error comes in Anthropic's form: {"type": "error", "error": {"type", "message"}, "request_id"}.
Counting tokens
POST /v1/messages/count_tokens takes a Messages body (model, messages, system, tools) and answers {"input_tokens": n}, counted the way the call's hold is counted. Nothing is charged; the scope is models:read. The Anthropic SDK calls it as client.messages.count_tokens(...).
Frequently asked questions
Why does Claude Code need the ANTHROPIC_DEFAULT_*_MODEL variables?
Besides ANTHROPIC_MODEL, Claude Code calls the Opus, Sonnet and Haiku tiers itself (Haiku for background tasks) by their Anthropic names. Our catalogue has no such ids, and without these variables background calls get model_not_found. The snippet sets all three to a catalogue model id.
Why is there no usage.cost in a Messages answer?
usage on the Messages wire has Anthropic's shape. The call's price comes from GET /v1/generation?id=gen-…, with the gen-… taken from the answer's x-request-id header.