TokenMix Research Lab · 2026-04-30

Claude Code with OpenRouter 2026: Setup, Limits, Alternatives
Last Updated: 2026-04-30
Author: TokenMix Research Lab
Data checked: 2026-04-30
Claude Code can route through OpenRouter by overriding Anthropic environment variables. The reliable path is Anthropic first-party models through OpenRouter, not random free models.
OpenRouter's Claude Code guide says Claude Code with OpenRouter is only guaranteed to work with the Anthropic first-party provider and recommends setting Anthropic 1P as the top-priority provider. Claude Code environment docs confirm ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, and ANTHROPIC_API_KEY control custom API routing and authentication. OpenRouter's setup requires ANTHROPIC_BASE_URL="https://openrouter.ai/api", ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY", and an explicitly blank ANTHROPIC_API_KEY. That works, but it is not the same as guaranteed compatibility with every OpenRouter model.
Table of Contents
- Quick Answer
- Confirmed vs Caveat
- Setup Checklist
- Shell Setup
- Project Settings Setup
- Verify The Connection
- Model Selection Rules
- OpenRouter vs TokenMix.ai vs Direct Claude
- Cost And Limit Math
- Common Failure Modes
- When To Use Each Path
- Final Recommendation
- FAQ
- Related Articles
- Sources
Quick Answer
Use these environment variables:
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=""
Then start Claude Code:
claude
This is a useful setup for team budget controls, provider failover, and OpenRouter usage visibility. If your goal is a general multi-model API gateway for apps rather than Claude Code itself, compare TokenMix.ai and other OpenRouter alternatives.
Confirmed vs Caveat
| Claim | Status | Source / note |
|---|---|---|
Claude Code supports ANTHROPIC_BASE_URL |
Confirmed | Claude Code environment docs |
Claude Code supports ANTHROPIC_AUTH_TOKEN |
Confirmed | Claude Code environment docs |
| OpenRouter has an official Claude Code guide | Confirmed | OpenRouter docs |
OpenRouter base URL for Claude Code is https://openrouter.ai/api |
Confirmed | OpenRouter guide |
ANTHROPIC_API_KEY should be explicitly blank for OpenRouter setup |
Confirmed | OpenRouter guide |
/status can verify the connection |
Confirmed | OpenRouter guide |
| Every OpenRouter model works well in Claude Code | False | OpenRouter says only Anthropic 1P is guaranteed |
| Free models are production-safe for Claude Code | No | Free tiers have rate limits and tool compatibility risks |
Setup Checklist
| Requirement | Value | Why it matters |
|---|---|---|
| Claude Code installed | Native installer or npm path | The CLI reads its own auth/session config |
| OpenRouter API key | OPENROUTER_API_KEY |
Used as bearer token |
| Base URL | https://openrouter.ai/api |
No /v1 here for Claude Code |
| Auth token | ANTHROPIC_AUTH_TOKEN |
Claude Code sends bearer auth |
| Blank API key | ANTHROPIC_API_KEY="" |
Prevents direct Anthropic key conflict |
| Provider priority | Anthropic first-party | OpenRouter compatibility warning |
| Verification | /status inside Claude Code |
Confirms base URL and token source |
The most common mistake is using the normal OpenRouter OpenAI-compatible base URL https://openrouter.ai/api/v1. Claude Code's OpenRouter guide uses https://openrouter.ai/api.
Shell Setup
Add this to your shell profile, such as ~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish:
export OPENROUTER_API_KEY="sk-or-your-key"
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""
Reload the shell:
source ~/.zshrc
Start Claude Code:
cd /path/to/your/project
claude
If Claude Code was already logged in to Anthropic, run:
/logout
Then restart Claude Code so the custom OpenRouter environment takes effect.
Project Settings Setup
Claude Code environment variables can also be configured in settings. Use this only when you intentionally want a project or team-level route.
{
"env": {
"OPENROUTER_API_KEY": "sk-or-your-key",
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
"ANTHROPIC_AUTH_TOKEN": "sk-or-your-key",
"ANTHROPIC_API_KEY": ""
}
}
Do not commit real API keys. Use shell-level secrets, team secret management, or CI secrets instead.
Verify The Connection
Inside Claude Code, run:
/status
You want to see:
| Field | Expected value |
|---|---|
| Auth token | ANTHROPIC_AUTH_TOKEN |
| Anthropic base URL | https://openrouter.ai/api |
| API key conflict | ANTHROPIC_API_KEY blank |
| Activity visibility | Request appears in OpenRouter dashboard |
If /status still shows the default Anthropic route, your environment variables are not being read by the Claude Code process.
Model Selection Rules
Claude Code is not a normal chat UI. It relies on tool calls, file edits, long context, and agent loops. Model compatibility matters more than raw benchmark numbers.
| Model route type | Recommended? | Reason |
|---|---|---|
| Anthropic first-party through OpenRouter | Yes | Officially recommended by OpenRouter for compatibility |
| Other Claude-compatible routes | Test carefully | Tool and message semantics can differ |
| Free coding models | Experimental | Rate limits and tool-call behavior can break sessions |
openrouter/free style random routing |
Not for serious work | Random model selection is bad for agent consistency |
| Direct Anthropic Claude Code | Strong baseline | Native provider path, fewer translation risks |
| TokenMix.ai for app APIs | Strong for apps | Better fit for app-side multi-model API routing |
My rule: use OpenRouter with Claude Code only when the route is predictable. Agent tools punish random routing.
OpenRouter vs TokenMix.ai vs Direct Claude
| Path | Best for | Strength | Risk |
|---|---|---|---|
| Direct Claude Code | Individual developers and native Claude workflow | Maximum first-party compatibility | Anthropic-only billing and limits |
| Claude Code with OpenRouter | Teams wanting OpenRouter budgets and visibility | Central credits, provider failover, dashboard | Compatibility caveats |
| TokenMix.ai | App-side multi-model API access | One OpenAI-compatible gateway across providers | Not a Claude Code CLI replacement |
| LiteLLM / self-hosted proxy | Internal platform teams | Full control | Operations burden |
Use OpenRouter for Claude Code routing. Use TokenMix.ai's OpenAI-compatible API for product APIs, backend agents, and multi-model application traffic.
Cost And Limit Math
Cost calculation 1: free tier capacity
OpenRouter's pricing page lists 50 requests/day for free users, and its rate-limit docs list 20 RPM for free model variants.
| Claude Code usage pattern | Requests/day assumption | Free tier fit |
|---|---|---|
| One short test session | 20 | Possible |
| One normal coding session | 100-300 | Not enough on free account |
| Daily developer usage | 300-1,000 | Needs paid/credit path |
| Team usage | 2,000+ | Needs budgets and monitoring |
Claude Code can make many model calls during one task. Counting "prompts" underestimates real usage.
Cost calculation 2: model mismatch waste
| Scenario | Result |
|---|---|
| Cheap/free model fails after 10 minutes | Developer loses time |
| Tool loop breaks and retries | More requests, no useful work |
| Fallback model changes behavior | Inconsistent code edits |
| Premium Claude route completes task once | Higher token cost, lower labor waste |
For coding agents, the cheapest model is often not the cheapest workflow.
Cost calculation 3: team budget control
| Team size | Daily coding sessions | Why gateway controls matter |
|---|---|---|
| 1 developer | 1-3 | Local env is enough |
| 5 developers | 10-20 | Shared credits and caps help |
| 20 developers | 40-100 | Dashboard and budgets become important |
| 100 developers | 200+ | Enterprise policy and audit are required |
OpenRouter's team value is less about "free Claude Code" and more about central visibility.
Common Failure Modes
| Symptom | Likely cause | Fix |
|---|---|---|
| Claude Code still asks for login | Cached direct Anthropic session | Run /logout, restart shell, verify env |
| Requests go to Anthropic direct API | ANTHROPIC_API_KEY still set |
Set ANTHROPIC_API_KEY="" or unset it |
| 401 error | Bad OpenRouter token | Regenerate key and check ANTHROPIC_AUTH_TOKEN |
| Model not found | Trying unsupported model selection | Use Anthropic 1P route or recommended model |
| Endless retries | Tool-call or provider compatibility issue | Switch to Anthropic 1P route |
| 429 error | Free model or provider rate limit | Use paid route and backoff |
| No dashboard activity | Claude Code is not routed through OpenRouter | Check /status and shell env |
| Works in terminal but not extension | Extension process does not inherit shell env | Configure extension-specific environment |
When To Use Each Path
| Goal | Best path |
|---|---|
| Native Claude Code reliability | Direct Anthropic |
| Central budget and usage visibility for Claude Code | OpenRouter with Anthropic 1P |
| Free experimentation | OpenRouter free models, with low expectations |
| Product backend using many models | TokenMix.ai |
| Local/self-hosted coding model experiments | Ollama, SGLang, or local router |
| Team-wide internal gateway | LiteLLM, Kong, or Bifrost |
If your goal is to run coding agents cheaply, test end-to-end task completion, not just model response quality.
Final Recommendation
Claude Code with OpenRouter is worth using when you want OpenRouter's budgets, activity dashboard, and provider failover while staying close to Anthropic first-party compatibility.
Do not sell yourself the fantasy that any free model can replace Claude Code's native Claude route. Coding agents are tool-heavy systems. Compatibility beats novelty.
FAQ
Can Claude Code use OpenRouter?
Yes. OpenRouter has an official Claude Code guide, and Claude Code supports custom Anthropic base URL and auth token environment variables.
What base URL should I use for Claude Code with OpenRouter?
Use https://openrouter.ai/api. Do not use the normal OpenAI-compatible /api/v1 base URL for this Claude Code setup.
Why must ANTHROPIC_API_KEY be blank?
Claude Code can prefer ANTHROPIC_API_KEY for API authentication. OpenRouter's guide says to explicitly blank it so requests use ANTHROPIC_AUTH_TOKEN and the OpenRouter base URL.
Can I use free OpenRouter models with Claude Code?
You can experiment, but do not treat it as reliable production setup. OpenRouter says Claude Code with OpenRouter is only guaranteed with Anthropic first-party provider, and free models have strict limits.
How do I verify Claude Code is using OpenRouter?
Run /status inside Claude Code. It should show ANTHROPIC_AUTH_TOKEN and https://openrouter.ai/api, and requests should appear in the OpenRouter activity dashboard.
Is Claude Code with OpenRouter cheaper than direct Claude?
Sometimes, but only if the route completes tasks reliably. A cheaper model that breaks tool calls or retries can cost more in developer time.
Is TokenMix.ai a Claude Code replacement?
No. TokenMix.ai is a hosted multi-model API gateway for apps and backend agents. It is not a drop-in replacement for Claude Code's CLI runtime.
Should teams use OpenRouter for Claude Code?
Teams should consider it if they need centralized OpenRouter credits, activity visibility, and budget controls. They should still test compatibility on real repositories before rollout.
Related Articles
- OpenRouter API 2026: Pricing, Models, Limits, Alternatives
- OpenRouter Alternatives: Cheaper API Routing Options
- OpenRouter vs Direct API: When A Router Is Actually Cheaper
- Claude Code Pricing Guide 2026
- Claude Code Router Guide 2026
- Anthropic OpenAI-Compatible API 2026: Claude SDK Setup Guide
- LiteLLM Alternatives 2026: AI Gateway Options Compared
Sources
- OpenRouter Claude Code integration: https://openrouter.ai/docs/guides/guides/coding-agents/claude-code-integration
- Claude Code environment variables: https://code.claude.com/docs/en/env-vars
- Claude Code settings: https://docs.anthropic.com/en/docs/claude-code/settings
- OpenRouter pricing: https://openrouter.ai/pricing
- OpenRouter API limits: https://openrouter.ai/docs/api-reference/limits/
- OpenRouter quickstart: https://openrouter.ai/docs/quickstart