Skip to content
InnovateTechie
Claude Code

Claude Code With OpenRouter: Setup, Costs and Caveats

InnovateTechieBy InnovateTechie11 min read
Share
Claude Code With OpenRouter: Setup, Costs and Caveats

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.

Claude 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:

  1. 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.
  2. 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.
  3. 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 endpointclaude-code-router (ccr)
What it isOpenRouter's hosted Anthropic-compatible APIA local translator proxy you install and run
SetupTwo environment variablesNode install, config file, ccr code launcher
ModelsAnthropic models, full feature parityAny provider ccr supports: OpenRouter, DeepSeek, Gemini, Ollama, more
Best forRunning Claude on OpenRouter billingClaude 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.

Claude Code routed through OpenRouter — ANTHROPIC_BASE_URL redirects the agent's native Anthropic API calls to OpenRouter's endpoint

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:

VariableValueWhy it matters
ANTHROPIC_BASE_URLhttps://openrouter.ai/apiRedirects every API call to OpenRouter
ANTHROPIC_AUTH_TOKENYour sk-or- keySent as the auth header OpenRouter expects
ANTHROPIC_API_KEY"" (explicitly empty)Blocks fallback to direct Anthropic auth
ANTHROPIC_DEFAULT_SONNET_MODEL / _OPUS_MODEL / _HAIKU_MODELAn OpenRouter model slugOptional — remaps each Claude Code tier
CLAUDE_CODE_SUBAGENT_MODELAn OpenRouter model slugOptional — 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:

ModelAnthropic API price (per 1M tokens, input/output)Through OpenRouter
Claude Opus 4.8$5 / $25Same list price + credit fee
Claude Sonnet 5$2 / $10 introductory until August 31, then $3 / $15Same list price + credit fee
Claude Sonnet 4.6$3 / $15Same list price + credit fee
Claude Haiku 4.5$1 / $5Same 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.

OpenRouter credit fee stacked on top of pass-through Anthropic model pricing for Claude Code sessions

The caveats the tutorials skip

A week of daily Claude Code with OpenRouter use surfaced five, in descending order of pain:

CaveatWhat we observedMitigation
Prompt caching fragilitySupported on paper; in practice cache behavior depends on OpenRouter's provider routing, and client bug reports about missed Anthropic cache hits are easy to findWatch cache_read figures; pin the Anthropic provider
The 5.5% feeEvery Claude token costs more than directAccept it, or BYOK past 1M requests
Added latencyOne extra network hop per request — trivial once, noticeable across hundreds of streamed tool calls in an agentic sessionNone; it's structural
Unofficial pairingAnthropic supports gateway variables generally, not OpenRouter specifically; a Claude Code update can break the skin until OpenRouter catches upKeep 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:

  1. 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.
  2. 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.
  3. 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

PlanPrice
Free$0
Pro$20 / month
Maxfrom $100 / month
APIPay per token

For the full breakdown of every plan, see our how much Claude costs guide.

Frequently Asked Questions

Set ANTHROPICBASEURL to https://openrouter.ai/api, set ANTHROPICAUTHTOKEN to your OpenRouter API key (it starts with sk-or-), and set ANTHROPICAPIKEY to an empty string. Restart Claude Code, then run /status to confirm the new base URL. No proxy, router, or extra software is needed for Anthropic models.

Not for Anthropic models — OpenRouter's native Anthropic-compatible endpoint accepts Claude Code's own protocol, so two environment variables replace the proxy entirely. Older tutorials predate that endpoint. claude-code-router still earns its install when you want non-Anthropic models or custom routing rules running inside Claude Code.

Yes. Pointed at OpenRouter, Claude Code bills every request against prepaid OpenRouter credits, pay-as-you-go, with no Claude Pro or Max seat and no Anthropic API account required. You install and run Claude Code exactly as normal; only the backend endpoint and the billing relationship change.

A cached Anthropic login outranks your new environment variables. Run /logout once inside Claude Code, restart the app completely, and confirm /status now shows the OpenRouter base URL. Check that ANTHROPICAPIKEY is set to an empty string too — leaving it unset lets Claude Code fall back to Anthropic.

No. OpenRouter passes Anthropic's per-token prices through unchanged, then adds a 5.5% fee when you buy credits, so the direct API always lands slightly cheaper for Claude usage. Real savings only appear when you swap in cheaper non-Anthropic models or lean on the free tier for light tasks.

You'll need claude-code-router — a local translator that converts Claude Code's Anthropic-format requests into whatever the target model expects, and back. Expect rougher edges: Anthropic-specific behavior like extended thinking degrades or disappears on other model families, and tool-calling reliability varies noticeably from model to model.

Barely. Free variants are capped at 20 requests per minute and 50 per day — 1,000 once you have ever bought $10 of credits — and one agentic session chews through that, ending in the same wall as a [Claude Code rate limit error](/claude-code-rate-limit-error). Fine for experiments, wrong for daily work.
InnovateTechie

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 →