Blog

Cut Claude Code Bills 60% by Routing to DeepSeek and Groq

12 min readLeanroute Team

Cut Claude Code Bills 60% by Routing to DeepSeek and Groq

TL;DR

Claude Code is great. Claude Code on Sonnet 5 for every request is expensive. If you point Claude Code at a gateway that speaks OpenAI, Anthropic, and MCP, you can keep the same workflow and route the cheap work (refactors, small edits, log searches, unit tests) to DeepSeek V4 Flash or Groq gpt-oss, while keeping the hard work on Sonnet or Opus. On a real developer workload the blended bill drops between 60% and 92%.

The Setup

Claude Code is the default reason a lot of developers get an Anthropic bill in the first place. Long sessions, big context, tool use, MCP, sub-agents. Each of those things is a great feature. Each of those things is also a token multiplier.

Here is what a Sonnet 5 heavy user looks like today, in round numbers:

Model Input $/M Output $/M Blended 5:1 per 6M tokens
claude-opus-5 5.00 25.00 $50.00
claude-sonnet-5 2.00 10.00 $20.00
claude-haiku-4-5 1.00 5.00 $10.00

Blended 5:1 (5 input to 1 output) is a reasonable approximation for interactive coding traffic. If you push 6M tokens a day through Sonnet 5, that is about $600 a month. Opus is 2.5x that.

Now the same math for the models you never think about when you are inside Claude Code:

Model Input $/M Output $/M Blended 5:1 per 6M tokens
deepseek-v4-flash (off-peak) 0.22 0.66 $1.76
deepseek-v4-pro (off-peak) 0.66 1.98 $5.28
groq/openai/gpt-oss-120b 0.15 0.60 $1.35
groq/openai/gpt-oss-20b 0.075 0.30 $0.675
openai/gpt-5-nano 0.05 0.40 $0.65
openai/gpt-5-mini 0.25 2.00 $3.25

DeepSeek V4 Flash is roughly 11x cheaper than Sonnet 5 on blended cost. GPT-5 Nano is roughly 30x cheaper. Groq gpt-oss-120b sits in between at 15x cheaper, and it runs on LPUs, so it is fast enough that you barely feel the round trip.

The question is not whether these numbers are real. They are. The question is how you actually use these cheaper models from inside your Claude Code session without breaking your workflow.

That is what the rest of this post is about.

Why This Was Hard Before

Claude Code talks to Anthropic. That is by design. Anthropic ships the CLI, Anthropic owns the model, Anthropic owns the invoice.

If you want to route some of that traffic to a different model, you have historically had a few bad options:

  1. Manually switch tools. Pop out of Claude Code, run something in Cursor with a different provider, paste the answer back. Slow, breaks your context, kills your flow.
  2. Run a local proxy. Set up LiteLLM or a Docker container, override ANTHROPIC_BASE_URL, hope the response format matches. Works, but you are now maintaining infrastructure.
  3. Live with the bill. What most people do.

The reason none of these are great is that Claude Code was built around one wire format (Anthropic Messages) and one MCP surface. If you want to route to OpenAI, DeepSeek, Groq, xAI, or one of the Chinese labs, you need something in the middle that speaks both wire formats and forwards MCP correctly.

That thing is a gateway.

The Setup

Here is the whole stack once you have a gateway in the middle:

Claude Code
     │
     ▼
Leanroute Gateway
     ├──▶ Anthropic (claude-sonnet-5, opus-5, haiku-4-5, fable-5)
     ├──▶ OpenAI (gpt-5-nano, gpt-5-mini, gpt-5.6-luna, terra, sol)
     ├──▶ DeepSeek (v4-flash, v4-pro, v4-flash-vision-exp)
     ├──▶ Groq (openai/gpt-oss-20b, openai/gpt-oss-120b)
     ├──▶ Google, xAI, Qwen, GLM, Doubao, Kimi
     ├──▶ Sarvam, Krutrim
     └──▶ Meta (Muse Spark, Muse Code)

Same Claude Code binary. Same tools, same MCP servers, same prompt cache behaviour. What changes is the endpoint your local claude is pointed at, and which model string you type.

Setup is three steps.

Step 1. Get a Leanroute key.

Sign up at leanroute.dev, top up some credit, mint a runtime key from the dashboard. The key looks like gw_live_... and it works anywhere the OpenAI or Anthropic wire format works.

Step 2. Point Claude Code at Leanroute.

Set two environment variables in your shell profile:

export ANTHROPIC_BASE_URL="https://api.leanroute.dev/anthropic"
export ANTHROPIC_API_KEY="gw_live_your_key_here"

The anthropic subpath tells Leanroute to speak Anthropic Messages wire format. Everything Claude Code sends, including tool calls, images, MCP mcp_servers blocks, and system prompts, forwards through unmodified.

Step 3. Install the Leanroute MCP server.

npm install -g @leanroute/mcp-server

Then in your Claude Code MCP config (~/.config/claude/mcp.json or the equivalent for your OS), add:

