In one line: people ask whether Claude Code can point at OpenRouter, and almost nobody first checks which model class the bill will follow once it does. The path and the environment variables come first, then the four classes on one assumed token mix, then the subscription meter next to pay-as-you-go, and only then the knobs an individual developer can actually turn.
Where the request goes after it leaves the machine
Claude Code speaks the Anthropic Messages API upstream. OpenRouter exposes a compatible front, which its docs call the Anthropic skin: thinking blocks and tool use pass through, and the charge lands on your OpenRouter credits. No local proxy process is required.
The base URL is https://openrouter.ai/api, with no /v1 on the end. Claude Code appends the rest of the path itself. A URL that includes /v1 is one of the common ways to set every variable and still hit the wrong host.
The compatibility note is narrow. OpenRouter’s Claude Code guide says the integration is guaranteed only with Anthropic’s first-party provider. Other ids can show up in the model picker, and the same page says Claude Code is optimized for Anthropic models and may not behave correctly elsewhere. Connecting OpenRouter is not the same move as silently selecting the cheapest id in the catalog. A low sticker price and a tool loop that finishes are separate checks.
Credit purchases and token rates are also separate. OpenRouter’s own Claude Code write-up says inference is not marked up — you pay the catalog rate — while buying credits adds a 5.5% fee, with a $0.80 minimum. Against a class change, that fee is the small number. The tables below put the ratio on one page.
Four environment variables, and the empty one has to stay
The quick start puts the key in ANTHROPIC_AUTH_TOKEN and sets ANTHROPIC_API_KEY to an explicit empty string. The token is sent as Authorization: Bearer, which is what the gateway expects. The API key is sent as x-api-key, and Claude Code treats that as a direct Anthropic credential. The empty string stops the fallback. Deleting the old key without writing ="" can still leave a saved login in place during an interactive session.
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=""
Order matters. ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY" expands when the shell reads that line. If the key is defined later, or injected by a secrets manager after the profile runs, the token becomes an empty string and every request fails auth. In ~/.zshrc, define OPENROUTER_API_KEY first.
If you have ever signed in to Claude Code with an Anthropic account, run /logout once, quit, and start again. The docs say a cached login beside a gateway credential warns about an auth conflict at startup, and the visible symptom is often a missing model, including OpenRouter-only ids such as openrouter/auto. On macOS the cache is a Keychain item named Claude Code-credentials. A native install does not necessarily write ~/.claude/.credentials.json.
Check with /status inside the session. The auth line should name ANTHROPIC_AUTH_TOKEN, and the base URL line should read https://openrouter.ai/api. If the auth line still names ANTHROPIC_API_KEY, or the login method is still a Claude account, this process never received the variables. The same request should show on OpenRouter’s Activity page.
A project can keep the variables in .claude/settings.local.json. Do not put them in a .env file — the native installer does not read one — and do not commit the key. A committed settings file hands the credit key to every clone. For a single machine, the docs prefer the shell profile, and reading the secret from the OS keychain rather than pasting an sk-or- string into a dotfile.
An empty key and a logout are different steps
/logout clears the cached OAuth session only. A real ANTHROPIC_API_KEY still sitting in the shell is untouched, and requests can keep billing as direct Anthropic usage.
A process that will not start, or a machine that runs out of memory, is a different failure from this billing path. Install and startup errors are in the Claude Code deployment error guide.
The four classes are the unit price
Claude Code splits work across Fable, Opus, Sonnet, and Haiku, each with its own variable. Sub-agents use CLAUDE_CODE_SUBAGENT_MODEL. OpenRouter’s sample points the classes at ~anthropic/claude-…-latest and points the sub-agent sample at Opus. That sample selects a moving alias. It is not a personal budget. Aliases follow the catalog. Today ~anthropic/claude-opus-latest is priced like anthropic/claude-opus-5.5. Tomorrow it does not have to be that id.
This table is the public OpenRouter catalog on 2026-10-20, in US dollars per million tokens. Cache read is the catalog’s cache-read rate. It applies only when the provider actually hits a prefix cache, not as a discount on every input token.
| Class | Id pinned in this article | Input | Output | Cache read | 1M in + 1M out |
|---|---|---|---|---|---|
| Fable | anthropic/claude-fable-5.1 |
$10 | $50 | $0.25 | $60 |
| Opus | anthropic/claude-opus-5.5 |
$4 | $20 | $0.20 | $24 |
| Sonnet | anthropic/claude-sonnet-5.5 |
$2 | $10 | $0.10 | $12 |
| Haiku | anthropic/claude-haiku-5.5 |
$0.10 | $0.50 | $0.01 | $0.60 |
On the same day, anthropic/claude-fable-5 matched 5.1 on input and output, $10 / $50, but cache read was $1, not $0.25. anthropic/claude-opus-5 was a different row: $5 in, $25 out. anthropic/claude-sonnet-5 matched 5.5 on input and output, with cache read at $0.20, twice 5.5’s $0.10. Sharing the name Opus or Sonnet does not mean sharing the bill. If the budget in this article is the one you want to keep, pin the id. Do not stop at latest.
export ANTHROPIC_DEFAULT_FABLE_MODEL="anthropic/claude-fable-5.1"
export ANTHROPIC_DEFAULT_OPUS_MODEL="anthropic/claude-opus-5.5"
export ANTHROPIC_DEFAULT_SONNET_MODEL="anthropic/claude-sonnet-5.5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="anthropic/claude-haiku-5.5"
export CLAUDE_CODE_SUBAGENT_MODEL="anthropic/claude-haiku-5.5"
The last line is a budget choice, not the official sample. The sample puts sub-agents on Opus. If those agents mostly search files, run tests, and write summaries, leaving them on the same Opus class bills every branch at $4 / $20. Before moving them to Haiku, confirm in /model that all four classes are listed, then check the model column on Activity against the id you pinned.
$60 divided by $0.60 is 100. That is a catalog ratio, not a measurement of one session. How text becomes a billed token is in the token and price comparison. Usage and sticker prices for other families this week are in the OpenRouter rankings.
One assumed mix, and how far the classes spread
This is not an average day pulled from a log. It answers one question: hold the tokens still, change the class, what does the catalog do. Assume a working day of 8 million input tokens and 0.8 million output tokens, about 10 to 1, standing in for an agent that keeps resending context while writing much less. This section assumes cache reads are zero.
| Pinned to this class all day | That day | 22 such working days |
|---|---|---|
| Fable 5.1 | $120 | $2,640 |
| Opus 5.5 | $48 | $1,056 |
| Sonnet 5.5 | $24 | $528 |
| Haiku 5.5 | $1.20 | $26.40 |
| Half Haiku, 40% Sonnet, 10% Opus | $15 | $330 |
The arithmetic is open. An Opus 5.5 day is 8 × $4 + 0.8 × $20 = $48. The mixed row splits the same 8 million / 0.8 million: half the tokens on Haiku is $0.60, 40% on Sonnet is $9.60, 10% on Opus is $4.80, and the sum is $15. Twenty-two is about a month of working days. It is not a discount and not a plan.
A second assumption, labeled the same way: if half of that Opus day’s input is billed as cache read, then 4 million × $4 + 4 million × $0.20 + $16 of output = $32.80, not $48. A changed tool result breaks the prefix, and the next turn is back at the full input rate. $32.80 is not a promise.
The 5.5% credit fee sits outside the table. On $48 it is about $2.64. On $330 it is about $18. It does not close the $2,310 gap between an all-Fable month of these days and the mixed row. Change the class first.
Do not rank this table against a Pro subscription
$48 is already above a month of Pro, and Pro is not unlimited Opus. The figures are catalog rates times assumed tokens. If your session did not send 8 million input tokens, the table is not your day.
A subscription, the Console, and OpenRouter are three meters
On 2026-10-20 the Claude pricing page still listed these amounts, before tax, and said plans can change. Pro is $20 billed monthly, or $17 a month on the annual plan ($200 up front). Max 5x is $100 a month. Max 20x is $200 a month. Pro and Max both include Claude Code, and they share usage with Claude on the web, desktop, and phone. The help center describes a five-hour session limit plus a weekly limit. Max adds a separate weekly limit for Fable. The 5x and 20x figures are per five-hour session, relative to Pro.
OpenRouter is a different meter. The help center says that if ANTHROPIC_API_KEY is set, Claude Code bills the API instead of the usage included in the subscription. The OpenRouter path also requires /logout, an empty API key, and ANTHROPIC_AUTH_TOKEN. Once that path is live, the first request spends OpenRouter credits. It does not draw down whatever Pro allowance is left.
Pick by which wall you are hitting, not by which gateway sounds newer:
- Usage that stays inside Pro or Max is a capped price. After $20 or $100, extra sessions in that period do not keep accruing at Opus rates. They hit the limit. If the limit is enough, there is no reason to split the work onto a token meter just to use OpenRouter.
- If you hit the limit every week and would buy API credits anyway, look at whether the wall is Fable or Opus. Moving sub-agents and ordinary edits to Haiku and Sonnet is often a more direct cut than stepping up a Max tier. A higher tier buys more subscription usage. It does not lower the token rate.
- If you want a hard cap on one key, and a model column per request, OpenRouter’s key limit and Activity page show what the subscription usage bar does not. You pay catalog rates for that view, plus 5.5% when you buy credits. When direct Console rates match the catalog, that 5.5% is the gateway’s own spread, in exchange for failover and one key over every request. “No inference markup” describes that layer. It does not mean the gateway is cheaper than Pro.
Whether Claude Code and an editor assistant are even the same product is covered in Claude Code vs Cursor. That piece compares the tools. This one compares the meters after the connection is made.
Five knobs, in the order an individual developer should turn them
First, do not leave the session on Fable or Opus all day. The four variables are that knob. Long-horizon reasoning stays on Fable, hard edits on Opus, ordinary changes on Sonnet, search and short completions on Haiku. Once the id is pinned, an alias repricing does not quietly replace the class you calculated.
Second, drop sub-agents on their own. Copy the official sample and they follow Opus. One parent session that spawns three sub-agents can spend more on the branches than the reply you see in the main transcript, if every branch is Opus. On a personal budget, set CLAUDE_CODE_SUBAGENT_MODEL to Haiku, and raise it only when that subtask is the hard reasoning.
Third, /fast costs more. The docs describe up to about 2.5× output speed at a premium over the matching Opus rate. It covers Opus 4.6, 4.7, 4.8, and Opus 5. It does not cover Fable. For Claude Code’s /fast to actually send speed: "fast" through OpenRouter, you need Claude Code 2.1.96 or newer, CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK=1, and the Opus variable pinned to a concrete id such as anthropic/claude-opus-5. Pin ~anthropic/claude-opus-latest and /fast can report that it is on while the request omits speed. One more behavior matters more than the toggle copy: if the session is on Fable, /fast does not speed Fable up. Claude Code switches the session to your configured Opus, and later requests bill as Opus. Leave the switch off if you are not buying speed.
Fourth, cap the key. An OpenRouter key can have its own limit. Keep the Claude Code key separate from experimental keys, and set the monthly cap at the amount you can stand to burn. The model column on Activity is how you notice that today drifted back to Fable. The statusline script in OpenRouter’s examples repo accumulates this session’s cost and cache discounts. Each refresh asks the generation endpoint again. A long session catches up gradually. It is not an invoice.
Fifth, a longer context is an input bill. A trailing [1m] only changes the window Claude Code assumes, so it does not compact early. OpenRouter strips the marker before routing. A larger assumed window is also a larger prefix you are allowed to send. Compaction, not reading the whole repo, and keeping a stable prefix cacheable, are input savings. Cache read is already an order of magnitude below input in the table, and it applies only while tool output has not broken the prefix.
Next to the model bill is the machine bill. A session left running overnight, with a compile and a simulator fighting for the same Mac’s memory, does not show up in OpenRouter. Memory sizing is in the Claude Code server memory guide. Keep the two bills apart, or a token overrun gets misread as a slow machine.
Do not treat a non-Anthropic model as the default saving
The picker appears after CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1. The docs call it a curated list, not the full catalog, and some entries route to non-Anthropic providers. They also say to keep Anthropic first-party at the top of provider priority, and that fast mode is served only there.
One failed tool call resends a full round of context. A rate that is a fraction of Opus, retried twice, can land back in the same range with the change still unfinished. If DeepSeek or another family belongs in the coding loop, test it as its own tool. Do not drop it in as a silent substitute for one of the four Claude Code variables. Capability and price together are in DeepSeek V4 Flash vs Claude Opus.
Order for an individual developer
Check whether you are still inside the subscription pool. If you are, and the limit holds, stay on Pro or Max. If you are already paying per token, split the four classes and the sub-agents first, then put a monthly cap on the key. Other models in the picker come after that.
Questions
Which models does the OpenRouter guide actually guarantee for Claude Code? Anthropic first-party only. Other models can appear in the picker. They are outside that sentence.
Does OpenRouter add a margin on the token rate? Its Claude Code page says inference is not marked up, and the rate is the catalog rate. The extra charge is on credit purchases: 5.5%, minimum $0.80.
Is Pro cheaper than paying per token? Not without a usage number. If you stay inside Pro ($20 a month, or $17 annualized) or Max ($100 / $200), the subscription is a cap. After you connect OpenRouter, requests spend credits and no longer draw on that included usage. The $48 and $15 figures above are catalog math on assumed tokens, not your invoice.
Does /fast save money? No. It trades a higher rate for faster output, and only on some Opus models. Turning it on while the session is on Fable moves the session to Opus billing.
Is it safe to put the key in ~/.zshrc? It works, and it is plaintext. A dotfile that lands in a repo or on a clipboard leaks the key. Reading it from the OS keychain is the tighter habit. If it leaks, revoke it on OpenRouter’s keys page. For a project, use settings.local.json and do not commit it.
I changed the base URL and Activity is still empty. Why? Check /status. The auth line should be ANTHROPIC_AUTH_TOKEN, and the base URL should be https://openrouter.ai/api without /v1. Clear an old account login with /logout. A leftover ANTHROPIC_API_KEY in the shell has to be an empty string. Logout alone does not clear it.
ZavCloud Developer Infrastructure
Once the model is metered, do not make the Mac fight the build
A long session, Xcode, and a simulator share one Mac's memory. That bill is not on OpenRouter.
A dedicated Mac node is a monthly rental, separate from tokens.