Skip to content
RU

Claude Code and Anthropic SDK

Connect Claude Code (and any Anthropic SDK) directly to Mixen — pay from your balance in roubles, with the same model catalog.

Terminal window
# npm (Node.js 18+)
npm install -g @anthropic-ai/claude-code
Terminal window
# official installer (macOS / Linux / WSL)
curl -fsSL https://claude.ai/install.sh | bash

macOS, Linux, WSL and native Windows are supported. Details — in the official docs.

Create a wrapper script ~/.local/bin/claude_mixen.sh:

#!/bin/bash
(
export ANTHROPIC_BASE_URL=https://api.mixen.ai
export ANTHROPIC_AUTH_TOKEN="your-api-key"
export ANTHROPIC_API_KEY=""
export ANTHROPIC_DEFAULT_OPUS_MODEL=anthropic/claude-opus-5
export ANTHROPIC_DEFAULT_SONNET_MODEL=anthropic/claude-sonnet-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=anthropic/claude-haiku-4.5
export CLAUDE_CODE_SUBAGENT_MODEL=z-ai/glm-5.3-flash
claude --effort high
)
Terminal window
# make executable
chmod +x ~/.local/bin/claude_mixen.sh
# extensionless symlink — shorter command name: claude_mixen
ln -s ~/.local/bin/claude_mixen.sh ~/.local/bin/claude_mixen

Add ~/.local/bin to PATH so the command works from any directory.

Terminal window
# bash (Linux)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Terminal window
# zsh (default on macOS)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Run:

Terminal window
claude_mixen

Notes:

  • ANTHROPIC_API_KEY="" — the explicit empty string matters: if a non-empty ANTHROPIC_API_KEY is set on your machine, Claude Code may try to reach Anthropic servers directly, bypassing Mixen.
  • CLAUDE_CODE_SUBAGENT_MODEL — the model for session subagents (background tasks, title generation). Any model from the catalog.

The base URL carries no /v1 suffix: Claude Code and the Anthropic SDK append it to the request path themselves (/v1/messages), unlike the OpenAI SDK.

The [1m] suffix (1M context) in model settings is supported — Mixen strips it automatically.

Instead of the wrapper script, you can set the variables in ~/.claude/settings.json — they apply to every Claude Code session:

{
"env": {
"ANTHROPIC_BASE_URL": "https://api.mixen.ai",
"ANTHROPIC_AUTH_TOKEN": "your-api-key",
"ANTHROPIC_API_KEY": "",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "anthropic/claude-opus-5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "anthropic/claude-sonnet-5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "anthropic/claude-haiku-4.5",
"CLAUDE_CODE_SUBAGENT_MODEL": "z-ai/glm-5.3-flash"
}
}

For a single project use .claude/settings.local.json (do not commit the key to git).

Verify: run /status inside Claude Code — it should show Anthropic base URL: https://api.mixen.ai.

from anthropic import AsyncAnthropic
client = AsyncAnthropic(
base_url="https://api.mixen.ai",
api_key="your-api-key", # the x-api-key header is supported
)
msg = await client.messages.create(
model="anthropic/claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hi!"}],
)
print(msg.content[0].text)
Feature Status
Text, system, stop_sequences
Images (vision models)
Tools / tool-use (agentic clients)
Streaming SSE (stream: true)
POST /v1/messages/count_tokens ✅ (estimated, no model call)
Prompt caching (cache_control)
Extended thinking (thinking)

Thinking blocks are visible in responses; reasoning models (Claude, GLM 5.3) send them even without the thinking parameter.

Caveats: the count_tokens estimate accounts for Cyrillic density (more accurate than “4 chars per token”); CJK scripts are not supported. Stopping via stop_sequences works, but the response does not report which condition fired — stop_sequence is always null.

Prompt caching is enabled by the client automatically (Claude Code sets cache_control markers on its own). The cache lives for 5 minutes with sliding renewal: every hit resets the timer — in a dense agentic session the cache lives from start to finish, and repeated context costs ~10% of the price. After a pause longer than 5 minutes, the first turn pays full input price plus a cache-write surcharge (×1.25) — that’s normal; the cache picks up again from there.

How much came from the cache is visible in the response usage:

{"input_tokens": 16, "output_tokens": 120,
"cache_read_input_tokens": 3644, "cache_creation_input_tokens": 0}

Here input_tokens counts only the NON-cached remainder, as the Anthropic protocol requires: total input is input_tokens + cache_read_input_tokens. In the example above, 3644 of 3660 context tokens came from the cache.

cache_creation_input_tokens is always 0: the upstream reports read volume only and never the write volume. Pricing is unaffected — the write surcharge is already part of the request cost — but a client’s “written to cache” stat will stay empty.

On the OpenAI-compatible /v1/chat/completions the same number lives in usage.prompt_tokens_details.cached_tokens, while prompt_tokens there DOES include the cache — that is a protocol difference, not ours.

For a deep dive on cache mechanics and savings, see Context caching.

By default Claude Code does not enable thinking. Add an environment variable to the wrapper:

Terminal window
export MAX_THINKING_TOKENS=10000 # thinking budget in tokens (minimum 1024)

The model will reason before answering (grey “Thinking…” blocks expand on click). Reasoning is billed as output tokens: 10,000 is a ceiling — simple questions use far less.

The budget caps only the reasoning, not the whole response: Mixen additionally reserves room for the answer itself, so even with a small max_tokens you never get “reasoning with no answer”. If the final ceiling leaves no room for the minimum budget (1024), reasoning is simply not enabled.

When to enable: architecture, refactoring, unfamiliar code, tricky bugs. For simple questions, comment it out — answers arrive faster and cheaper. You can also set it for a single run: MAX_THINKING_TOKENS=10000 claude_mixen.

Models come from the catalog; authentication uses the same mxn-… keys, with a limit of 60 RPM per key.