MorphogenDocs

Claude Code

Connecting Claude Code to Morphogen with environment variables.

Claude Code works through the Anthropic Messages API. Morphogen accepts this format for any text model, so environment variables are enough.

Setup

Create a separate key for Claude Code: its spending then shows on its own row. Then set the variables:

export ANTHROPIC_BASE_URL=https://api.morphogen.ru
export ANTHROPIC_AUTH_TOKEN=$MORPHOGEN_API_KEY
export ANTHROPIC_MODEL=claude-sonnet-5
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=4000

Give the URL without /v1: Claude Code adds the /v1/messages path itself. In ANTHROPIC_MODEL, any text model from GET /v1/models works, not only Anthropic ones.

CLAUDE_CODE_MAX_OUTPUT_TOKENS=4000 caps the response: without it Claude Code asks for a large maximum response, the reserve does not fit into the key limit and the second request gets 402. The reserve uses the smaller of this value and the model ceiling, so with a large key limit you can raise it if long code answers get cut off. The first request of a session costs more than the rest (about 12 ₽ for claude-sonnet-5 as of October 10, 2026): Claude Code sends a large system prompt, later it comes from the cache.

To avoid setting the variables in every session, add them to ~/.zshrc or ~/.bashrc.

Check

claude -p "ответь одним словом: работает?"

Claude Code prints the model's answer. If you get an error instead, find it by status and message text on the Errors page.

Error 402.

Morphogen reserves money for the maximum response of the model. Check that CLAUDE_CODE_MAX_OUTPUT_TOKENS is set and top up the balance. Details are in "Common errors".

What works

Streaming responses. Tool calls on models that support tool use. Images in the input. Prompt caching: the cache_control field passes through as is, and Claude's explicit cache is counted in the spending.

Full table: Compatibility.

Common errors

Claude Code receives errors in the Anthropic format, which has no error.code field: look for the cause by the status and the error.message text. The code in the table is for the Errors page.

SymptomCauseWhat to do
401the key is missing, revoked or expiredcheck ANTHROPIC_AUTH_TOKEN, issue a new key
403 model_not_allowedthe model is not in the key's listchoose a model from GET /v1/models
404 model_not_foundno such name in the catalogcompare ANTHROPIC_MODEL with the list
402 key_limit_exceededthe reserve for the maximum response does not fit into the daily or monthly limit of the keyset CLAUDE_CODE_MAX_OUTPUT_TOKENS=4000 or raise the key limit
402 insufficient_fundsthe balance is below the reserve for the maximum responseset CLAUDE_CODE_MAX_OUTPUT_TOKENS=4000 and top up the balance
429 rate_limit_exceededover the key limit (by default 120 requests or 200,000 tokens per minute)wait for the time in Retry-After

Next

On this page