How to Make Claude Code Cheaper with DeepSeek V4
Claude Code is a fantastic coding assistant, but running it on Anthropic’s top Opus 4.7 model can get expensive fast. Some users have even seen unexpected charges when usage was routed through costly API calls. The good news: you can keep the same Claude Code experience while dramatically cutting your costs by swapping the backend model to DeepSeek V4.
Why Use DeepSeek V4 Behind Claude Code?
DeepSeek V4 is a new, high-performance large language model that launched around the same time as Claude Opus 4.7. On paper, Opus 4.7 still edges it out slightly on some benchmarks, but the gap is small—and in real-world coding tasks, DeepSeek V4 often performs shoulder-to-shoulder with Opus.
On an aggregate “intelligence index” across multiple evaluations, DeepSeek V4 scores around 50 while Opus 4.7 scores about 57. That might look like a big difference at first glance, but detailed benchmarks tell a different story. In tasks like GPK QA Diamond, DeepSeek V4 is comparable to Opus, and in instruction-following tests such as IFBench, DeepSeek V4 actually outperforms Opus 4.7.
If you’re interested in broader comparisons, you can also look at head-to-head coding and UI tests like GPT‑5.5 vs DeepSeek V4 Pro vs Claude Opus 4.7, which explore how these models behave in more realistic scenarios.
The Cost Difference: Up to 8× Cheaper
The real game changer is price. When you use Claude Code with Opus 4.7 directly, you’re typically paying:
• Around $5 per 1 million input tokens
• Around $25 per 1 million output tokens
By switching the backend to DeepSeek V4, the pricing drops roughly to:
• About $1.70 per 1 million input tokens
• About $3.40 per 1 million output tokens
That’s roughly 3–4× cheaper for inputs and 7–8× cheaper for outputs. At scale—especially for heavy coding sessions, long refactors, or multi-file generations—the savings add up quickly while you still get comparable quality.
How the Claude Code → DeepSeek V4 Routing Works
The trick is simple: keep using the Claude Code CLI and UI you’re used to, but change what’s behind it. Instead of hitting Anthropic’s Opus endpoint, you point the underlying API calls to DeepSeek’s V4 endpoint. From Claude Code’s perspective, it still thinks it’s talking to Anthropic; under the hood, you’ve swapped in DeepSeek.
The high-level idea is:
1. Get a DeepSeek API key.
2. Store that key securely on your local machine.
3. Override the default Anthropic/Claude Code API configuration so that any calls intended for Anthropic are actually sent to DeepSeek’s base URL, authenticated with your DeepSeek key.
4. Run Claude Code as usual, but with a small configuration tweak so its “Sonnet” endpoint is compatible with DeepSeek V4.
This way, you don’t have to change your workflow, prompts, or the Claude Code interface. You’re just swapping the engine under the hood.
Step-by-Step: Setting Up DeepSeek V4 for Claude Code
1. Create a DeepSeek Account and API Key
Step 1: Go to the DeepSeek platform at deepseek.com and create an account if you don’t already have one.
Step 2: Set up a billing method. You can simply add a one-time credit (for example, $10) instead of a monthly subscription. This credit will be used to pay for API calls.
Step 3: Navigate to the API keys section in your DeepSeek dashboard and generate a new API key. Copy this key—you’ll need it for the rest of the setup.
2. Store the API Key Securely on Your Machine
Next, you’ll want to save the DeepSeek API key locally in a safe way so that your terminal and Claude Code can access it without hardcoding it into scripts.
The general approach is:
• Create or use a configuration folder (the transcript used a folder name like mg, but you can choose any name).
• Store the key in an environment variable or a config file that your shell and Claude Code can read.
• Make sure only your user account can read that file (e.g., by setting proper file permissions).
Once this is done, any script or CLI command you run can pull the key from your local environment instead of embedding it directly in code.
3. Override Claude Code’s Default API Configuration
By default, Claude Code authenticates against Anthropic’s own services (directly or via platforms like Vertex AI). To route traffic to DeepSeek instead, you need to override those settings so that:
• The base URL points to DeepSeek’s API endpoint.
• The authorization header uses your DeepSeek API key.
• The model name Claude Code thinks it is calling (for example, a Sonnet endpoint) is mapped in a way that’s compatible with DeepSeek V4’s API.
The idea is to configure your environment so that when Claude Code tries to call Anthropic’s Sonnet model, the underlying client library actually sends the request to DeepSeek’s V4 endpoint using your DeepSeek credentials.
After this override, nothing changes in the Claude Code UI. You still type the same commands, but all the heavy lifting is done by DeepSeek V4.
4. Run Claude Code with the New Backend
Once your environment is configured, you can start Claude Code from the terminal with a command that:
• Ensures the configuration file or environment variables are loaded.
• Uses the same model name Claude Code expects (for compatibility), even though the actual backend is DeepSeek V4.
It may look like you’re calling a Sonnet model, but because you’ve changed the base URL and API key, the requests go to DeepSeek V4 instead. This compatibility layer is what lets you keep the Claude Code experience while benefiting from DeepSeek’s pricing.
Real-World Test: 3D Game Demo at a Fraction of the Cost
To test how well this setup works, the same complex coding task was run twice: once using Claude Code with Opus 4.7, and once using Claude Code routed through DeepSeek V4.
The prompt: build a single-file 3D first-person walking demo using Three.js in an index.html file, with specific requirements for the world, environment, player controls (WASD movement, mouse look, sprinting with Shift), and collision behavior.
Both setups successfully generated working demos:
• DeepSeek V4 backend: Produced a fully functional scene with WASD movement, mouse look, and sprinting. It followed the instructions closely and behaved as expected.
• Opus 4.7 backend: Also produced a high-quality demo with smooth navigation and collision handling around buildings.
In terms of quality, there was no major difference for this task. But the cost difference was dramatic. With a $10 DeepSeek credit, the balance dropped only from $9.96 to $9.90 after running the test—just a few cents for a substantial code generation task. The same kind of workload on Opus 4.7 would have cost several times more.
If you want to explore more ways to run DeepSeek V4 efficiently, including on your own hardware or via NVIDIA’s stack, you may find this guide useful: how to use DeepSeek V4 Pro & Flash for free with NVIDIA NIM.
When Does This Make Sense?
Routing Claude Code through DeepSeek V4 is especially attractive if:
• You’re a heavy Claude Code user and worried about monthly bills.
• You don’t strictly need the absolute top benchmark scores of Opus 4.7 for every task.
• You’re comfortable doing a bit of configuration work to change the backend API.
For many coding workflows—building demos, writing utilities, scaffolding apps, or exploring new ideas—DeepSeek V4’s performance is more than good enough, and the cost savings can be substantial.
In short: you can keep the Claude Code experience you like, swap in DeepSeek V4 behind the scenes, and cut your token costs by up to 8× with very similar real-world results.
Comments
No comments yet. Be the first to share your thoughts!