Griffin / OpenRouter with Claude Code
How do I use OpenRouter with Claude Code?
Short answer: set ANTHROPIC_BASE_URL to https://openrouter.ai/api, put your OpenRouter key in ANTHROPIC_AUTH_TOKEN, set ANTHROPIC_API_KEY to an empty string, run /logout once if you used an Anthropic login, restart claude and check /status.1
The setting, step by step
OpenRouter speaks the Anthropic Messages API, so Claude Code connects straight to it with no local proxy.1 Add these lines to your shell profile, such as ~/.zshrc (if your key is set in a file that loads later, use ~/.zshenv so the token isn’t empty):
export OPENROUTER_API_KEY="<your-openrouter-api-key>"
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY="" # must be explicitly empty
- Reload the shell, so the new values are live.
- If you ever logged in to Claude Code with an Anthropic account, run
/logoutonce, then quit and relaunchclaude. A cached login next to a gateway credential causes confusing model-not-found errors.1 - Run
/status. It should showAuth token: ANTHROPIC_AUTH_TOKENandAnthropic base URL: https://openrouter.ai/api. Your requests then appear in OpenRouter’s Activity dashboard.1
Do not put these in a project .env file: the native Claude Code installer does not read it. Use your shell profile or .claude/settings.local.json instead.1 Anthropic’s own gateway page documents ANTHROPIC_AUTH_TOKEN as the variable Claude Code sends as an Authorization: Bearer header.2
Choosing the model for each role
Claude Code picks a model per role. Point each role at an OpenRouter model with ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL and CLAUDE_CODE_SUBAGENT_MODEL.1 Two warnings from OpenRouter’s own page: the setup is only guaranteed with the Anthropic first-party provider, and Claude Code “may not work correctly” with other providers’ models.1 Try a cheaper model on one role (the subagent is the safest) and watch a few sessions before you widen it; changing the model in Claude Code lists every role and alias. What each Claude plan and model costs overall is in Claude Code pricing, and Claude Code Router sends different roles to different providers. DeepSeek, Z.ai and Kimi need no gateway at all, since each has an Anthropic-compatible endpoint: see DeepSeek in Claude Code, the GLM Coding Plan and the Kimi coding plan.
What the model choice costs
Which model you pin moves the bill far more than the gateway does. Our benchmark, RouteBench, sent the same 108 graded tasks with fixed answers to each model on OpenRouter (run of November 16, 2026): code review, security review, tool calling, JSON extraction, classification and math. Cost is dollars per 1,000 tasks.3
| Model | Code review | Security review | Tool calling | All 108 graded tasks |
|---|---|---|---|---|
| Claude Opus 5.5 | 100% · $2.84 | 100% · $3.53 | 100% · $7.43 | 100% · $5.20 |
| Claude Sonnet 5.5 | 100% · $1.31 | 100% · $1.80 | 100% · $3.65 | 100% · $2.30 |
| Claude Haiku 5.5 | 100% · $0.10 | 100% · $0.10 | 100% · $0.19 | 98.1% · $0.16 |
| DeepSeek V4.1 Flash | 100% · $0.08 | 94.4% · $0.23 | 100% · $0.18 | 99.1% · $0.24 |
On these tasks Opus billed 2.3 times Sonnet and 32 times Haiku, with the same pass rate on code review and tool calling. That is a ratio between models, not a forecast: RouteBench tasks are short API calls, and a Claude Code session sends far more tokens per task, so the dollars scale up. RouteBench grades single answers, not whole coding sessions, and it is one run.
Seeing which sessions cost what
OpenRouter’s Activity dashboard shows usage by model and key.1 Splitting it by feature is not something it does; that is what Griffin’s OpenRouter usage view adds, and Griffin is our product. To price a model change before you make it, use the LLM cost calculator; for the fees OpenRouter adds, see OpenRouter pricing.
Sources
Each fact above links to its number here. We read every page on the date shown; settings and prices change, so check before you rely on them.
FAQ
Setup and what Griffin records are in the docs.
Why do I set ANTHROPIC_API_KEY to an empty string?
OpenRouter asks for it to be explicitly empty to prevent conflicts. Claude Code sends ANTHROPIC_API_KEY in an x-api-key header and asks once to approve it; the OpenRouter key goes in ANTHROPIC_AUTH_TOKEN, which Claude Code sends as an Authorization: Bearer header.
Does OpenRouter cost more than Anthropic directly?
OpenRouter bills your credits at the model's price and adds a fee when you buy credits; see our OpenRouter pricing page for the current fee. Which model you pick moves the bill far more: on RouteBench, Opus 5.5 cost 2.3 times Sonnet 5.5.
See what each feature costs.
Griffin shows spend per feature on your own OpenRouter calls and tests cheaper models on them. Watching is free.