Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

How to Set Up Claude Code with OpenRouter: Configuration and Troubleshooting

Route Claude Code through OpenRouter by setting its Anthropic-compatible endpoint and auth token, then verify the setup and troubleshoot common issues.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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 ~/.zshrc or ~/.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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

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

  1. Start Claude Code in the terminal where you set the variables.
  2. Run /status inside Claude Code. Check that the auth token is ANTHROPIC_AUTH_TOKEN and the base URL is https://openrouter.ai/api.
  3. 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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fix common setup failures

Authentication still fails

  • Run /status and confirm the base URL and auth token source.
  • Check that ANTHROPIC_API_KEY is 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.