Part ofWhat Is Claude Code? The Complete Guide
Point Claude Code at OpenRouter with two environment variables. Setup steps, honest cost math vs the direct Anthropic API, and the caveats tutorials skip.
In This Article
8 sectionsClaude Code with OpenRouter works by pointing two environment variables at OpenRouter's Anthropic-compatible endpoint: set ANTHROPIC_BASE_URL to https://openrouter.ai/api and ANTHROPIC_AUTH_TOKEN to your OpenRouter key. Claude Code then bills every request to prepaid OpenRouter credits instead of an Anthropic account — same Claude models, one key, roughly 5.5% extra in platform fees.
We publish this site with Claude Code, Anthropic's terminal coding agent — if that sentence needs unpacking, start with our pillar guide, What Is Claude Code? — and we ran Claude Code with OpenRouter as our only backend for a full week to test the one-key-many-models pitch against real work. Short version: the setup genuinely takes five minutes, the savings are smaller than the tutorials promise, and two caveats matter more than anything those tutorials mention.
Why run Claude Code with OpenRouter?
Three reasons hold up in practice, and one popular reason doesn't:
- One key, hundreds of models. OpenRouter fronts models from dozens of providers behind a single API key and a single invoice. If your team already routes GPT, Gemini, and DeepSeek traffic through it, adding Claude Code to that same billing pipe is genuinely convenient.
- No Anthropic account required. Requests bill against OpenRouter credits pay-as-you-go. That matters if you can't get an Anthropic API account approved, your company has an OpenRouter contract but no Anthropic one, or you want to try the agent without a subscription — Is Claude Code Free? covers what the entry points cost otherwise.
- Provider failover. OpenRouter serves Anthropic models from multiple upstream providers and fails over between them automatically when one is down or rate-limited. During an Anthropic incident, that redundancy is real.
The reason that doesn't hold up: cheaper Claude. Run Claude Code with OpenRouter and per-token Claude pricing still matches Anthropic's list price, with the platform fee on top. We'll do that math below.
How it works: native endpoint or claude-code-router
Claude Code speaks the Anthropic Messages API and nothing else. The trick is that it reads ANTHROPIC_BASE_URL at startup, so any server that understands Anthropic's request format can stand in for the real thing. OpenRouter ships exactly that — an endpoint it calls the Anthropic Skin — and its Claude Code integration cookbook confirms the skin passes thinking blocks, native tool use, streaming, and prompt caching through untouched on Anthropic models. That native endpoint is the reason Claude Code with OpenRouter no longer needs middleware.
Older tutorials predate it and route through claude-code-router (ccr), a community proxy by musistudio that runs locally, translates Claude Code's requests into other providers' formats, and adds routing rules. Both paths still exist; they solve different problems:
| Native OpenRouter endpoint | claude-code-router (ccr) | |
|---|---|---|
| What it is | OpenRouter's hosted Anthropic-compatible API | A local translator proxy you install and run |
| Setup | Two environment variables | Node install, config file, ccr code launcher |
| Models | Anthropic models, full feature parity | Any provider ccr supports: OpenRouter, DeepSeek, Gemini, Ollama, more |
| Best for | Running Claude on OpenRouter billing | Claude Code alternative models and custom per-task routing |
The rule we'd give a colleague: staying on Claude models, use the native endpoint; swapping in DeepSeek or a local Ollama model, that's a claude-code-router job.
The five-minute Claude Code OpenRouter setup
Create a key at openrouter.ai (it starts with sk-or-), load some credits, then export three variables in your shell profile:
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="sk-or-your-key-here"
export ANTHROPIC_API_KEY=""
That last line trips people constantly. ANTHROPIC_API_KEY must be an empty string, not unset — leave it undefined and Claude Code can fall back to authenticating against Anthropic directly. Here's the full variable map for Claude Code with OpenRouter:
| Variable | Value | Why it matters |
|---|---|---|
ANTHROPIC_BASE_URL | https://openrouter.ai/api | Redirects every API call to OpenRouter |
ANTHROPIC_AUTH_TOKEN | Your sk-or- key | Sent as the auth header OpenRouter expects |
ANTHROPIC_API_KEY | "" (explicitly empty) | Blocks fallback to direct Anthropic auth |
ANTHROPIC_DEFAULT_SONNET_MODEL / _OPUS_MODEL / _HAIKU_MODEL | An OpenRouter model slug | Optional — remaps each Claude Code tier |
CLAUDE_CODE_SUBAGENT_MODEL | An OpenRouter model slug | Optional — picks the model subagents run on |
Most OpenRouter Claude Code guides stop at the export lines, so here are two placement notes from our own stumbles. First, a project-level .env file does nothing — the native Claude Code installer doesn't read one; use your shell profile or an env block in .claude/settings.local.json. Second, if you ever logged into Claude Code with an Anthropic account, run /logout once and restart, because the cached credential outranks your environment variables. Then run /status and check the base URL it reports. This override mechanism isn't a hack, incidentally — Anthropic documents ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN as the supported way to route Claude Code through a gateway in its LLM gateway documentation. If authentication still misbehaves after all that, our walkthrough on authenticating Claude Code in the terminal traces the whole credential chain.
What Claude Code with OpenRouter actually costs
OpenRouter's business model is refreshingly legible: it passes each provider's per-token price through unchanged and takes a 5.5% fee (minimum $0.80) when you purchase credits, or about 5% on crypto payments. Bring your own Anthropic key (BYOK) and the first million requests each month are free, then a 5% fee applies. So the Claude sticker prices you're comparing are Anthropic's own:
| Model | Anthropic API price (per 1M tokens, input/output) | Through OpenRouter |
|---|---|---|
| Claude Opus 4.8 | $5 / $25 | Same list price + credit fee |
| Claude Sonnet 5 | $2 / $10 introductory until August 31, then $3 / $15 | Same list price + credit fee |
| Claude Sonnet 4.6 | $3 / $15 | Same list price + credit fee |
| Claude Haiku 4.5 | $1 / $5 | Same list price + credit fee |
Run the numbers on a heavy month — say $200 of Claude Sonnet 4.6 usage — and Claude Code with OpenRouter costs about $211 for identical tokens. Not ruinous, never cheaper. The full direct-API math lives in our Anthropic Claude API pricing breakdown, and How Much Does Claude Cost? maps every plan against it.
Where OpenRouter genuinely saves money is changing the model, not the route. Claude Code alternative models like DeepSeek and Gemini cost a fraction of Claude's rates through claude-code-router, and OpenRouter's :free models cost nothing — within limits we'll get to.
The caveats the tutorials skip
A week of daily Claude Code with OpenRouter use surfaced five, in descending order of pain:
| Caveat | What we observed | Mitigation |
|---|---|---|
| Prompt caching fragility | Supported on paper; in practice cache behavior depends on OpenRouter's provider routing, and client bug reports about missed Anthropic cache hits are easy to find | Watch cache_read figures; pin the Anthropic provider |
| The 5.5% fee | Every Claude token costs more than direct | Accept it, or BYOK past 1M requests |
| Added latency | One extra network hop per request — trivial once, noticeable across hundreds of streamed tool calls in an agentic session | None; it's structural |
| Unofficial pairing | Anthropic supports gateway variables generally, not OpenRouter specifically; a Claude Code update can break the skin until OpenRouter catches up | Keep a direct API key for fallback |
| Free-model limits | :free models cap at 20 requests/minute and 50/day (1,000/day once you've ever bought $10 of credits) | Treat free models as demos only |
The caching row deserves the emphasis. Claude Code sessions resend a huge, mostly-stable context every turn, so on the direct API most input tokens bill as cache reads at roughly a tenth of full price. OpenRouter supports Anthropic's cache controls and uses sticky routing to keep you on the same upstream provider, but every moving part it adds is a chance for a cold cache — and a cold cache re-bills those tokens at full input price, which swamps any fee comparison instantly. Claude Code with OpenRouter is an unofficial pairing at the end of the day, and caching is where you feel it first.
When the direct route is simply better
We'd steer you back to Anthropic in three situations:
- You only run Claude models. Direct API access is 5.5% cheaper for identical tokens, first-party prompt caching is the most dependable version of Claude Code's biggest cost lever, and new features reach you the day Anthropic ships them.
- You use Claude Code heavily every day. Flat-rate subscriptions beat per-token billing on both routes: Claude Pro is $20/month with Claude Code included, and the Max tiers at $100 (5x usage) and $200 (20x usage) are built for all-day agentic work. Our Claude Max review covers where the break-even sits.
- You need support and predictability. With a direct account, billing disputes, rate-limit increases, and incident comms come from Anthropic. Through a reseller, you're one hop removed.
Our own default after the experiment: subscription for daily driving, direct API key for automation, and we keep Claude Code with OpenRouter configured as a named fallback profile for provider outages. That's the honest ranking.
Verdict
Claude Code with OpenRouter is a legitimate, officially-tolerated configuration that solves three specific problems — consolidated multi-provider billing, Claude access without an Anthropic account, and failover — and it solves them well. It is not a discount. You pay list price plus 5.5% for the same Claude Sonnet 4.6 or Claude Opus 4.8 tokens, you accept a slightly longer request path, and you inherit caching behavior that's one abstraction further from your control. Use OpenRouter with Claude Code when the flexibility is the point; stay direct when Claude is the point.
Claude pricing at a glance
| Plan | Price |
|---|---|
| Free | $0 |
| Pro | $20 / month |
| Max | from $100 / month |
| API | Pay per token |
For the full breakdown of every plan, see our how much Claude costs guide.
Frequently Asked Questions

Written by
InnovateTechie
Writing about Claude and the Anthropic toolkit — models, Claude Code, pricing, features, and fixes, in clear, practical, hands-on guides tested by daily use.
View all posts →





