Claude Code + OpenRouter or Unified API: Cut Costs 60% (2026)

By · · 10 min read

Claude Code + OpenRouter or Unified API: Cut Costs 60% (2026)

Last updated: October 20, 2026 · Prices checked against Anthropic's official pricing page, OpenRouter's pricing page and Oxyy's live model pages on this date.

Disclosure: This guide is published by the Oxyy.ai team. Every competitor number is taken from the provider's own public page.

Quick answer: To run Claude Code through OpenRouter or any unified API, set ANTHROPIC_BASE_URL to the gateway's address and put the gateway key in ANTHROPIC_AUTH_TOKEN. OpenRouter charges Anthropic's list price plus a 5.5% credit fee. Oxyy.ai currently charges 40% of list price, so the same Claude Code session costs about 60% less.

Model (per 1M tokens)Anthropic official (input / output)OpenRouter (incl. 5.5% fee)Oxyy.ai (60% off)Context
Claude Opus 5.5$4.00 / $20.00$4.22 / $21.10$1.60 / $8.001M
Claude Sonnet 5.5$2.00 / $10.00$2.11 / $10.55$0.80 / $4.001M
Claude Opus 5$5.00 / $25.00$5.28 / $26.38$2.00 / $10.001M
Claude Sonnet 5$2.00 / $10.00$2.11 / $10.55$0.80 / $4.001M
Claude Haiku 5.5 (prompts ≤100K)$0.10 / $0.50$0.11 / $0.53$0.04 / $0.201M

Official prices: Anthropic pricing page. OpenRouter passes through provider list prices and charges a 5.5% fee when you buy credits on its Standard plan (8% on Business); the column applies 5.5% for comparison. Oxyy prices: Oxyy model pages (current 60% "Launch Promo"). Checked October 20, 2026.

Key Takeaways

  • Claude Code works with any Anthropic-format gateway. Two variables do the job: ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN.
  • OpenRouter isn't cheaper than going direct. It bills Anthropic's list price and adds a 5.5% fee on credit purchases (8% on its Business plan).
  • Oxyy is cheaper than direct. Claude Sonnet 5.5 costs $0.80 / $4.00 per 1M tokens instead of $2.00 / $10.00, and Opus 5.5 costs $1.60 / $8.00 instead of $4.00 / $20.00.
  • Claude traffic on Oxyy is served by Anthropic upstream, so you get the same models, not look-alikes.
  • Claude Code only supports Claude models through a gateway. Anthropic doesn't support routing it to non-Claude models.
  • Setup takes about two minutes, and Oxyy gives you a free starting balance to test with.

Why Claude Code Gets Expensive Fast

Claude Code is an agent, not a chat box. On every step it re-sends your instructions, the conversation so far, tool output and file contents. That makes the traffic input-heavy: on Oxyy's public activity chart for Claude Sonnet 5, about 91% of tokens were input (363.5M prompt tokens vs 34M completion and reasoning tokens in the window we checked).

That's why the per-token price matters more for Claude Code than for almost any other app. A small difference in the input rate gets multiplied by hundreds of millions of tokens a month.

You have three ways to pay for Claude Code:

  1. A Claude subscription (Pro or Max): fixed monthly price, but usage limits apply.
  2. Anthropic API key: pay per token at list price, with tier-based rate limits and monthly spend caps.
  3. An LLM gateway (OpenRouter, Oxyy and others): pay per token through one key. The price depends on the gateway.

This guide covers option 3: first the OpenRouter setup most people search for, then a cheaper alternative.

What Is an LLM Gateway for Claude Code?

LLM Gateway for Claude Code

An LLM gateway is a proxy between Claude Code and the model provider. Claude Code sends its requests to the gateway's URL instead of Anthropic's, and authenticates with the gateway's key. Anthropic's own docs say any gateway that exposes a supported API format works. Claude Code needs the Anthropic Messages format (/v1/messages), which both OpenRouter and Oxyy provide.

Option 1: How to Use Claude Code With OpenRouter

This is OpenRouter's documented setup, from its Claude Code integration guide:

# ~/.zshrc or ~/.bashrc
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=""   # must be explicitly empty

What to know before you choose OpenRouter:

  • Price: OpenRouter bills each provider's list price with no markup on tokens, but charges a 5.5% fee when you buy credits on the Standard plan and 8% on Business. So $1,000 of Claude usage costs about $1,055.
  • Compatibility: OpenRouter says Claude Code is "only guaranteed to work with the Anthropic first-party provider" and recommends setting Anthropic as top-priority provider.
  • Empty ANTHROPIC_API_KEY: it stops Claude Code from falling back to your Anthropic login.

Option 2: How to Use Claude Code With Oxyy (60% Cheaper)

Claude Code With Oxyy

