Repository navigation
fix(pricing): add cache_read_input_token_cost to 8 deepseek models - #28853
silencedoctor wants to merge 1 commit into
Conversation
|
Filed the follow-up deprecation discussion as #28854 (separate from this PR — only mentioning here so it's easy to find). |
Greptile SummaryThis PR fixes a silent billing bug where cache-hit tokens on 8 DeepSeek/OpenRouter-DeepSeek models were charged at $0 because the cost calculator reads
Confidence Score: 4/5Safe to merge — the pricing JSON edits are narrow additive changes that restore correct cache-read billing for the 8 affected models. The data changes are correct and well-tested. The only concern is the test fixture that sets a global env var and overwrites tests/test_litellm/test_deepseek_cache_read_pricing.py — the autouse fixture needs yield-based teardown to avoid state leakage.
|
| Filename | Overview |
|---|---|
| model_prices_and_context_window.json | Adds cache_read_input_token_cost to 8 DeepSeek/OpenRouter-DeepSeek model entries, mirroring their existing input_cost_per_token_cache_hit values. Values are consistent with how other DeepSeek models already declare this field. |
| litellm/model_prices_and_context_window_backup.json | Identical fix applied to the backup pricing file — same 8 models, same values, kept in sync with the primary JSON. |
| tests/test_litellm/test_deepseek_cache_read_pricing.py | New regression test covering all 8 affected models; fixture sets local model cost map but does not teardown, leaving global state modified for any co-located test files in the same pytest process. |
Reviews (1): Last reviewed commit: "fix(pricing): add cache_read_input_token..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Values look right to me — checked each of the 8 entries and the new One thing worth a note for future maintainers: these two fields now duplicate the same number per model ( Nice that both |
|
Thanks for the review! 🙏 |
a0a9775 to
ed47bde
Compare
8 deepseek and openrouter/deepseek models declared only the legacy `input_cost_per_token_cache_hit` field, but the cost calculator (`litellm.litellm_core_utils.llm_cost_calc.utils._get_token_base_cost`) only reads `cache_read_input_token_cost`. As a result, prompt-cache-hit tokens were billed at $0 instead of the cache-read rate for: - deepseek/deepseek-coder - deepseek/deepseek-r1 - deepseek/deepseek-v3.2 - openrouter/deepseek/deepseek-chat-v3.1 - openrouter/deepseek/deepseek-v3.2 - openrouter/deepseek/deepseek-v3.2-exp - openrouter/deepseek/deepseek-r1 - openrouter/deepseek/deepseek-r1-0528 This patch adds `cache_read_input_token_cost` with the same value as the existing legacy field to both pricing JSONs, matching the convention already used by `deepseek/deepseek-chat`, `deepseek/deepseek-reasoner`, `deepseek/deepseek-v3`, and others. Adds a regression test that parametrizes over the 8 models and an end-to-end check that a cache hit on `deepseek/deepseek-r1` is billed at the cache-read rate via `generic_cost_per_token`.
ed47bde to
6195f53
Compare
…7064 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Superseded by the rolling registry PR #34941, which re-verified and absorbed the |
Relevant issues
None.
Pre-Submission checklist
tests/test_litellm/(tests/test_litellm/test_deepseek_cache_read_pricing.py)make test-uniton the touched test file (uv run pytest tests/test_litellm/test_deepseek_cache_read_pricing.py— 9 passed)cache_read_input_token_costfield to 8 model entries plus one regression testType
🐛 Bug Fix
Changes
8 DeepSeek / OpenRouter-DeepSeek model entries declared only the legacy
input_cost_per_token_cache_hitfield but were missing the canonicalcache_read_input_token_costfield. The cost calculator only reads the latter, so prompt-cache-hit tokens on these models were silently billed at $0 instead of the cache-read rate.Root cause
litellm/litellm_core_utils/llm_cost_calc/utils.pyresolves the cache-read price viacache_read_input_token_costonly:```python
cache_read_cost_key = _get_service_tier_cost_key("cache_read_input_token_cost", service_tier)
cache_read_cost = cast(float, _get_cost_per_unit(model_info, cache_read_cost_key))
...
prompt_cost += float(prompt_tokens_details["cache_hit_tokens"]) * cache_read_cost
```
No code path consumes
input_cost_per_token_cache_hitfor cost calculation — it is only declared onModelInfoBase(litellm/types/utils.py) and listed in the field-name allowlist test. So for models that have only the legacy key,cache_read_costresolves toNone→0.0, and cache-hit tokens are billed at $0 (since they are also subtracted fromtext_tokensso they aren't billed at the full input rate either).Affected models
input_cost_per_token_cache_hit(was)cache_read_input_token_cost(now)deepseek/deepseek-coderdeepseek/deepseek-r1deepseek/deepseek-v3.2openrouter/deepseek/deepseek-chat-v3.1openrouter/deepseek/deepseek-v3.2openrouter/deepseek/deepseek-v3.2-expopenrouter/deepseek/deepseek-r1openrouter/deepseek/deepseek-r1-0528Each new
cache_read_input_token_costvalue is identical to the model's existinginput_cost_per_token_cache_hit. This matches the double-write convention already used by other DeepSeek entries that are billing correctly today (deepseek/deepseek-chat,deepseek/deepseek-reasoner,deepseek/deepseek-v3,novita/deepseek/deepseek-v3.2, etc.).The change is applied to both pricing JSONs:
model_prices_and_context_window.jsonlitellm/model_prices_and_context_window_backup.jsonTests
tests/test_litellm/test_deepseek_cache_read_pricing.py:cache_read_input_token_costequal toinput_cost_per_token_cache_hit.generic_cost_per_tokenbills cache-hit tokens at the cache-read rate fordeepseek/deepseek-r1.```
$ uv run pytest tests/test_litellm/test_deepseek_cache_read_pricing.py -v
...
9 passed in 0.56s
```
Existing
tests/test_litellm/test_cost_calculator.pycontinues to pass (53 passed).Follow-up
Out of scope for this PR, but worth a separate discussion:
input_cost_per_token_cache_hitappears to be a dead field — it is declared in the type definitions and JSON schema, but no calculator code path reads it. Today this is a footgun for community contributors and AI-assisted PRs that add new model entries by copying nearby DeepSeek configs and only carrying the legacy key over. I'll open a separate issue to discuss whether the field should be (a) wired to the calculator as a fallback with a deprecation warning, or (b) fully removed after a deprecation window. Happy to put up either patch once the maintainers signal which direction they prefer.