{
  "mcpServers": {
    "leanroute": {
      "command": "npx",
      "args": ["-y", "@leanroute/mcp-server"],
      "env": {
        "LEANROUTE_ADMIN_KEY": "gw_admin_your_admin_key_here"
      }
    }
  }
}

The MCP server exposes tools like list_models, get_pricing, cheapest_for, get_usage, and route_call. Now Claude Code can ask itself, mid conversation, questions like "what is the cheapest flagship model I can use for this refactor" and route accordingly.

That is the whole install.

The Routes to Savings

Here is where the actual money comes from. Each of these is a real substitution you can make inside a Claude Code session today, along with the cost math and the rough quality tradeoff.

Route 1: Small edits go to Groq gpt-oss-20b

Everyone knows Sonnet is overkill for renaming a variable, but everyone uses it anyway because that is what Claude Code opens with. If you switch to Groq gpt-oss-20b for the small stuff, you drop from $20 per 6M tokens to $0.68. That is a 29x reduction on the blended cost, and Groq's LPU inference is fast enough (about 500 to 1000 tokens per second on the 20B) that you get the answer before you would have finished blinking.

How to do it: at the start of a small-edit request, ask Claude to route to groq/openai/gpt-oss-20b. The MCP server sees the intent and issues the call. You still see the diff, you still approve it, but the token bill goes to Groq.

Route 2: Refactors and multi-file changes go to DeepSeek V4 Flash

This is the big one. DeepSeek V4 Flash sits in the flagship tier on quality benchmarks but costs $0.22 in and $0.66 out per million tokens off-peak. Blended 5:1 that is $1.76 per 6M, versus Sonnet 5 at $20.

For a typical refactor pass (read 20 files, propose changes to 5, get user feedback, re-read, revise), you can burn through 300k to 500k tokens easily. On Sonnet 5 that is about $1 to $1.60. On DeepSeek V4 Flash it is $0.09 to $0.14.

Quality tradeoff is real but smaller than the price gap suggests. DeepSeek V4 Flash handles most refactoring, test generation, and boilerplate work without a noticeable step down. Where it slips is nuanced product judgement, ambiguous specs, and long-horizon multi-step reasoning. For those, you route to something better.

DeepSeek has one gotcha: peak-hour pricing doubles rates during 01:00 to 04:00 and 06:00 to 10:00 UTC on weekdays. Weekends are always off-peak. If you are in North America the peak windows are your evenings, which is inconvenient. Leanroute's arbitrage router knows the schedule and will move DeepSeek traffic to a same-tier alternative (Groq gpt-oss-120b, or gpt-5.6-luna) during peak windows if you have arbitrage enabled.

Route 3: The hard reasoning stays on Opus 5 or gets swapped to DeepSeek V4 Pro

For the requests that genuinely need premium reasoning (architecture design, tricky concurrency bugs, security review), Claude Opus 5 is $50 per 6M tokens blended. DeepSeek V4 Pro is $5.28. That is a 9.5x reduction and V4 Pro is a legitimate reasoning model, not a distilled downgrade.

If you trust the swap, keep arbitrage on and let the router pick V4 Pro. If you do not, keep Opus in your explicit route list and use it for the requests where you actually notice the difference.

A useful discipline: at the start of the session, tell Claude something like "for design questions or bugs that touch concurrency or auth, use Opus 5. For everything else prefer the cheapest available flagship." The MCP server exposes cheapest_for and route_call so Claude can make that decision per request.

Route 4: Log searches and simple tool calls go to GPT-5 Nano

If your Claude Code session is doing a lot of "grep this repo," "count occurrences of X," "list files matching pattern" style tool work, the LLM is essentially orchestrating shell commands. That does not require a $2/M input model. GPT-5 Nano at $0.05 in / $0.40 out is 40x cheaper on input than Sonnet 5, and easily good enough to decide which grep to run.

Route 5: Vision goes to Google Gemini 3.7 Flash, or DeepSeek V4 Flash Vision

When you paste a screenshot into Claude Code to say "why does this button look wrong," Anthropic's vision model is doing the work at Sonnet 5 rates. Google Gemini 3.7 Flash is $0.75 in / $3.75 out (intro pricing through December 31, 2026) and handles UI screenshots and diagram parsing well.

DeepSeek's new v4-flash-vision-exp is even cheaper but caps images at 384 input tokens per image, which is fine for small icons and bad for full page screenshots. Leanroute keeps it explicit rather than auto-routing there, so you have to ask for it by name. Worth it when you know your images are small.

The Practical Playbook

Here is what a real Claude Code session looks like once you have this set up.

Session start.

You launch claude in your project. First message you type includes:

For this session, use these routing rules:
- Small edits (renames, single-line fixes): groq/openai/gpt-oss-20b
- Refactors and file-scale changes: deepseek/deepseek-v4-flash
- Design questions or bugs I flag as hard: anthropic/claude-opus-5
- Everything else: cheapest available flagship, prefer non-peak DeepSeek

Confirm and I will start.

Claude reads the rules, calls the MCP server's list_models once to confirm they resolve, and acknowledges.

During the session.

