How to use Claude Code with OpenRouter
Set ANTHROPIC_BASE_URL=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 were signed in to Anthropic, and restart Claude Code. OpenRouter speaks the Anthropic Messages API natively, so no proxy is needed. Usage is billed from your OpenRouter credits at the model's rate plus the 5.5% fee you paid on those credits.
Step 1: set the environment
OpenRouter's cookbook uses a shell profile or a project settings file. Define the key before it is used, and do not use a project .env file: the native Claude Code installer does not read it.
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{
"env": {
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
"ANTHROPIC_AUTH_TOKEN": "<your-openrouter-api-key>",
"ANTHROPIC_API_KEY": ""
}
}Step 2: clear the Anthropic login and check
- If you have used Claude Code with an Anthropic account, run
/logoutonce, then quit and startclaudeagain. - Run
/status. It should showAuth token: ANTHROPIC_AUTH_TOKENandAnthropic base URL: https://openrouter.ai/api. - Send a short prompt and look for the request in OpenRouter's Activity page.
Step 3: choose models (optional)
Claude Code asks for a model per role. To pin each role, set these variables in the same place; OpenRouter's cookbook uses its ~anthropic/...-latest aliases. Setting CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 shows a picker with a curated set of OpenRouter models instead.
export ANTHROPIC_DEFAULT_OPUS_MODEL="~anthropic/claude-opus-latest[1m]"
export ANTHROPIC_DEFAULT_SONNET_MODEL="~anthropic/claude-sonnet-latest[1m]"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="~anthropic/claude-haiku-latest"
export CLAUDE_CODE_SUBAGENT_MODEL="~anthropic/claude-opus-latest[1m]"Gotchas
- OpenRouter only guarantees Claude Code with the Anthropic first-party provider and recommends making it your top provider. Non-Anthropic models in the picker may not handle Claude Code's tools correctly.
- A stale Anthropic login causes confusing model-not-found errors. On macOS it lives in the Keychain as
Claude Code-credentials;/logoutremoves it. - In a shell profile,
ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"expands when the file loads. If the key is defined later, every request fails with an auth error. - Claude Fable is not offered in
/modelby default; setANTHROPIC_DEFAULT_FABLE_MODELto make it selectable. /fastonly sends fast mode when the Opus variable is pinned to a specific Opus ID; with the-latestalias it reports fast mode on but runs at standard speed. It also needsCLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK=1.- OpenRouter's one-command launcher runs Claude Code per session with
ori claude, but its permanent setup,ori harness setup claude, is not available yet.
What it costs
There is no subscription: Claude Code runs on your credits at Anthropic's rates, plus the 5.5% fee charged when you buy them. In our Agent Burn Index, a median coding day was 94 requests and cost $3.53 on Claude Sonnet 5.5 at list price; a busy day cost $28.97. Over 20 active days that is about $74 and $611 a month on OpenRouter. Set a credit limit on the key you give Claude Code so a long session cannot run past what you planned.
The flat-plan alternative: Claude Code on Standard Compute
Standard Compute also serves the Anthropic Messages API natively, so the setup is the same two variables with a different URL and key. Set ANTHROPIC_MODEL and every ANTHROPIC_DEFAULT_*_MODEL variable to standardcompute and the router picks a cost-efficient model per request, or to a catalog ID such as anthropic/claude-sonnet-5.5 to pin one. Leave none of them empty: Claude Code's built-in IDs such as claude-sonnet-5-5 return model_not_found. The plan is a fixed monthly price with the compute included, and new requests stop with HTTP 402 when the budget is used.
The launcher does the setup per session: install it with curl -fsSL https://standardcompute.com/cli/install.sh | sh, then run standardcompute launch claude.
export ANTHROPIC_BASE_URL="https://api.stdcmpt.com" # no /v1
export ANTHROPIC_AUTH_TOKEN="<your-standard-compute-key>"
export ANTHROPIC_MODEL="standardcompute"
export ANTHROPIC_DEFAULT_OPUS_MODEL="standardcompute"
export ANTHROPIC_DEFAULT_SONNET_MODEL="standardcompute"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="standardcompute"Run Claude Code on a fixed monthly budget
Plans start at $19 a month with $20 of compute included, and every plan can use every model. Usage counts against the monthly budget with no 5-hour or weekly windows.
FAQ
Does OpenRouter support Claude Code?
Yes. OpenRouter exposes the Anthropic Messages API, so Claude Code connects directly with ANTHROPIC_BASE_URL=https://openrouter.ai/api and your OpenRouter key in ANTHROPIC_AUTH_TOKEN. No local proxy is needed.
Why do I get model-not-found or auth errors with OpenRouter in Claude Code?
Usually a cached Anthropic login or an empty token. Run /logout, make sure ANTHROPIC_API_KEY is set to an empty string and that your OpenRouter key is defined before ANTHROPIC_AUTH_TOKEN uses it, then restart Claude Code and check /status.
Can I use non-Claude models in Claude Code through OpenRouter?
You can pin any OpenRouter model in the ANTHROPIC_DEFAULT_*_MODEL variables, but OpenRouter only guarantees Claude Code with the Anthropic first-party provider. Other models may handle Claude Code's tools differently. See Claude Code with other models.
Can I use my Claude Pro or Max subscription through OpenRouter?
No. OpenRouter bills Claude Code from your OpenRouter credits or your own provider keys. A Claude subscription is a separate product, and so is a Standard Compute plan.
Is OpenRouter cheaper than a flat plan for Claude Code?
For the same pinned model the cost is close: OpenRouter adds 5.5% to provider prices, and a Standard Compute plan includes 5% to 14% more compute than its price if you use it all. Light use is cheaper on OpenRouter. A plan wins when you want a fixed monthly cost and let routine steps run on efficient models.
Sources: OpenRouter: Claude Code integration · OpenRouter: Ori Harness · OpenRouter FAQ · Standard Compute: Claude Code