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=4000Give 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.
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: thecache_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.
| Symptom | Cause | What to do |
|---|---|---|
| 401 | the key is missing, revoked or expired | check ANTHROPIC_AUTH_TOKEN, issue a new key |
403 model_not_allowed | the model is not in the key's list | choose a model from GET /v1/models |
404 model_not_found | no such name in the catalog | compare ANTHROPIC_MODEL with the list |
402 key_limit_exceeded | the reserve for the maximum response does not fit into the daily or monthly limit of the key | set CLAUDE_CODE_MAX_OUTPUT_TOKENS=4000 or raise the key limit |
402 insufficient_funds | the balance is below the reserve for the maximum response | set CLAUDE_CODE_MAX_OUTPUT_TOKENS=4000 and top up the balance |
429 rate_limit_exceeded | over the key limit (by default 120 requests or 200,000 tokens per minute) | wait for the time in Retry-After |
Next
- Connect the documentation as MCP so Claude Code searches it on its own: Documentation as MCP.
- Direct calls through the SDK: Anthropic SDK.