Oxyy.ai is a unified AI API gateway with a native Anthropic Messages endpoint. Its Anthropic endpoint lives at https://api.oxyy.ai (no /v1: Claude Code adds /v1/messages itself), and it accepts your key as either a Bearer token or x-api-key.

Step 1: Get an Oxyy API Key

  1. Sign up at oxyy.ai/register with email, Google or GitHub. A free starting balance is applied automatically and no card is needed.
  2. Create an API key on the API keys page.

Step 2: Set the Environment Variables

macOS / Linux (Bash or Zsh):

export ANTHROPIC_BASE_URL="https://api.oxyy.ai"
export ANTHROPIC_AUTH_TOKEN="$OXYY_API_KEY"
export ANTHROPIC_API_KEY=""

# Optional: pin the models Claude Code uses
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-5-5"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-5-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-5-5"

Windows (PowerShell):

$env:ANTHROPIC_BASE_URL = "https://api.oxyy.ai"
$env:ANTHROPIC_AUTH_TOKEN = $env:OXYY_API_KEY
$env:ANTHROPIC_API_KEY = ""

Shell exports only last for one terminal session. To apply the gateway everywhere Claude Code runs, including background agents, add an env block to ~/.claude/settings.json (on Windows: %USERPROFILE%\.claude\settings.json):

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.oxyy.ai",
    "ANTHROPIC_AUTH_TOKEN": "sk-oxyy-your-key",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5"
  }
}

Security note: never put your key in a project's .claude/settings.json, because that file is committed to your repo. Use the user-level file or .claude/settings.local.json (and keep it in .gitignore).

Step 4: Verify the Connection

curl -sS -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "claude-sonnet-5-5", "max_tokens": 1, "messages": [{"role": "user", "content": "."}]}'

