Cheap Backend, Expensive Habit: Running Claude Code Against DeepSeek on One Key
Claude Code can be pointed at cheaper backends like DeepSeek to cut per-token costs, but the savings often erode through retries, longer outputs, and hidden overhead. This article explains how to route Claude Code to DeepSeek via an OpenAI-compatible endpoint using one API key, compares the true cost drivers of a session, and offers practical tips to keep the cheaper backend from becoming an expensive habit.
Why run Claude Code on a non-default backend?
Claude Code is a terminal-based coding agent that sends prompts to a language model and acts on the responses. By default, it uses Anthropic's API. However, because it speaks an OpenAI-compatible protocol when configured, you can point it at other providers—including DeepSeek—to take advantage of lower per-token prices.
The appeal is straightforward: DeepSeek's published token prices are lower than Claude's. But a Claude Code session is not a single API call; it's a chain of calls with tool use, retries, and context growth. The effective cost per task can diverge significantly from the headline per-token rate.
How to route Claude Code to DeepSeek with one key
You can use an API aggregator that supports multiple models behind a single key, or configure Claude Code directly with DeepSeek's OpenAI-compatible endpoint. The general steps are:
- Get an API key from your chosen provider or aggregator. If you use an aggregator, you can top up with USDC on Base and skip KYC.
- Set environment variables so Claude Code (or its underlying client) uses the custom endpoint. Typically this means setting
OPENAIAPIBASEto the provider's OpenAI-compatible URL andOPENAIAPIKEYto your key. - Select the model by name in your Claude Code configuration or via a model flag.
- Test with a small prompt to confirm connectivity and response format.
If you're using an aggregator, the same key can also access Claude, GPT, and other models, which makes it easy to switch back if DeepSeek underperforms on a particular task.
The cost anatomy of a Claude Code session
A Claude Code session involves more than the initial prompt. Key cost drivers include:
- Input tokens: Each turn resends the conversation history, which grows with every tool call and response. Longer sessions mean more input tokens per request.
- Output tokens: Code generation, explanations, and tool-call arguments all count as output. DeepSeek may produce longer outputs than Claude for the same task, especially if it's more verbose or requires more clarification.
- Retries and errors: If DeepSeek returns malformed tool calls, times out, or produces code that fails tests, Claude Code may retry. Each retry adds tokens.
- Tool-call overhead: Agents often make many small calls. A model that is cheaper per token but less precise can increase the number of calls.
Where the cheaper per-token price gets eaten
The per-token price is only one factor. In practice, the effective cost per completed task can be higher than expected because:
- Longer outputs: If DeepSeek generates more verbose responses, you pay for those extra output tokens even at a lower rate.
- More retries: A model that struggles with tool-call formatting or code correctness may trigger retries, each of which consumes tokens.
- Context bloat: If the model requires more back-and-forth to understand the task, the conversation history grows, increasing input tokens on every subsequent call.
- Failed sessions: A session that fails and must be restarted wastes all tokens spent up to that point.
These factors can narrow or even erase the price advantage, especially for complex coding tasks.
Practical tips to keep costs predictable
- Benchmark on your own tasks: Run a few representative prompts on both backends and compare total tokens consumed, not just per-token price.
- Constrain output length: Use system prompts or parameters to limit verbosity where possible.
- Monitor retries: If you see frequent retries, consider whether the model is a good fit for the task. Sometimes paying more per token for a model that completes the task in fewer calls is cheaper overall.
- Use the right model for the job: Simple edits may work well on DeepSeek; complex refactors might be better on a more capable model. An aggregator with one key makes switching easy.
- Keep sessions focused: Break large tasks into smaller sessions to avoid context bloat.
Understanding the pricing model
On this aggregator, you pay the official price multiplied by 1.3 for any model you use. If you contribute keys, you're credited the official price multiplied by 1.1 (or 1.2 for premium models) in USDC. This means the relative cost difference between DeepSeek and Claude is preserved, but the absolute cost is higher than the raw official price. Factor this multiplier into your comparisons.
When to choose DeepSeek vs. Claude
DeepSeek can be a cost-effective choice for tasks where its output quality is sufficient and its tool-calling is reliable. Claude may be more economical for complex tasks where fewer retries and more precise outputs reduce total token consumption. The key is to measure effective cost per task, not just per token.
Conclusion
Running Claude Code against DeepSeek on one key is a viable way to reduce per-token costs, but the savings depend on how well the model handles your workload. By understanding the full cost anatomy and monitoring retries and output length, you can avoid turning a cheap backend into an expensive habit.