OpenRouter Claude Code: Setup, Costs and Free Credits

Set up OpenRouter with Claude Code step by step, see what it costs versus Anthropic direct, and find free credits to cover it via AI Perks.

OpenRouter Claude CodeClaude Code OpenRouterClaude Code SetupOpenRouterFree AI CreditsAI Perks
Andrew
Andrew
AI Perks Team
10,615•

Quick Answer

Point Claude Code at https://openrouter.ai/api, put your OpenRouter key in ANTHROPIC_AUTH_TOKEN, blank ANTHROPIC_API_KEY, run /logout if you used an Anthropic login, then relaunch and check /status. No local proxy is needed. Free Anthropic and OpenRouter credits to fund it are listed at getaiperks.com.

AI Perks

AI Perks curates and provides access to exclusive discounts, credits, and deals on AI tools, cloud services, and APIs to help startups and developers save money.

AI Perks Cards

How do you use Claude Code with OpenRouter?

Set the base URL to https://openrouter.ai/api, put your OpenRouter API key in ANTHROPIC_AUTH_TOKEN, and blank ANTHROPIC_API_KEY. Claude Code then talks to OpenRouter directly, with no local proxy, and bills your OpenRouter credits.

This is the setup described in the official OpenRouter guide for Claude Code. In its words, Claude Code speaks its native protocol directly to OpenRouter and no local proxy server is required. That is the main difference from tools like Claude Code Router, which run a proxy on your machine (see our Claude Code Router guide if you want that route instead).

The rest of this article covers the exact variables, where they go, the caveats OpenRouter states, what it costs, and how free credits can pay for it.


Top AI Credits for Startups

Apply directly through these verified programs.

Which environment variables does OpenRouter need?

Three variables do the work. The guide asks for the full OpenRouter API URL including the scheme, so a bare hostname will not do.

VariableValueWhy
ANTHROPIC_BASE_URLhttps://openrouter.ai/apiSends Claude Code traffic to OpenRouter
ANTHROPIC_AUTH_TOKENYour OpenRouter API keyAuthenticates with OpenRouter
ANTHROPIC_API_KEYEmpty stringBlanked explicitly to prevent conflicts

The base URL is the part people most often get wrong when searching for a claude code base url openrouter answer. Use https://openrouter.ai/api exactly, with https:// at the front.

Blanking ANTHROPIC_API_KEY matters because Claude Code reads both variables. If an old Anthropic key is still set, it can conflict with the OpenRouter token.


Where should you put the variables, and where not?

You have two supported places, and one place that does not work.

Option 1: your shell profile. OpenRouter recommends this for persistence. Add the variables there, then reload your shell. The guide is blunt about the reload: skip it and you keep testing the old environment, then wrongly conclude the configuration is broken.

Option 2: a project-level settings file. You can instead use .claude/settings.local.json in your project root. This keeps the configuration scoped to one project.

Not a .env file. The guide says not to put these in a project-level .env file, because the native Claude Code installer does not read standard .env files.

One more trap: if your OpenRouter key lives in another variable that ANTHROPIC_AUTH_TOKEN refers to, define it before it is consumed. Otherwise auth fails. The guide suggests a file that loads earlier, such as ~/.zshenv for zsh.


Top AI Credits for Startups

Apply directly through these verified programs.

How do you set it up, step by step?

Step 1: Get credits through AI Perks

Claude Code through OpenRouter is billed from your OpenRouter credits, so start by finding free ones. The AI Perks Guide lists OpenRouter credits of up to $3,000, plus Anthropic credits you can use if you bring your own key. Check the catalogue for amounts and details before you spend your own money.

Step 2: Create an OpenRouter API key

Generate a key in your OpenRouter account settings. This is the value that goes into ANTHROPIC_AUTH_TOKEN.

Step 3: Add the variables

Put the base URL, the auth token and the blank ANTHROPIC_API_KEY in your shell profile, or in .claude/settings.local.json. Do not use a .env file. Reload your shell afterwards.

Step 4: Run /logout if needed

If you previously logged in to Claude Code with an Anthropic account, run /logout once to remove the cached session. Then quit and relaunch claude so it picks up the new variables. If you never logged in with Anthropic, you can skip this step.

Step 5: Verify with /status

Run /status inside Claude Code to confirm the connection. Then check your OpenRouter dashboard: usage, including reasoning tokens, appears there.


What caveats does OpenRouter state?

The guide is clear about the limits, and they affect how you should configure things.

  • First-party Anthropic only. Claude Code with OpenRouter is only guaranteed to work with the Anthropic first-party provider. For maximum compatibility, OpenRouter recommends making Anthropic 1P the top-priority provider.
  • Other models may break. Claude Code is optimized for Anthropic models and may not work correctly with other providers. Treat non-Anthropic models as an experiment, not a default.
  • Context window assumption. Claude Code assumes a 200k context window unless the model name ends in [1m].
  • Failover. Requests automatically fail over between multiple Anthropic providers when routed through OpenRouter.
  • Privacy. OpenRouter does not log your source code prompts unless you opt in to prompt logging in your account settings.

That first caveat is why "claude code openrouter free" searches need care. OpenRouter does offer free models, but they are capped, and Claude Code is only guaranteed on Anthropic first-party. Free models are limited to 20 requests per minute and 50 per day, rising to 1,000 per day after you have bought at least $10 of credits. See our OpenRouter free tier guide for the full breakdown.


Top AI Credits for Startups

Apply directly through these verified programs.

Can you use fast mode through OpenRouter?

