[KongchangAI]
· 3 min read· 1,614 words

Running DeepSeek V4.1 Flash with Claude Code: 2 Cents Actual Cost, Counter Overstates by 50x

Running DeepSeek V4.1 Flash with Claude Code: 2 Cents Actual Cost, Counter Overstates by 50x

Claude Code on DeepSeek costs just 2 cents per real task, but the built-in counter overstates it ~50x at Opus rates.

The author switched Claude Code to DeepSeek V4.1 Flash using nine environment variables and ran a real coding task three times in an isolated config directory. All runs passed independent verification: 8 tests passed, output was character-identical across 32 AGENTS.md/CLAUDE.md files, and the new JSON mode worked. Actual cost was ~2 cents per run, but Claude Code, not recognizing the model, fell back to Opus rates and displayed $0.87–$1.28 — ~50x overstated. DeepSeek's own caching billed 94.6% of input tokens at a low price. Versus Claude, DeepSeek is 17–35x cheaper than Sonnet/Opus but roughly on par with Haiku 5.5, even pricier at peak.

Can Claude Code run on non-Claude models? Yes, but its built-in cost counter will mislead you. A developer swapped the default model for DeepSeek V4.1 Flash and ran the same real coding task three times. Each run cost about 2 cents in reality, while Claude Code displayed costs between $0.87 and $1.28 — because the tool priced an unfamiliar model at the rates of its own most expensive Opus model.

rss source: I ran Claude Code on DeepSeek V4.1 Flash. It cost 2 cents. Claude Code said 96.

Setup: Nine Environment Variables to Make the Switch

DeepSeekAd officially provides a guide for using its models in Claude Code. On top of that, the author added one line of configuration to point the Claude config directory to a separate empty folder, ensuring the test wouldn't touch his own Claude login session, CLAUDE.md files, or plugins. Every run started from the same blank environment.

The key environment variables include: ANTHROPIC_BASE_URL pointing to DeepSeek's Anthropic-compatible endpoint, ANTHROPIC_AUTH_TOKEN set to the DeepSeek API key, ANTHROPIC_MODEL and the various default model slots set to deepseek-flash[1m], the sub-agent model set to deepseek-flash, effort level set to max, and the auto-compact window set to 786432.

ANTHROPIC_BASE_URL is the entry address for the Anthropic API, which Claude Code points to the official endpoint by default. After changing it to a third-party compatible endpoint, all client requests (including model calls, cache markers, etc.) are sent to that address. ANTHROPIC_AUTH_TOKEN replaces the official OAuth or API key authentication, attached directly to the request headers as a Bearer Token. ANTHROPIC_MODEL and the various default model slots (such as the fast model and background model) specify the primary model and auxiliary models; since Claude Code has multiple model roles internally, changing only one slot may cause some subtasks to still use the default model. The [1m] in deepseek-flash[1m] usually indicates a 1-million-token context window variant, but Claude Code cannot recognize that suffix, which is one of the reasons the cost counter falls back as described below.

Task Design: Small but Realistic Code Refactor

The test task was to add a --json option to the agents check of the open-source tool bridle. The requirements were clear: when the flag is added, output a single JSON object; without the flag, the text report must remain character-for-character identical. Tests also needed to be added for both passing and failing files, and the full test suite had to be run.

This task was small in scale but realistic enough — the report was originally printed line by line to the screen, and the code had to be refactored while keeping the output unchanged. Each run started from a fresh clone of the repository and executed in claude -p unattended mode.

Verification: Look at Results, Not Summaries

All three runs claimed to pass. The author didn't take this at face value and verified it himself: node --test showed all 8 tests passing, including the original 6 and the 2 new ones.

The more critical verification was beyond the tests. The author ran both the new code and the original code against 32 AGENTS.md and CLAUDE.md files from a study of 25 well-known repositories, and the text output was completely identical across all 32 files in all three runs. The new flag also worked as expected — --json output a structured JSON object containing file, verdict, failure count, and detailed line information.

One unrequested behavior was worth noting: all three runs added entries to LOG.md. The repository's own CLAUDE.md requires every change to be logged. Even though the prompt said "don't change anything else," the model chose to follow the file rather than the prompt, and noted this in its summary. This shows that regardless of the model behind it, CLAUDE.md still has the highest priority.

Cost Data: The Gap Between 2 Cents and 96 Cents

The specific data for the three runs is as follows:

  • First run (effort max): 31 turns, 93 seconds, new input 44,065 / cache 632,192 / output 17,123 tokens, Claude Code displayed $0.96, DeepSeek actually charged $0.019
  • Second run (effort max): 42 turns, 123 seconds, new input 43,284 / cache 970,880 / output 22,957 tokens, Claude Code displayed $1.28, DeepSeek actually charged $0.023
  • Third run (effort high): 26 turns, 91 seconds, new input 38,074 / cache 605,312 / output 14,896 tokens, Claude Code displayed $0.87, DeepSeek actually charged $0.017

