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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To use Claude Code with OpenRouter, point Claude Code at OpenRouter’s Anthropic-compatible API, pass your OpenRouter key as its auth token, and explicitly clear the Anthropic API-key variable. Then use /status to confirm the route. The configuration is direct—no local proxy is required—and requests are billed to your OpenRouter credits.

Set up Claude Code to use OpenRouter

Install Claude Code using its official installation route, then set the four environment variables in the shell that launches Claude Code:

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=""
  1. Provide the OpenRouter credential. OPENROUTER_API_KEY holds your OpenRouter key, and ANTHROPIC_AUTH_TOKEN passes that value to Claude Code as the authentication token.
  2. Set the endpoint. ANTHROPIC_BASE_URL directs Claude Code requests to OpenRouter’s Anthropic-compatible API at https://openrouter.ai/api.
  3. Explicitly clear the Anthropic key. Keep ANTHROPIC_API_KEY set to an empty string. OpenRouter’s setup guide specifies this to avoid credential conflicts; do not leave an old Anthropic key in this variable.

For persistent settings, put the exports in the shell profile you use, such as ~/.zshrc or ~/.bashrc, or use a supported Claude Code project settings location. A standard project .env file is not a substitute: the native Claude Code installer does not read it, according to the integration guide.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Confirm requests are going through OpenRouter

  1. Restart the terminal after changing a shell profile so the new process receives the updated environment.
  2. Launch Claude Code and run /status.
  3. Confirm the status shows ANTHROPIC_AUTH_TOKEN as the auth token source and https://openrouter.ai/api as the base URL.
  4. Check the OpenRouter Activity Dashboard for incoming requests.

These checks are recommended in OpenRouter’s Claude Code integration guide. A correct local status verifies the configured route; the dashboard provides a separate check that requests are reaching the account.

Fix authentication problems

Claude Code still uses an Anthropic login

If Claude Code was previously authenticated directly with Anthropic, run /logout inside Claude Code, quit the application, and relaunch it after setting the OpenRouter environment. Logging out clears a cached login, but it does not remove credentials still present in the shell environment. The troubleshooting guidance recommends checking the environment separately.

Authentication still fails

  • Check that ANTHROPIC_API_KEY is explicitly empty in the shell profile and in the environment used to launch Claude Code.
  • Confirm that ANTHROPIC_AUTH_TOKEN references the OpenRouter key and that the base URL is exactly https://openrouter.ai/api.
  • Restart the terminal after editing the profile, then relaunch Claude Code.
  • Run /status again to see which token source and base URL Claude Code is using.

These steps address separate possible causes: a cached login, a conflicting key, or a terminal process that has not loaded the updated environment. See OpenRouter’s integration troubleshooting instructions.

A model is reported as not found

Check that the model identifier matches the current entry in the OpenRouter model catalog, and verify the credential source in /status. Model identifiers and availability can change, so do not rely on a remembered name.

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

A request exceeds the context length

Break the work into smaller chunks or start a new Claude Code session, as the integration guide suggests.

Choose model roles carefully

The integration guide documents environment variables for assigning models to Claude Code roles:

  • ANTHROPIC_DEFAULT_OPUS_MODEL for Opus-class tasks.
  • ANTHROPIC_DEFAULT_SONNET_MODEL for Sonnet-class tasks.
  • ANTHROPIC_DEFAULT_HAIKU_MODEL for Haiku-class tasks.
  • CLAUDE_CODE_SUBAGENT_MODEL for subagent work.

Use the current model identifiers shown in the OpenRouter catalog and follow the integration guide for setting role overrides. Being selectable through OpenRouter does not guarantee that every model will support Claude Code features: OpenRouter cautions that Claude Code is optimized for Anthropic models, and other providers may not behave correctly.

The guide also documents optional fast mode for particular Opus models, with a Claude Code version requirement for /fast. Because supported models and version requirements can change, check the live integration documentation before relying on fast mode. If a model does not support the fast-mode parameter, the request may continue at standard speed if that parameter is dropped.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Understand routing, usage, and billing

Claude Code connects directly to OpenRouter’s Anthropic-compatible API at the configured base URL; this setup does not require a local proxy. Requests are charged against OpenRouter credits, and OpenRouter says usage—including reasoning tokens—appears in its dashboard. Check the live account and model pages for current prices and availability; this setup guide does not establish a current token-price comparison.

Use the same configuration with the Anthropic Agent SDK

OpenRouter also documents using this environment configuration with the Anthropic Agent SDK in TypeScript and Python: use the Anthropic-compatible base URL, pass the OpenRouter key as the auth token, and explicitly blank ANTHROPIC_API_KEY. The SDK documentation says Claude Agent SDK inherits model override capabilities. Follow the current Agent SDK instructions for package-specific code and setup details; examples may change as package versions evolve.

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.