Repository navigation
fix(cost_calc): default fireworks cached input to the documented 50% discount when the map has no cache-read rate - #41917
Conversation
…discount when the map has no cache-read rate Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
bugbot run |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
…llm/llms Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
|
Addressed the Greptile boundary finding: the Fireworks cache-read derivation now lives under litellm/llms/fireworks_ai, shared utils only dispatch by provider |
…-through Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
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 05cefb1. Configure here.
TLDR
Problem this solves:
How it solves it:
FIREWORKS_AI_DEFAULT_CACHE_READ_RATE_RATIO = 0.5with the source and access date cited next to itcache_read_input_token_costvalues, standard or off-peak, stay authoritativelitellm/llms/fireworks_ai/cache_pricing.py; shared cost utils only dispatch by providerconfig.yamlare coerced before the discount, like the other cost fieldsUser Flow
Before: a team routing a Fireworks model without a cache-read price in the map sees cached prompts cost the same as uncached ones
fw-qwen-no-cache-rate, a Fireworks model priced at 9e-7 per input token and no cache-read priceprompt_tokens_details.cached_tokens: 2564out of 2565 prompt tokensx-litellm-response-costheader reads0.002313, the same as a fully uncached prompt, and the spend log records that amountAfter: the same request is billed at the documented Fireworks cached-token discount
fw-qwen-no-cache-rateprompt_tokens_details.cached_tokens: 2564x-litellm-response-costheader reads0.0011592, withx-litellm-response-cost-cache-read: 0.0011538(2564 tokens at half the input rate), and the spend log records that amountfw-glm-explicit-cache-rate) is billed exactly as beforeRelevant issues
Affected release
Linear ticket
Resolves LIT-7845
Closes LIT-7845
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Live proxy against the real Fireworks API, no mocks. Both arms use byte-identical request bodies (sha256
eeaa2f37...for the no-cache-rate body,1a61ee35...for the explicit-rate body) and the same config. The proxy is started withPYTHONPATH=<checkout>so each arm loads the intended treeConfig (
config.yaml); the Qwen deployment is not in the local pricing map, so it gets explicit input/output rates and no cache-read rate, which is exactly the ticket's shape. The GLM entry has an explicitcache_read_input_token_costin the map and acts as the override control:Request loop (
run_arm.sh), one warm and one cached leg per body:Before (ff7dc86)
Proxy:
PYTHONPATH=/home/ubuntu/repos/litellm-base python litellm/proxy/proxy_cli.py --config config.yaml --port 4000 --detailed_debugNo cache-read rate in the map (fw-qwen-no-cache-rate)
./run_arm.sh BEFOREExplicit cache-read rate in the map (fw-glm-explicit-cache-rate)
After (05cefb1)
Proxy:
PYTHONPATH=/home/ubuntu/repos/litellm python litellm/proxy/proxy_cli.py --config config.yaml --port 4000 --detailed_debug. Build check:python -c "import litellm.llms.fireworks_ai.cache_pricing as m; print(hasattr(m, '_as_rate'))"printsTrueunder that PYTHONPATHNo cache-read rate in the map (fw-qwen-no-cache-rate)
./run_arm.sh AFTERcached_tokens: 0and doubles as an uncached control; the cached leg is the fixed case:Explicit cache-read rate in the map (fw-glm-explicit-cache-rate)
Scope of the live run: both legs go through the proxy's
/v1/chat/completionspath into the Fireworks cost calculator and the token-type breakdown./v1/responsesand/v1/messagesshare the same cost calculator entry point and are not separately exercised here. Off-peak pricing is covered by the mapped unit tests only, since no live Fireworks entry in the map carries an off-peak block without a cache-read rateType
🐛 Bug Fix
Caveats (if any)
Medium
cache_read_input_token_costin the mapLow
generic_cost_per_tokenand caching savings paths now share the dispatcher); X4 found by Bugbot and fixed (string rates from config are coerced like the other cost fields); W1 not applicable, the helper copies the entry and its off-peak block; X1-X5 usesis Noneand key presence, an explicit 0 rate is preserved; C1 recorded above as the intended default change; T1-T5/T17 covered by regressions that fail when the ratio is 1.0 or the helper call is removed; H1-H10 pass mechanically, the only new source comment is the ticket-required citationFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/deb1acef3f4249c5874229b6948681c9
Open in Devin Desktop: https://app.devin.ai/desktop/session/deb1acef3f4249c5874229b6948681c9?variant=devin