Guides
Claude Code
Run Claude Code on AZRouter models through the Anthropic Messages endpoint.
Tested: Claude Code 2.1.301, 2026-10-16
Claude Code talks to /v1/messages. Point it at AZRouter with three environment variables and pick a model by its AZRouter slug.
Claude models
Claude Opus 5.5 (anthropic/claude-opus-5.5) and Claude Haiku 5.5 (anthropic/claude-haiku-5.5) are on sale, and Claude Code also runs on the other text models; the examples below use one of those. Claude Code marks its prompts for caching on content blocks, so a Claude model caches them for 5 minutes: see Prompt caching.
1. Install
npm install -g @anthropic-ai/claude-code2. Point it at AZRouter
The base URL has no /v1: Claude Code adds /v1/messages itself.
export ANTHROPIC_BASE_URL="https://api.azrouter.dev"
export ANTHROPIC_AUTH_TOKEN="$AZROUTER_API_KEY"
export ANTHROPIC_MODEL="qwen/qwen3.8-flash"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen/qwen3.8-flash"ANTHROPIC_AUTH_TOKEN sends the key as a bearer token. ANTHROPIC_DEFAULT_HAIKU_MODEL is the model Claude Code uses for small background tasks; set it to an AZRouter slug too, such as anthropic/claude-haiku-5.5, so those requests don't ask for a Claude model name AZRouter doesn't sell.
3. Check it
claude -p "Reply with exactly: Hello from AZRouter"Then start claude in your project as usual.
Keep the settings
To avoid exporting variables in every shell, put them in ~/.claude/settings.json. apiKeyHelper reads the key from your environment, so the key itself stays out of the file:
{
"apiKeyHelper": "printenv AZROUTER_API_KEY",
"env": {
"ANTHROPIC_BASE_URL": "https://api.azrouter.dev",
"ANTHROPIC_MODEL": "qwen/qwen3.8-flash",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen/qwen3.8-flash"
}
}What to expect
- Context window warning. Claude Code doesn't know non-Claude models, so it prints "Claude Code doesn't recognize the model … assumes a context window of 200k tokens". Requests still work. Claude Code's model configuration docs (opens in a new tab) show how to set the real window.
- Approximate context meter. AZRouter has no
/v1/messages/count_tokens, so Claude Code estimates token counts itself. Billing uses the counts the model reports. - Auto mode notice. Claude Code may say that auto mode's classifier requests are billed as normal requests through a gateway. Nothing breaks.
- Cost per prompt. Every prompt carries Claude Code's system prompt and tool definitions, about 20,000 input tokens. On
qwen/qwen3.8-flashthe one-line check above cost $0.0033 on a cold start and $0.0004 when it ran again seconds later, because most of the prompt was then a cache read.