The configuration
From OpenRouter's Claude Code guide:
export OPENROUTER_API_KEY="your-openrouter-key"
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""
- The base URL is
https://openrouter.ai/api—no/v1. ANTHROPIC_API_KEYmust be explicitly empty to avoid conflicts.- Define
OPENROUTER_API_KEYbefore referencing it, or the token ends up blank and you get an auth error.
Step by step
Create an OpenRouter key
Add credits and create a key in your OpenRouter dashboard.
Set the variables
Use the exports above, or put the same values under
envin~/.claude/settings.jsonor.claude/settings.local.json. Don't rely on a project.envfile—the native install doesn't read it.Log out of Anthropic
If you previously signed in, run
/logout, quit, and startclaudeagain.Verify
/statusshould showAuth token: ANTHROPIC_AUTH_TOKENandAnthropic base URL: https://openrouter.ai/api.
Things to know
OpenRouter states Claude Code "is only guaranteed to work with the Anthropic first-party provider." Routing to other providers or non-Anthropic models may not work correctly.
- Fast mode is only available when requests are routed to Anthropic first-party.
- OpenRouter can fail over between providers; pin them with
provider.orderorprovider.onlyif you need consistency. - Using a gateway disables Anthropic's Remote Control and cloud sessions, which require a claude.ai login.
Run it on AlwaysAgent
AlwaysAgent gives you a dedicated Linux server with Claude Code and Codex preinstalled. Paste your OpenRouter key in settings and the workspace configures the variables for you. Your key stays on your server; we never proxy your requests or add a markup, and your tasks keep running after you close the browser.
FAQ
Why does Claude Code say my OpenRouter key is invalid?
Can I use non-Claude models through OpenRouter in Claude Code?
Can I use Codex with OpenRouter too?
Skip the setup
AlwaysAgent runs Claude Code on your own cloud server. Paste your OpenRouter key in settings and work from any browser, including your phone.
Try it for $0.05/h →