The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →To use Claude Code with OpenRouter, point Claude Code at OpenRouter’s Anthropic-compatible API, provide your OpenRouter key as the auth token, and explicitly clear the Anthropic API key variable. Then verify the route with /status and the OpenRouter Activity Dashboard.
What you need before you start
- Claude Code installed using its current official installation route.
- An OpenRouter API key and credits in your OpenRouter account.
- Access to your shell profile, such as
~/.zshrcor~/.bashrc.
OpenRouter’s Claude Code integration guide documents this direct connection: Claude Code sends requests to OpenRouter’s Anthropic-compatible API. No local proxy is required.
As an Amazon Associate I earn from qualifying purchases.
Configure Claude Code to use OpenRouter
Add these environment variables to your shell profile, replacing the example value with your OpenRouter API key:
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=""
The base URL directs API requests to OpenRouter. Claude Code reads the OpenRouter key through ANTHROPIC_AUTH_TOKEN; the integration guide specifically instructs you to set ANTHROPIC_API_KEY to an empty string. Leaving an Anthropic key in that variable, or failing to clear it as instructed, can cause authentication conflicts.
#1 Best Overall
Save the changes, then restart your terminal so new Claude Code processes inherit the updated environment. You can also use a supported project settings location. Do not rely on a standard project .env file: the native Claude Code installer does not read standard .env files, according to the integration guide.
Verify the connection
- Start Claude Code in the terminal where you set the variables.
- Run
/statusinside Claude Code. Check that the auth token isANTHROPIC_AUTH_TOKENand the base URL ishttps://openrouter.ai/api. - Open the OpenRouter Activity Dashboard and check that requests appear there.
These checks confirm both the configuration Claude Code reports and whether activity is reaching your OpenRouter account.
Choose model overrides carefully
OpenRouter’s integration guide documents environment variables for assigning models to Claude Code’s model roles:
| Variable | Role |
|---|---|
ANTHROPIC_DEFAULT_OPUS_MODEL |
Opus-class tasks |
ANTHROPIC_DEFAULT_SONNET_MODEL |
Sonnet-class tasks |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
Haiku-class tasks |
CLAUDE_CODE_SUBAGENT_MODEL |
Subagent work |
Set a variable only when you want to override that role, and use a current model identifier from the OpenRouter model catalog. Identifiers and availability can change, so check the catalog rather than relying on an old example.
Being able to select a model does not guarantee that every Claude Code feature will work with it. OpenRouter warns that Claude Code is optimized for Anthropic models; its integration guide does not promise feature parity with other providers. The guide also documents optional fast mode for certain Opus models, but supported models and Claude Code version requirements can change. Check the live integration guide before configuring fast mode; if a request’s fast-mode parameter is unsupported and dropped, the request may continue at standard speed.
Understand billing and usage
Requests are billed against your OpenRouter credits, and the integration guide says usage—including reasoning tokens—is visible in the OpenRouter dashboard. This setup guide does not establish current token prices. Check the live account and model pages for pricing and availability before choosing a model.
Rank #4
Fix common setup failures
Authentication still fails
- Run
/statusand confirm the base URL and auth token source. - Check that
ANTHROPIC_API_KEYis explicitly set to an empty string in the shell environment Claude Code uses. - If you changed the shell profile, restart the terminal so the updated variables are loaded.
A previous direct Anthropic login can also remain cached. In that case, run /logout in Claude Code, quit the application, and relaunch it. Logging out clears the cached login; it does not remove an ANTHROPIC_API_KEY value still present in your shell, so check the environment separately.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →A model is reported as not found
Check the exact model identifier against the current OpenRouter catalog. Also verify which credential source Claude Code is using with /status; a correct model identifier will not resolve an authentication mismatch.
A request exceeds the context length
OpenRouter’s integration guide suggests splitting the work into smaller chunks or starting a new session.
Using the same configuration with the Anthropic Agent SDK
OpenRouter also documents using the Anthropic-compatible base URL, the OpenRouter key as the auth token, and an explicitly blank Anthropic API key with the Anthropic Agent SDK in TypeScript and Python. Its SDK guide says Claude Agent SDK inherits the model override capabilities. Follow the current Agent SDK guide for package-specific code and version details.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




