HomeClaude Code › OpenRouter
OverviewInstallCLI referencePricing & limitsAgent SDKSkills & pluginsGitHubWeb, desktop & IDEModelsErrorsOpen source?TutorialFor studentsQA automationvs Cursorvs Codex & OpenCodeSubagentsHooksMCPEcosystemVS CodeOpenRouterRate limits中文指南
Last updated: September 23, 2026

How to use OpenRouter in Claude Code (and when not to)

People point Claude Code at OpenRouter for two different reasons: to pay for Claude through an account they already have, or to run other vendors' models inside Claude Code. Both work, with caveats that are worth knowing before you spend an afternoon on them.

TLDR

  • Route 1: OpenRouter's Anthropic-compatible endpoint via ANTHROPIC_BASE_URL + your OpenRouter key — Claude models only, list price plus OpenRouter's fee.
  • Route 2: claude-code-router in front of Claude Code — any OpenRouter model per task, at the cost of a local proxy and occasional tool-call quirks.
  • Non-Claude models handle Claude Code's tool schema unevenly; expect more retries.
  • If you only want Claude, a Claude gateway is cheaper than OpenRouter: the same models at 7.69× face value instead of list price plus a fee.

Route 1: point Claude Code at OpenRouter directly

OpenRouter exposes an Anthropic-compatible Messages endpoint alongside its OpenAI-style API. Claude Code only needs the base URL and a key, so the setup is the same two variables you would use for any gateway — check OpenRouter's docs for the current base path if the one below has moved:

export ANTHROPIC_BASE_URL=https://openrouter.ai/api
export ANTHROPIC_AUTH_TOKEN=sk-or-...     # your OpenRouter key
claude --model anthropic/claude-sonnet-5   # OpenRouter's model id format

Model ids follow OpenRouter's vendor/model naming, which is also what you put in the per-tier variables (ANTHROPIC_DEFAULT_SONNET_MODEL and friends). Run /status to confirm the endpoint and /model to switch. Billing is OpenRouter's: the model's list price plus OpenRouter's platform fee on credits, so this route costs slightly *more* than Anthropic direct — its point is convenience and one account, not price.

Route 2: claude-code-router for non-Claude models

claude-code-router is a local proxy that receives Claude Code's requests and forwards each one to a provider you choose by rule — default, background, think, long-context. Configure OpenRouter as a provider with your key, pick models per route, launch with ccr code. This is how people run open-weight or other vendors' models inside Claude Code.

// ~/.claude-code-router/config.json (excerpt)
{
  "Providers": [{
    "name": "openrouter",
    "api_base_url": "https://openrouter.ai/api/v1/chat/completions",
    "api_key": "sk-or-...",
    "models": ["anthropic/claude-sonnet-5", "google/gemini-2.5-pro", "deepseek/deepseek-chat"]
  }],
  "Router": { "default": "openrouter,anthropic/claude-sonnet-5", "background": "openrouter,deepseek/deepseek-chat" }
}

What breaks: Claude Code's agent loop relies on Anthropic's tool-use format, and the router has to translate it for OpenAI-style models. Strong models cope; smaller ones drop tool calls, hallucinate file paths or ignore the permission protocol, and the session degrades into retries. Keep the *default* and *think* routes on a Claude model and use the others for background work, and it is a good setup.

What it costs, honestly

  • OpenRouter direct: Anthropic list price + OpenRouter's fee. Convenient, never cheaper than Anthropic.
  • claude-code-router + OpenRouter: whatever the routed models cost; savings come from sending background tasks to cheap models, not from Claude being cheaper.
  • Claude gateway (this site): the same Claude models, billed at list rates against credits bought 87% below face value ($13 → $100 of usage), or a flat-rate unlimited plan from $1. Claude only — no other vendors.

If you only want Claude, skip OpenRouter

Most people searching for "OpenRouter in Claude Code" want one of two things: a cheaper Claude bill, or a way to pay without an Anthropic console account. OpenRouter solves the second and makes the first worse. A Claude gateway solves both — same two variables, no proxy, Claude only:

export ANTHROPIC_BASE_URL=https://aiprimetech.io
export ANTHROPIC_API_KEY=your_gateway_key
claude

And the two compose: define this gateway as an Anthropic-type provider in claude-code-router and route the Claude tiers to it while sending background tasks elsewhere. The ecosystem guide covers the router in more depth.

PlanDurationPrice
Unlimited 1 Hour1 hour$1
Unlimited 24 Hours24 hours$10
Unlimited 1 Week1 week$49
Unlimited 15 Days15 days$89

All unlimited plans →

Frequently asked questions

Can Claude Code use OpenRouter?

Yes — directly through OpenRouter's Anthropic-compatible endpoint (Claude models), or through claude-code-router for any OpenRouter model. Set ANTHROPIC_BASE_URL and your OpenRouter key for the direct route.

Is OpenRouter cheaper for Claude Code?

No. OpenRouter charges Anthropic's list price plus its own fee. Savings only come from routing background tasks to cheaper non-Claude models, or from using a Claude gateway that sells the same models below list.

Which models work best in Claude Code through OpenRouter?

Claude models, unsurprisingly — the agent loop is built around Anthropic's tool format. Other strong models work with the router; small ones struggle with tool calls.

Run Claude Code on the gateway

Same models, two environment variables, credits at 7.69× face value — or a flat-rate unlimited plan.

Get an API key See unlimited plans

AI Prime Tech is an independent API gateway and is not affiliated with, endorsed by, or sponsored by Anthropic. “Claude” and “Claude Code” are trademarks of Anthropic. Claude Code features described here follow Anthropic’s public documentation at the time of writing and change frequently; prices and model lists on this page are read from this gateway’s live settings.

More Claude Code guides

Claude Code: the complete guideHow to install Claude CodeClaude Code CLI documentation: commands and flagsClaude Code pricing and limits, explainedThe Claude Code SDK, now the Claude Agent SDKClaude Code skills and pluginsClaude Code in GitHub: the App, the Action and @claudeDoes Claude Code have a web interface? Web, desktop and IDE explainedWhich model Claude Code uses, and how to change itClaude Code errors and how to fix themIs Claude Code open source?Claude Code tutorial: your first real sessionClaude for students: Claude Code, the API and what education actually gets youHow to use Claude Code for QA automationClaude Code vs Cursor: which one, when — and how to run bothClaude Code vs Codex vs OpenCode: the terminal agents comparedClaude Code subagents: how they work, how to define them, and agent teamsClaude Code hooks: deterministic control over what the agent doesClaude Code MCP: connecting servers, scopes, remote MCP and real examplesThe Claude Code ecosystem: routers, frameworks, plugins and the lists that track themClaude Code in VS Code: the extension, the terminal route, and the errorsClaude rate limit error: what "API error: rate limit reached" means and how to fix itClaude Code 怎么用:从安装到日常使用