Claude handles routing per turn. When it decides a request is a small edit, it calls route_call targeting the Groq SKU. When it hits a refactor, DeepSeek V4 Flash. You still see the diff, you still see the tool calls, you still approve edits. The only thing that changed is which provider answered.

At the end.

You run one MCP call to see the damage:

Use the leanroute MCP to show my usage for the last 24 hours, grouped by model.

You get back a table showing which SKUs answered what share of your traffic and how much each cost. On a real day of coding work, this typically looks like 70% to 80% of tokens on DeepSeek V4 Flash or Groq, 15% to 20% on Sonnet 5 or Opus 5, and the rest split across GPT-5 Nano and Gemini for tool calls and vision.

Real Numbers on a Real Workload

We ran this on an internal week of Claude Code work (13 developers, roughly 62 hours of active sessions, a mix of refactors, feature work, bug fixing, and code review).

Without routing, all traffic on Sonnet 5, with occasional Opus escalations:

  • Total tokens: 41.8M
  • Total cost: $487.90
  • Average per developer: $37.53

With routing, using the rules above:

  • Total tokens: 41.8M
  • Total cost: $158.20
  • Average per developer: $12.17

That is a 67.6% reduction. The split ended up at 68% DeepSeek V4 Flash, 8% Groq gpt-oss-120b, 12% Sonnet 5, 6% Opus 5, 4% GPT-5 Nano, 2% other. No one noticed a quality difference in day to day work. The two people who did notice were both doing algorithm design and stayed on Opus 5 on purpose.

Your mileage will vary based on how much of your work is genuinely reasoning-hard versus pattern-matching. If most of your Claude Code time is "read this file, propose a fix," you will see the higher end of the savings range. If most of it is "design me a distributed rate limiter for a multi region deploy," you will see the lower end.

Guardrails That Make This Safe

Cheaper models are only worth it if the failure modes are bounded. A few things the gateway does by default:

Failover. If your primary provider returns a 5xx or gets rate limited, the gateway retries on a same-tier alternative before returning an error to Claude Code. So a DeepSeek outage during peak hours does not become a stuck session, it becomes a transparent swap to Groq or Gemini.

Explicit routing. If you need to pin a request to a specific provider (benchmarking, compliance, tool-call behaviour that only one provider gets right), Claude Code can send x-gateway-routing: explicit on the request. Arbitrage and cheaper-model swap are both disabled for that call.

Per-key spend caps. You can mint runtime keys with daily and monthly USD caps in the dashboard. If your team is experimenting with routing, cap the key at $10 a day and you literally cannot lose more than $10 to a bad rule.

Admin keys are a separate class. The key you gave the MCP server (gw_admin_...) can list, mint, and revoke runtime keys and read your usage, but it cannot dispatch LLM traffic. And the key you gave Claude Code (gw_live_...) can dispatch traffic but cannot mint keys or touch billing. So even a compromised MCP server cannot burn your account, and a compromised runtime key cannot escalate privileges.

Vision guardrail. Vision-bearing requests never silently swap to a non-vision model. Some vision-capable models with restrictive image size caps (like DeepSeek's v4-flash-vision-exp with its 384 token per image ceiling) are excluded from the silent swap pool, so a "check this screenshot" request never gets truncated to a thumbnail.

What This Means for You

If you have been using Claude Code every day and paying for it every day, you are probably leaving somewhere between 40% and 90% of your bill on the table. The reason you have not clawed it back is that switching providers used to mean switching tools, breaking your context, and giving up MCP.

None of that is true anymore. Anthropic wire format works through any OpenAI-compatible gateway that translates. MCP servers forward cleanly. Failover keeps sessions alive. And the models that used to be "the cheap option that is not actually good enough" (DeepSeek V4 Flash, Groq gpt-oss-120b, GPT-5 Mini) crossed the quality threshold for most day to day coding work months ago.

The blended savings on our own team was 67%. Yours could be more, especially if you are heavier on refactor and test work and lighter on architecture design.

The install is 5 minutes. The rules go in your first message of the session. And the failure mode, if you pick the wrong split, is that some request is slightly worse than it would have been on Sonnet, and you tweak the rules for tomorrow.


Key Takeaways

  • Claude Code defaults to Sonnet. Sonnet is $20 per 6M tokens blended.
  • DeepSeek V4 Flash is $1.76 per 6M for the same tier of work.
  • Groq gpt-oss-120b is $1.35 per 6M and runs on LPUs, so it is fast.
  • Point Claude Code at a gateway (set two env vars). Install the Leanroute MCP. Give Claude routing rules at session start.
  • Failover, explicit routing, spend caps, and two key classes keep the worst case bounded.
  • Real internal test: 67.6% reduction on a real week of coding, no quality complaints.

About Leanroute

Leanroute is One Gateway for Models and Tools.

Route Claude Code requests across 13 AI providers through a single OpenAI-compatible and Anthropic-compatible endpoint. MCP forwarding is native. Failover, cost caps, and cheaper-model routing are on by default.

Get started at leanroute.dev

Claude CodeLLM RoutingAI GatewayCost OptimizationDeepSeekGroqMCP