Repository navigation
Conversation
Greptile SummaryThis PR distinguishes explicit and implicit Qwen cache-read pricing while preserving existing fallback behavior
Confidence Score: 5/5The PR appears safe to merge because no new actionable issue or outstanding previous finding remains The immutable refactor preserves cache-rate selection, including service-tier and zero-valued rates, while all previous findings are resolved in the current code
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/llm_cost_calc/utils.py | Resolves implicit cache-read rates through immutable values and applies them consistently to totals, breakdowns, and savings |
| litellm/llms/dashscope/cost_calculator.py | Classifies Qwen cache mode and selects matching flat, tiered, and off-peak pricing |
| litellm/types/utils.py | Preserves cache-type metadata and exposes implicit cache pricing through shared typed models |
| litellm/utils.py | Propagates implicit cache-read pricing through model registration and model information lookup |
| litellm/cost_calculator.py | Defers Fireworks and Perplexity calculator imports to their matching dispatch branches |
| tests/test_litellm/llms/dashscope/test_dashscope_cost_calculator.py | Covers explicit and implicit pricing across generic, DashScope, tiered, service-tier, off-peak, breakdown, and savings paths |
Reviews (10): Last reviewed commit: "refactor(cost): keep cache rate immutabl..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai Please review the latest commit. Cache-mode classification now stays in the DashScope adapter and uses provider response metadata only |
|
@greptileai Please review the latest commit. Shared cost utilities now use a provider-neutral registry, while DashScope owns its cache-rate resolver |
…n_cache_pricing # Conflicts: # litellm/litellm_core_utils/llm_cost_calc/utils.py
|
@greptileai Please review current commit. DashScope now owns cache-mode pricing behind the provider-neutral configuration boundary, with current main and E2E proof. |
|
bugbot run |
|
@greptileai Please review current commit. The test now exercises a real provider without chat configuration and no longer monkeypatches class methods. |
|
bugbot run |
|
@greptileai Please review current commit. Tiered implicit rates now honor model-level configuration, savings use the same provider-resolved rate, and all checks pass. |
|
bugbot run |
|
@greptileai Please review current commit e68b357. The CodeQL import cycle is removed: DashScope now returns only a provider-specific pricing key, while shared code resolves that key without importing provider cost modules. Focused tests, 100% patch coverage, make check, and current-tip real E2E pass. |
|
bugbot run |
|
@greptileai Please review current commit b9db42a. Provider configuration hooks and dynamic provider imports have been removed. Shared pricing now activates the optional implicit rate only from normalized cache metadata plus model pricing, while DashScope total-cost logic remains provider-local. Focused tests, 100% patch coverage, make check, and current-tip real E2E pass. |
|
bugbot run |
|
@greptileai Please review commit bfca7aa. It aligns generic cache totals with breakdown rates and removes the CodeQL import cycles. |
|
bugbot run Please review commit bfca7aa, especially generic cache total consistency and the lazy Fireworks and Perplexity imports. |
|
@greptileai Please re-review commit 2cafaa3 after the immutable cache-rate refactor; focused tests, patch coverage, and make check pass locally. |
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 2cafaa3. Configure here.
|
@krrishd @ishaan-jaff Could you please prioritize reviewing this PR? Explicit and implicit Context Cache are official, documented features of Alibaba Cloud's DashScope API, with different billing rates. Correctly distinguishing and pricing them is essential for accurate DashScope cost tracking in LiteLLM. Official documentation: https://www.alibabacloud.com/help/en/model-studio/context-cache This PR addresses that gap while preserving existing pricing when no implicit-cache rate is configured. The latest commit, I also emailed Krrish about this PR roughly a day ago and haven't received a reply yet. I'd appreciate a review soon, or help routing it to the appropriate maintainer. Please let me know if anything else is needed before merging. Thanks! |
TLDR
Feature this adds:
How it works:
cache_typein normalized usagecache_read_input_token_costfor explicit reads andcache_creation_input_token_costfor cache creationimplicit_cache_read_input_token_costfor implicit readsExplicit (
cache_control-based) and implicit (automatic prefix) caching are documented DashScope capabilities. This PR adds pricing support for distinguishing their cache reads in LiteLLM.Provider documentation: https://www.alibabacloud.com/help/en/model-studio/context-cache
User Flow
Before: Qwen cache reads share one configured rate
cache_read_input_token_costat$0.10/Mtokens; separate implicit-cache read pricing is not supportedPOST http://localhost:4000/v1/chat/completionstwice with the same long Qwen prompt and nocache_control200 OKwithcached_tokensand nocache_type$0.10/MrateAfter: the admin can opt into separate implicit-cache read pricing
cache_read_input_token_costat$0.10/Mand sets the newimplicit_cache_read_input_token_costto$0.20/M$0.20/M; an explicit hit withcache_type: "ephemeral"continues to use$0.10/MRelevant issues
Closes #40090
Related transport and pricing work:
Affected release
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
608 passed; spend tracking reports225 passed; savings reports97 passed; types reports39 passed2cafaa308f5/5for2cafaa308f)Local verification:
100%across 88 changed executable Python linesmake checkgates passed on2cafaa308f, including circular-import, type-discipline, test-quality, frontend, andschema.d.tssync checksmlflow 3.15.0/PYSEC-2026-3865from the unchangeduv.lock; OSV reports no fixed release20.17µsto14.47µsand Anthropic from21.50µsto18.14µsnpm run gen:apiproduced no generated diffDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Feature Verification
This no-mock proof used real
dashscope/qwen3.8-maxcalls. A local relay forwarded request bodies unchanged to the development gateway and removed only upstream cost headers, forcing each checkout to calculate its own cost from the unmodified provider usage.Both checkouts used the same model configuration below. The new
implicit_cache_read_input_token_costfield enables separate implicit-cache pricing in the PR checkout; the baseline uses the existing shared cache-read rate. These values are illustrative custom rates, not a statement of the provider's current model prices:The implicit request contained a stable prompt longer than 1,024 tokens and no
cache_control. The explicit request used the same text withcache_control: {"type": "ephemeral"}. Eachcurlloop sent the request twice and captured the second response.Before (30f33a9)
Implicit automatic cache hit
Send the implicit request twice to the baseline
maincheckout (30f33a949b):Observe 50,176 cached tokens with no
cache_type, priced using the existing shared cache-read rate:50176 * 0.0000001 = 0.0050176Explicit ephemeral cache hit
Send the explicit request twice to the same
maincheckout:Observe 50,654 cached tokens with
cache_type: "ephemeral", priced using the existing explicit cache-read rate:50654 * 0.0000001 = 0.0050654After (2cafaa3)
Implicit automatic cache hit
Send the identical implicit request twice to the current PR checkout:
Observe the same 50,176 cached tokens, now priced using the separately configured implicit-cache read rate:
50176 * 0.0000002 = 0.0100352Explicit ephemeral cache hit
Send the identical explicit request twice to the same PR checkout:
Observe the same 50,654 explicit cached tokens still using the existing explicit rate:
50654 * 0.0000001 = 0.0050654Type
🆕 New Feature
Caveats (if any)
Low
Final Attestation