Yes, but only under specific conditions. Anthropic's fast mode gives up to 2.5x faster output at premium pricing, priced above the standard token rates of the underlying Opus model.

RequirementDetail
ModelsClaude Opus 4.6, 4.7, 4.8 and Claude Opus 5
Claude Code versionv2.1.96 or newer
Environment variableCLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK=1 to use /fast
ProviderAnthropic first-party only
Model settingPin the Opus variable to a specific ID such as anthropic/claude-opus-5

Fast mode is only served by the Anthropic first-party provider, since other providers such as Amazon Bedrock and Google Vertex do not support it. To actually get it, pin the Opus model variable to a specific Opus ID rather than the latest alias. The guide does not publish the premium multiplier here, so check current rates before you rely on it.


What does Claude Code on OpenRouter cost versus Anthropic direct?

OpenRouter does not mark up inference. Inference is billed at the provider's list price on every plan. The fee is charged when you buy credits, never on individual requests.

Here is what the fee works out to on a $10 credit purchase:

Credit purchaseFee rateFee on $10
Non-crypto, Standard5.5%, $0.80 minimum$0.80 (5.5% of $10 is $0.55, below the minimum, so the minimum applies)
Crypto5.0% flat, no minimum$0.50 (5.0% of $10)
Non-crypto, Business8%$0.80 (8% of $10)

So the honest comparison is this: the per-token price is the provider's list price, and OpenRouter adds a purchase fee on top. Paying Anthropic directly avoids that fee. What you get for it is one key, one dashboard, and failover between Anthropic providers.

Per-model token prices are not published on the OpenRouter pricing page. They have to be read from the models API. For Anthropic's own numbers, see our Claude API pricing breakdown.

How does BYOK change the math?

Standard and Business plans include $25,000 per month of list-price inference through BYOK (bring your own key) with no OpenRouter fee. Above that allowance, OpenRouter charges 5% of what the request would cost at list price, deducted from your credits.

With BYOK, you control rate limits and costs through your own provider account. That is where free vendor credits become useful: if your provider account holds credits, your Claude Code usage can draw on them, subject to that vendor's own credit terms.


Top AI Credits for Startups

Apply directly through these verified programs.

Which free credits can cover your Claude Code usage?

These are the catalogue amounts most relevant to running Claude Code. Details, and what each perk involves, are in the AI Perks catalogue.

CompanyFree creditsHow to get
OpenRouterUp to $3,000Get this perk
Anthropic (direct)$20,000Get this perk
Claude via partnersUp to $100,000Get this perk
AWS (Amazon Bedrock)$300,000Get this perk

Total across these four rows: $3,000 + $20,000 + $100,000 + $300,000 = up to $423,000 in listed credits.

The catalogue also lists credits from OpenAI, Google Cloud, Azure OpenAI, Mistral AI, Together AI, Cerebras and Novita AI. Those are mainly useful if you want to test non-Anthropic models, keeping in mind OpenRouter's warning that Claude Code may not work correctly with them. For the Anthropic side specifically, read our guide to a free Anthropic API key, and see the catalogue for the larger Claude credit amounts.


FAQ

Does Claude Code need a local proxy to work with OpenRouter?

No. OpenRouter states that Claude Code speaks its native protocol directly to OpenRouter and no local proxy server is required. You only set environment variables. A proxy-based tool such as Claude Code Router is a different approach, useful when you want custom routing rules across many models.

Why does Claude Code still use my old Anthropic login?

You probably have a cached session. Run /logout once, then quit and relaunch claude so it reads the new variables. Also confirm you reloaded your shell after editing the profile, and that ANTHROPIC_API_KEY is blank. Check the result with /status.

Can I use Claude Code with OpenRouter for free?

Partly. New OpenRouter users get a small free allowance, and free models exist with caps of 20 requests per minute and 50 per day. But Claude Code is only guaranteed on the Anthropic first-party provider. For real usage, look at free credits listed at getaiperks.com.

Does OpenRouter charge extra per request for Claude models?

No. Inference is billed at the provider's list price, and OpenRouter's fee applies when you buy credits: 5.5% on Standard and 8% on Business. Non-crypto purchases have an $0.80 minimum, and crypto purchases carry a flat 5.0%. Compare that with paying Anthropic directly using the Anthropic credits in the catalogue.

Can I use free Anthropic credits through OpenRouter?

Through BYOK, you attach your own provider key and costs run through your provider account. Standard and Business include a $25,000 monthly BYOK allowance with no OpenRouter fee. To find Anthropic credits worth up to $100,000 via partners, see the catalogue at AI Perks.

Why is my Claude Code context window 200k?

Claude Code assumes a 200k context window unless the model name ends in [1m]. If you want Claude Code to treat the window as larger, the model name has to carry that suffix. The guide does not publish further detail on which models support it.


Top AI Credits for Startups

Apply directly through these verified programs.

Ready to fund your Claude Code setup?

The setup takes minutes. The cost is the part worth planning: OpenRouter credits, Anthropic credits and cloud credits are all tracked in one catalogue, so you can match the right credits to your usage before paying list price.

Get free AI credits at getaiperks.com →

Browse the full catalogue of free AI credits at getaiperks.com and run Claude Code on credits you did not pay for.

AI Perks

AI Perks curates and provides access to exclusive discounts, credits, and deals on AI tools, cloud services, and APIs to help startups and developers save money.

AI Perks Cards

This content is for informational purposes only and may contain inaccuracies. Credit programs, amounts, and eligibility requirements change frequently. Always verify details directly with the provider.