The account balance confirms this: after three runs it dropped from $0.49 to $0.46.

Why the Counter Is Off by 50x

During the runs, Claude Code printed a [claude-code:unrecognized_model] warning. It didn't recognize deepseek-flash[1m], couldn't retrieve DeepSeek's pricing, and so fell back to Claude Opus 5's rates: $5 per million input, $0.50 cached, $25 output. Using these rates, the token counts from the three runs compute exactly to $0.96, $1.28, and $0.87.

This means if you budget based on the cost Claude Code displays, you'll be off by about 50x — fortunately in the conservative direction.

Claude Code's cost counter relies on a hard-coded mapping from model names to pricing tables. When a model name isn't in the mapping, it doesn't query the provider for real-time pricing; instead it falls back to the built-in top-tier rates (Opus 5 here) and prints a [claude-code:unrecognized_model] warning. This design is sufficient for official models but completely fails for custom endpoints. More subtly, the counter calculates all input tokens at the "uncached input price," while in the actual bill a large number of tokens are charged at the cache price — the two unit prices differ by tens of times, further amplifying the error. Therefore, for any non-official model integration, ignore the cost displayed by the client and rely on the provider's backend billing.

Caching Mechanism: DeepSeek Has Its Own Approach

DeepSeek's documentation states that its Anthropic endpoint ignores Claude Code's cache_control markers, but it caches on its own. Across the three runs, 94.6% of input tokens were cache hits, billed at $0.003 per million rather than $0.15. This number matters because Claude Code resends the entire session context every turn. The author's previous personal data showed that resent context accounted for 97.5% of all tokens. The cache price is what truly determines the cost.

Claude Code's cache_control markers are part of Anthropic's prompt caching, used to mark reusable context prefixes that are billed at a lower price when hit. DeepSeek's Anthropic-compatible endpoint doesn't parse these markers; instead it automatically identifies and caches repeated prefixes according to its own policy, with hits priced at about $0.003 per million — far below the miss price. Since Claude Code resends the full session context every turn, automatic caching has a much greater impact on cost than the model's own input unit price; this also means that when evaluating low-cost models, the cache hit rate determines the final bill more than the list price.

Price Comparison with Claude Models

Calculating the average token mix of the three runs at each model's list price:

  • DeepSeek V4.1 Flash off-peak: about $0.020 per run
  • Claude Haiku 5.5: about $0.021
  • DeepSeek V4.1 Flash peak: about $0.039
  • Claude Sonnet 5.5: about $0.34
  • Claude Opus 5.5: about $0.68
  • Claude Fable 5.1: about $1.52

For Sonnet and Opus, DeepSeek is about 17 to 35 times cheaper. But against Haiku 5.5 the cost is roughly on par, and during peak hours Haiku is actually cheaper. Peak hours are weekdays UTC 01:00–04:00 and 06:00–10:00, which in India covers most of the working morning.

A caveat: this table only prices DeepSeek's tokens at Claude's rates; Claude models may consume different numbers of turns and tokens on the actual task. The author did not run this task with Haiku 5.5, so whether it passes the tests remains unverified.

Practical Takeaways

Based on this test, a few lessons are worth remembering:

  • Ignore the cost counter for non-Claude models. Go by your provider's bill. Claude Code estimates unfamiliar models at Opus rates, and the error is huge.
  • "Max" effort level isn't cheap. The two max runs used 31 and 42 turns respectively, and the high run used 26 turns. Three runs are just a sample, not a trend.
  • Check the work results, not the model's summary. All three summaries were accurate this time, but the only way the author could confirm that was by running the verification himself.
  • Switching models doesn't change the priority of project rules. The constraints in CLAUDE.md still apply, even when they conflict with the prompt.

The core takeaway from this test isn't "DeepSeek is cheaper than Claude" — it's that low-cost models have entered the range of a few cents per task. The real question becomes: which model passes your checks, not just which is cheaper.

One-line Summary

Claude Code with DeepSeek costs just 2 cents for a real task, but the built-in counter overstates it by about 50x at Opus rates.

Paragraph Summary

The author used nine environment variables to switch Claude Code to DeepSeek V4.1 Flash and ran a real coding task three times in an isolated config directory. All three runs passed independent verification: all 8 tests passed, text output was character-for-character identical across 32 AGENTS.md/CLAUDE.md files, and the new mode output JSON as expected. The actual cost was about 2 cents per run, but Claude Code, unable to recognize the model name, fell back to Opus rates and displayed $0.87 to $1.28 — about 50x overstated. DeepSeek's own caching billed 94.6% of input tokens at a low price. Compared with Claude models, DeepSeek is 17 to 35 times cheaper than Sonnet/Opus, but roughly on par with Haiku 5.5 and even more expensive during peak hours.

#Claude Code#DeepSeek V4.1 Flash#cost counter#prompt caching#LLM pricing
Share:

Related articles