A JSON reply that starts with {"id":"msg_ means it works. Then start claude, run /status, and check that the Anthropic base URL line shows https://api.oxyy.ai.

Using the VS Code Extension?

Put the same variables in claudeCode.environmentVariables in your VS Code user settings (JSON). Anthropic notes the extension checks credentials from that setting before launching.

Claude Code Cost: Direct vs OpenRouter vs Oxyy

Here's an illustrative heavy month for one developer: 150M input tokens and 6M output tokens.

Scenario A: No Prompt Caching

RouteClaude Sonnet 5.5Claude Opus 5.5
Anthropic API (list price)$360.00$720.00
OpenRouter (+5.5% fee)$379.80$759.60
Oxyy (60% off)$144.00$288.00
Saved per year vs direct$2,592$5,184

Scenario B: 80% of Input Served From Cache

Claude Code reuses a lot of context, so real sessions often hit the prompt cache. With 30M uncached input, 120M cached input and 6M output (cache writes left out for simplicity):

RouteClaude Sonnet 5.5Claude Opus 5.5
Anthropic API (list price)$132.00$264.00
Oxyy$57.60$105.60
Saving56%60%

Why 56% on Sonnet 5.5? Anthropic prices Sonnet 5.5 cache hits at $0.10 per 1M, and Oxyy charges $0.08 there, so cached reads save less than the other rates. Input, output and Opus 5.5 cache reads are all 60% off.

Oxyy vs OpenRouter for Claude Code

FeatureOpenRouterOxyy.ai
Claude token priceAnthropic list price40% of list price (current promo)
Platform fee5.5% on credit purchases (Standard), 8% (Business)None
Anthropic Messages endpointYes (https://openrouter.ai/api)Yes (https://api.oxyy.ai)
Who serves ClaudeConfigurable; Anthropic 1P recommended for Claude CodeAnthropic upstream
Prompt cachingYesYes, cache_control preserved per block
count_tokens endpointCheck provider docsYes, free and doesn't use your rate limit
Model catalog500+ models170+ models
Free startFree models (rate-limited)Free starting balance, no card
Credits expire?See OpenRouter termsNever

Bottom line: OpenRouter is a good choice if you want the widest catalog. If your goal is a cheaper Claude Code bill, Oxyy is the stronger pick, because it's the only option here that charges less than Anthropic's own price.

Oxyy by the Numbers (Live, October 2026)

  • 178 models from 16 vendors through 14 upstream providers
  • 5.8 million requests and about 50 billion tokens processed in the last 30 days (Oxyy About page)
  • OpenAI, Anthropic and Google SDKs work unchanged against the same key
  • Live latency, throughput and 30-day success rate on every model page, so you can check performance before you switch
  • Prompts and completions aren't used to train anything

Tips to Cut Claude Code Costs Even Further

  1. Pin a cheaper default model. Use Sonnet 5.5 for most work and switch to Opus only for hard problems.
  2. Set ANTHROPIC_DEFAULT_HAIKU_MODEL. Claude Code uses the Haiku slot for background tasks like session titles. Haiku 5.5 costs $0.04 / $0.20 per 1M tokens on Oxyy for prompts up to 100K tokens (longer prompts cost more).
  3. Keep context lean. Clear or compact long sessions, since every step re-sends the conversation.
  4. Let caching work. Stable instructions in CLAUDE.md are cached and billed at the cache-read rate.
  5. Track spend in one place. Oxyy's activity log itemizes every request at the real charged rate.

Troubleshooting

SymptomFix
401 invalid tokenCheck the key. If you put it in ANTHROPIC_API_KEY, move it to ANTHROPIC_AUTH_TOKEN (or the other way round).
/status shows no base URLThe variable didn't reach the session. Start claude from the same terminal, or use settings.json.
Claude Code still uses your subscriptionSetting only ANTHROPIC_BASE_URL isn't enough. You also need a gateway credential variable. Run /logout once if needed.
Unknown model errorUse an Oxyy model ID, such as claude-sonnet-5-5 or claude-opus-5. The URL and key are fine if the error names the model.
429 rate limitWait for the Retry-After seconds. Higher Oxyy rate limits unlock automatically as you top up.
Failed calls on a locked-down networkSet CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 to turn off telemetry and version checks outside the gateway.

Final Verdict

OpenRouter is the setup most tutorials show, and it works. But it doesn't lower your bill: you pay Anthropic's price plus a 5.5% fee. If you want Claude Code for less than Anthropic's own price, point ANTHROPIC_BASE_URL at Oxyy. You keep the same Claude models served by Anthropic, the same workflow, and pay 40% of list price during the current promotion.

Get your free Oxyy API key and run Claude Code for 60% less →

Related: Claude API pricing on Oxyy · Claude Opus 5 · Claude Sonnet 5 · Oxyy Anthropic SDK docs

Frequently Asked Questions

Can I use Claude Code with OpenRouter?

Yes. Set ANTHROPIC_BASE_URL to https://openrouter.ai/api, put your OpenRouter key in ANTHROPIC_AUTH_TOKEN and set ANTHROPIC_API_KEY to an empty string. OpenRouter says Claude Code is only guaranteed to work with the Anthropic first-party provider.

Is OpenRouter cheaper than the Anthropic API for Claude Code?

No. OpenRouter bills Claude at Anthropic's list price and charges a 5.5% fee when you buy credits on its Standard plan (8% on Business), so it costs slightly more than going direct.

What is the cheapest way to run Claude Code with an API key?

Using a gateway that charges below list price. Oxyy.ai currently charges 40% of Anthropic's list price, so Claude Sonnet 5.5 costs $0.80 input and $4.00 output per 1M tokens instead of $2.00 and $10.00.

How do I set a custom API endpoint in Claude Code?

Set the ANTHROPIC_BASE_URL environment variable to the gateway's address and put the gateway credential in ANTHROPIC_AUTH_TOKEN (for bearer tokens) or ANTHROPIC_API_KEY (for x-api-key). You can set them in your shell or in the env block of ~/.claude/settings.json.

What is the Oxyy base URL for Claude Code?

Use https://api.oxyy.ai without /v1. Claude Code adds /v1/messages itself. For OpenAI-format tools, Oxyy's base URL is https://api.oxyy.ai/v1.

Does Claude Code work with non-Claude models through a gateway?

Anthropic doesn't support routing Claude Code to non-Claude models through any gateway. Use Claude models such as Opus 5.5, Sonnet 5.5 or Haiku 5.5 for Claude Code.

Are the Claude models on Oxyy the real Anthropic models?

Yes. Oxyy's Claude model pages list Anthropic as the upstream provider, so requests are served by Anthropic. Oxyy is an independent gateway and isn't affiliated with Anthropic.

Does Claude Code still use my Claude subscription if I set a gateway?

No, as long as you set a gateway credential variable. Requests then carry the gateway key and are billed per token by the gateway. Setting only ANTHROPIC_BASE_URL keeps your saved subscription login active.

How much does Claude Code cost per month on the API?

It depends on usage. A heavy month of 150M input and 6M output tokens on Claude Sonnet 5.5 costs $360 at Anthropic list price, about $380 on OpenRouter and $144 on Oxyy before caching.

Is the Oxyy discount permanent?

The 60% discount is labeled a "Launch Promo" on Oxyy's model pages. Each page shows both the standard price and the charged price, so you always see what you'll pay.

Does prompt caching reduce Claude Code costs?

Yes. Cached input is billed at a fraction of the normal input rate. On Oxyy, cached input costs $0.08 per 1M tokens on Claude Sonnet 5.5 and Opus 5.5.

Can I use Claude Code with Oxyy in VS Code?

Yes. Add ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN to claudeCode.environmentVariables in your VS Code user settings JSON.

Models mentioned

Pay-as-you-go prices, live from the Oxyy catalog.

Browse all modelsSee pricing