Claude Code talks to the Anthropic API. OpenRouter exposes an endpoint that behaves exactly like the Anthropic API. Set three environment variables and Claude Code routes through OpenRouter instead of hitting Anthropic directly. No proxy server, no code changes, no wrapper scripts.
This is what OpenRouter calls the "Anthropic Skin." It handles model mapping, passes through extended thinking blocks, and supports native tool use. From Claude Code's perspective, it is talking to Anthropic. From your perspective, you get failover across multiple providers, a single billing dashboard, and per-key spending limits.
What Is the Anthropic Skin?
OpenRouter is an API gateway that routes requests to 400+ AI models from every major provider through a single endpoint. Most of those models use the OpenAI chat completions format. But Claude Code does not speak OpenAI format. It speaks Anthropic's native Messages API.
The Anthropic Skin solves this. It is a compatibility endpoint at https://openrouter.ai/api that accepts requests in Anthropic's exact format and returns responses in Anthropic's exact format. Model names get mapped automatically: when Claude Code requests claude-sonnet-4-20250514, OpenRouter routes it to the right provider.
Features that pass through without modification:
- Extended thinking blocks (Claude's reasoning mode)
- Native tool use and tool results
- Prompt caching with cache control headers
- Streaming responses
- System prompts and multi-turn conversations
The skin is not a translation layer that loses information. It is a wire-compatible proxy. The same bytes go in and come out, with OpenRouter handling routing, failover, and billing in between.
Why Route Claude Code Through OpenRouter
Provider Failover
Anthropic's API has outages. Every API does. When you go direct, an outage means your Claude Code session stops. When you route through OpenRouter, your request automatically cascades to backup providers hosting Claude (Google Vertex AI, AWS Bedrock). OpenRouter deprioritizes any provider that has had outages in the last 30 seconds and routes to the next healthy one.
Budget Controls
Anthropic's API billing is per-organization. OpenRouter lets you set per-key spending limits. Give each developer their own API key with a $50/day cap. When they hit the limit, requests stop. No surprise $2,000 bills from an agent loop that ran overnight.
Single Billing Dashboard
If your team uses Claude, GPT-4, Gemini, and open-source models, you are managing four billing accounts. OpenRouter consolidates them into one. One credit balance, one invoice, one dashboard showing spend per model and per key.
Model Flexibility
The Anthropic Skin routes to Claude by default. But Claude Code also supports ANTHROPIC_MODEL and ANTHROPIC_SMALL_FAST_MODEL environment variables for overriding which model handles primary and lightweight tasks. Through OpenRouter, you can point these at any compatible model. Some teams use Claude Opus for complex tasks and a cheaper model for background indexing.
Setup (3 Minutes)
Step 1: Get an OpenRouter API Key
Go to openrouter.ai/settings/keys and create a new key. Add credits to your account if you have not already.
Step 2: Set Environment Variables
Add these to your shell profile (~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish):
Shell Profile Configuration
# Route Claude Code through OpenRouter
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="sk-or-v1-your-key-here"
export ANTHROPIC_API_KEY=""ANTHROPIC_API_KEY Must Be Empty
Set ANTHROPIC_API_KEY to an empty string, not unset. If this variable contains your Anthropic key, Claude Code will try to authenticate with Anthropic instead of OpenRouter. The empty string tells Claude Code to use ANTHROPIC_AUTH_TOKEN for authentication.
Step 3: Log Out of Anthropic (If Previously Logged In)
If you previously authenticated Claude Code with Anthropic directly, run /logout inside a Claude Code session. Then restart your terminal to pick up the new environment variables.
Step 4: Verify
Open Claude Code and run /status. It should show your connection info. Send a test message and check your OpenRouter Activity Dashboard to confirm requests are flowing through.
Do Not Use .env Files
Claude Code's native installer does not read .env files. You must add these variables to your shell profile for them to persist. Alternatively, use the project-level configuration described in the next section.
Project-Level Configuration
If you only want OpenRouter routing for specific projects (not globally), create a .claude/settings.local.json file in your project root:
.claude/settings.local.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
"ANTHROPIC_AUTH_TOKEN": "sk-or-v1-your-key-here",
"ANTHROPIC_API_KEY": ""
}
}This overrides global settings for that project only. Useful when you want some projects on Anthropic direct (lower latency) and others on OpenRouter (budget-controlled).
Model Overrides
You can also override which model Claude Code uses per-project:
Model Override Environment Variables
# Primary model for complex tasks
export ANTHROPIC_MODEL="anthropic/claude-sonnet-4"
# Lightweight model for background tasks (tab completion, summaries)
export ANTHROPIC_SMALL_FAST_MODEL="anthropic/claude-haiku-4-5"Provider Fallback Behavior
OpenRouter does not just pick a random provider. It uses an intelligent routing algorithm:
- Deprioritize recent failures. Any provider with outages in the last 30 seconds drops to the bottom of the list.
- Cost-weighted selection. Among healthy providers, it selects weighted by inverse square of price, favoring cheaper options.
- Automatic cascading. If Provider A fails, the request goes to Provider C, then Provider B. No retry logic needed on your end.
You can override this default behavior with provider preferences in your request headers, though Claude Code does not expose this directly. For most users, the defaults work well.
Sorting Shortcuts
OpenRouter supports model name suffixes that change routing priority:
:nitroappended to a model name prioritizes throughput (faster token generation):floorprioritizes price (cheapest available provider)
Disabling Fallback
If you want requests to fail rather than route to a non-preferred provider, you can configure allow_fallbacks: false in the provider options. This is relevant for compliance scenarios where you need requests to stay on a specific provider (e.g., only Anthropic direct, never Vertex or Bedrock).
Cost: Direct Anthropic vs. OpenRouter
For Claude models, OpenRouter pricing typically matches Anthropic's direct rates:
| Model | Input (per 1M tokens) | Output (per 1M tokens) | Source |
|---|---|---|---|
| Claude Sonnet 4 (Anthropic Direct) | $3 | $15 | anthropic.com |
| Claude Sonnet 4 (OpenRouter) | $3 | $15 | openrouter.ai |
| Claude Opus 4.6 (Anthropic Direct) | $15 | $75 | anthropic.com |
| Claude Opus 4.6 (OpenRouter) | $15 | $75 | openrouter.ai |
| Claude Haiku 4.5 (Anthropic Direct) | $0.80 | $4 | anthropic.com |
| Claude Haiku 4.5 (Anthropic Direct) | $0.80 | $4 | openrouter.ai |
The per-token cost is functionally identical. The difference is operational. With Anthropic direct, you get slightly lower latency (one fewer network hop). With OpenRouter, you get failover, budget controls, and consolidated billing. For most teams, the latency difference is negligible. The operational benefits are not.
Cache Pricing Also Passes Through
Prompt caching discounts apply through OpenRouter. Cache reads cost 10% of standard input pricing, and cache writes cost 125%. These rates match Anthropic's direct pricing.
Team Budget Management
This is where OpenRouter adds the most value over direct Anthropic access. Anthropic's billing is per-organization. If a developer leaves an agent running overnight, the whole org pays. OpenRouter gives you per-key controls.
Per-Key Spending Limits
When creating API keys in the OpenRouter dashboard, you can set a credit limit per key. Developer A gets $50/day. Developer B gets $100/day. The intern gets $10/day. When a key hits its limit, requests return a 402 error and the developer knows to check their usage before continuing.
Usage Visibility
The Activity Dashboard shows every request with the model used, tokens consumed, cost, and which API key made the call. You can filter by key, model, or time range. This makes it straightforward to answer "who spent $300 on Opus this week?"
Real-Time Cost Statusline
You can add a custom statusline to Claude Code that shows your running cost. Add this to ~/.claude/settings.json:
Claude Code Statusline Configuration
{
"statusline": {
"type": "command",
"command": "curl -s 'https://openrouter.ai/api/v1/auth/key' -H 'Authorization: Bearer $ANTHROPIC_AUTH_TOKEN' | jq -r '.data | "$\(.usage | tostring) used"'"
}
}GitHub Actions Integration
Claude Code's official GitHub Action supports OpenRouter. Pass your OpenRouter key as the API key and set the base URL in the environment:
GitHub Actions Workflow
- name: Run Claude Code
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.OPENROUTER_API_KEY }}
env:
ANTHROPIC_BASE_URL: "https://openrouter.ai/api"This gives your CI/CD pipeline the same failover and budget controls as local development. Useful for teams that run Claude Code in automated review or code generation workflows.
Using Morph Through OpenRouter
Morph's fast-apply model is available on OpenRouter. If you use Claude Code with OpenRouter for coding and need fast, accurate code edits, you can access Morph through the same billing account and API key.
Morph specializes in code application, the step where an AI's suggested changes get merged into your existing file. It processes 10,500 tokens per second and handles the "last mile" of code generation where diffs need to be applied cleanly. Several coding agents, including tools that integrate with Claude Code, use Morph as their apply model.
Try Morph on OpenRouter
Fast, accurate code application at 10,500 tok/s. Available through the same OpenRouter account you use for Claude Code.
FAQ
Does the Anthropic Skin add latency?
One additional network hop. In practice, this adds 20-50ms to the initial connection. For Claude Code sessions where individual requests take 5-30 seconds, the added latency is not noticeable. If you are running high-frequency, low-latency API calls (not typical for Claude Code), direct Anthropic access will be faster.
Can I use this with the Claude Code VS Code extension?
Yes. The VS Code extension reads the same environment variables. Set them in your shell profile and restart VS Code. The extension will route through OpenRouter.
What if I want to switch back to direct Anthropic?
Remove or comment out the three environment variables from your shell profile, restart your terminal, and run claude to log in with your Anthropic account. The switch takes under a minute.
Does prompt caching work through OpenRouter?
Yes. Cache control headers pass through the Anthropic Skin. Cache read and write pricing matches Anthropic's direct rates. The caching happens on the provider side (Anthropic, Vertex, Bedrock), so cache hit rates depend on which provider handles your request. If failover routes you to a different provider mid-session, you may lose cached context for that request.
Can I restrict which providers OpenRouter uses?
Yes, through the provider preferences API. You can specify an ordered list of preferred providers and disable fallback entirely. Claude Code does not expose this configuration directly, but you can set it via a lightweight proxy or custom headers if your compliance requirements demand it.
Is the Anthropic Agent SDK compatible?
Yes. The Anthropic Agent SDK uses Claude Code as its runtime and reads the same environment variables. Set ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, and ANTHROPIC_API_KEY="", and your Agent SDK workflows route through OpenRouter.