Repository navigation
Conversation
limdeng
force-pushed
the
litellm_dashscope_qwen_cache_pricing
branch
from
September 7, 2026 09:03
69b1718 to
07dc234
Compare
…n_cache_pricing # Conflicts: # litellm/litellm_core_utils/llm_cost_calc/utils.py
limdeng
had a problem deploying
to
e2e-changed
September 14, 2026 03:30 — with
GitHub Actions
Failure
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 BerriAI#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