Claude Code
Claude Code speaks the Anthropic Messages protocol, and the Model API answers it at POST /v1/messages. So Claude Code needs only our address and a Model API key: nothing else to install. The model is auto, which picks a model of the catalogue for the conversation.
Requirements: Claude Code (claude --version shows the version), a Model API key and money on the organization balance.
1. Create a key
In the developer console, open API keys, keep Model API key in the Access field and create the key. Copy it: the secret is shown once.
2. Set the variables
Claude Code reads the env object of ~/.claude/settings.json (or of settings.json in the folder named by CLAUDE_CONFIG_DIR), in the terminal and in the IDE extensions alike. Create the file if there is none. If it already has an env object, add these keys to it rather than replacing it. If you would rather keep the key out of the file, export the same variables from your shell profile (~/.zshrc, ~/.bashrc): that is the Shell tab.
| Variable | What it does |
|---|---|
ANTHROPIC_BASE_URL | Sends Claude Code's requests to the Model API. The address has no /v1: Claude Code appends /v1/messages itself. |
ANTHROPIC_AUTH_TOKEN | The Model API key, sent as Authorization: Bearer. |
ANTHROPIC_API_KEY | Left empty. Claude Code sends this one as x-api-key and takes it for a key of Anthropic itself, so a real key left in the shell would win over the token. |
ANTHROPIC_MODEL | The model a session starts on. |
ANTHROPIC_DEFAULT_FABLE_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL | The models of Claude Code's tiers: /model opus, plan mode and a subagent with its own tier ask for a tier, not for ANTHROPIC_MODEL, and background tasks go to the Haiku tier. Without them such a call names an Anthropic model the catalogue does not have and gets model_not_found. |
CLAUDE_CODE_SUBAGENT_MODEL | The model of subagents that name no tier of their own. |
If you were signed in to Claude Code with an Anthropic account, run /logout once and start claude again: a saved login conflicts with the token.
3. Check the connection
Start claude in a project folder and run /status. The auth token line names ANTHROPIC_AUTH_TOKEN, the base URL line names https://api.samreshuuu.ru. If it names an Anthropic account or ANTHROPIC_API_KEY instead, the variables did not reach the session: reload the shell or check the JSON of settings.json.
Send a prompt. The call shows up in the call log of the console with the model auto picked and its cost.
Models
auto picks the model itself and keeps it for the conversation, so the cache holds; how it picks is under Model choice auto. Any variable of the block takes a model id instead: from the Models page or GET /v1/models, a cheaper model for the Haiku tier for example. For one session, claude --model <id> names the model at start. A [1m] suffix on a model name, as OpenRouter's guide writes it, is dropped before the model is looked up.
Claude Code does not know the window of auto or of a catalogue model and keeps a conversation within the window it assumes, compacting it when needed. If you pin a model with a smaller window, set CLAUDE_CODE_AUTO_COMPACT_WINDOW to its context_length from GET /v1/models.
Thinking and effort
With its own address replaced, Claude Code takes the Model API for Anthropic's and sends thinking and the /effort level (output_config.effort) for any model. The API reads them the way it reads reasoning on the OpenAI wire: a level the answering host does not take is brought to the nearest one (see reasoning), and a model that does not reason answers without thinking.
Cache and cost
Claude Code sends the x-claude-code-session-id header: it keeps the calls of one session in one cache. The attribution line Claude Code puts first in the system prompt changes on every request, and we remove it before the host, so it does not break the cache.
Each call is paid from the balance at the price of the host that answered, and the answer states it in usage.cost. Claude Code does not read that field: /cost shows its own estimate at Anthropic's list prices, not what the balance was charged. The script in the next section puts the charged amount in the status line. The call log of the console shows every call of the session with its model, host and cost; from code, GET /v1/generation?id=gen-… returns one call, with the gen-… from the answer's x-request-id header (see Answer and cost).
Cost in the status line
Claude Code draws its status line with a command you assign. The script below reads the answer ids from the session transcript, asks GET /v1/generation about each new one and shows the model auto chose, the host and what the session has charged the balance: glm-5.3 · deepinfra · 12,40 ₽. It takes the key and the address from the same ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. It needs Node.js 18 or newer.
Save the script as ~/.claude/statusline-cost.mjs:
Add this to ~/.claude/settings.json next to env:
The line refreshes after every answer. A call that has not reached the log yet is asked about on the next refresh, and until then their count follows the sum: +1…. The session's sum is kept in the system temp folder in claude-cost-<session id>.json, which you can delete at any time. settings.json holds one status line, so this one replaces yours if you had one.
Undo the setup
Remove the keys you added from env in settings.json, or the exports from your shell profile. Claude Code then goes back to your Anthropic account.
Troubleshooting
| What you see | What to check |
|---|---|
| Claude Code asks you to sign in to Anthropic | ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN are not both read. Check that they are in the env object of the file Claude Code loads and that the JSON is valid. |
| A warning about an auth conflict at start | A saved Anthropic login or a real ANTHROPIC_API_KEY. Run /logout, leave ANTHROPIC_API_KEY empty and restart claude. |
401 | The key is wrong or revoked. Check it under API keys in the console. |
model_not_found naming a claude-… model | One of the ANTHROPIC_DEFAULT_*_MODEL variables is not set: a tier asked for its Anthropic name. The error names the variables; no other model stands in. |
402 | The balance does not cover the call's hold, or the key's spend limit is reached. |
| HTTP | type | Code | message | Retry |
|---|---|---|---|---|
| 401 | authentication_error | invalid_api_key | The API key is unknown, disabled, revoked or expired. Switch a disabled key back on in the developer console; create a new one in place of a revoked or expired key. | no |
| 404 | not_found_error | model_not_found | The model does not exist. GET /v1/models lists the models this API sells. | no |
| 400 | invalid_request_error | no_auto_model | No model meets the request for auto. | no |
| 402 | billing_error | insufficient_balance | The organization balance does not cover this request (max_tokens is held in full until the answer is settled). Top up the balance or lower max_tokens. | no |
| 402 | billing_error | key_limit_exceeded | This API key has reached its spending limit. Raise the limit or use another key. | no |
If an error persists, write to support with the x-request-id of the answer.
Frequently asked questions
Why does Claude Code need the ANTHROPIC_DEFAULT_*_MODEL variables?
Besides ANTHROPIC_MODEL, Claude Code calls its Fable, Opus, Sonnet and Haiku tiers itself (subagents, plan mode, Haiku for background tasks) by their Anthropic names. Our catalogue has no such ids, and without these variables those calls get model_not_found. The block sets every tier to auto.
Does Claude Code work with models other than Claude?
Yes. The Messages wire serves every text model of the catalogue, tools and thinking included, and auto picks one for the conversation. Claude Code is tuned for Claude models, so how well a long session goes depends on the model that answers.
Where do I see what a session cost?
In Claude Code's status line, with the script from Cost in the status line: it shows what the session has charged the balance. Every call of the session with its model, host and cost is in the call log of the developer console (https://console.samreshuuu.ru). From code, GET /v1/generation?id=gen-… returns one call, with the gen-… taken from the answer's x-request-id header.