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

bash
export ANTHROPIC_BASE_URL="https://api.samreshuuu.ru" export ANTHROPIC_AUTH_TOKEN="$SAMRESHUUU_API_KEY" export ANTHROPIC_MODEL="deepseek/deepseek-v4.1-flash" export ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek/deepseek-v4.1-flash" export ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek/deepseek-v4.1-flash" export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek/deepseek-v4.1-flash" claude

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

FieldWhat happens to itNote
messagespassed to the host as sent
systempassed to the host as sent
toolspassed to the host as sent
tool_choicepassed to the host as sent
temperaturepassed to the host as sent
top_ppassed to the host as sent
top_kpassed to the host as sent
stop_sequencespassed to the host as sent
thinkingpassed to the host as sent
output_configpassed to the host as sent
output_formatpassed to the host as sent
cache_controlpassed to the host as sent
context_managementpassed to the host as sent
modelreplaced: read by this API, the host gets this API's value
max_tokensreplaced: read by this API, the host gets this API's value
streamreplaced: read by this API, the host gets this API's value
metadatareplaced: read by this API, the host gets this API's value
modelsreplaced: read by this API, the host gets this API's value
providerreplaced: read by this API, the host gets this API's value
pluginsreplaced: read by this API, the host gets this API's value
service_tieraccepted and dropped
mcp_serversrefused with 400mcp_servers and container run on Anthropic's own servers, which this API does not reach.
containerrefused with 400mcp_servers and container run on Anthropic's own servers, which this API does not reach.
extra_bodyrefused with 400extra_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_headersrefused with 400extra_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_queryrefused with 400extra_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.
timeoutrefused with 400extra_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 (messages in wires). It gets the body fields this API knows, with our model, max_tokens and conversation key in metadata.user_id. cache_control marks go through as they are, less the ttl and scope keys.
  • The host speaks only Chat Completions. The body is translated. On top of the table, top_k, a top-level cache_control, context_management, citations on text blocks, signature of thinking blocks and redacted_thinking blocks are not applied, and document, search_result and container_upload blocks and an image with a file source are refused with 400. 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 valueWhat happens to it
claude-code-20250219passed to the host as sent
interleaved-thinking-2025-05-14passed to the host as sent
fine-grained-tool-streaming-2025-05-14passed to the host as sent
token-efficient-tools-2025-02-19passed to the host as sent
prompt-caching-2024-07-31passed to the host as sent
context-management-2025-06-27passed to the host as sent
effort-2025-11-24passed to the host as sent
structured-outputs-2025-11-13passed to the host as sent
context-1m-2025-08-07accepted and dropped
extended-cache-ttl-2025-04-11accepted and dropped
fast-mode-2026-02-01accepted and dropped
output-128k-2025-02-19accepted and dropped
output-300k-2026-03-24accepted and dropped
oauth-2025-04-20accepted and dropped
prompt-caching-scope-2026-01-05accepted and dropped
advanced-tool-use-2025-11-20accepted and dropped
files-api-2025-04-14accepted and dropped
mcp-client-2025-11-20accepted and dropped
code-execution-2025-08-25accepted and dropped
web-search-2025-03-05accepted and dropped
web-fetch-2025-09-10accepted and dropped
computer-use-2025-11-24accepted and dropped
skills-2025-10-02accepted and dropped
advisor-tool-2026-03-01accepted 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.

Was this page helpful?