Skip to content

fix(cost_calc): default fireworks cached input to the documented 50% discount when the map has no cache-read rate - #41917

Merged
kerry-berri merged 4 commits into
mainfrom
litellm_fireworks_cache_read_default_discount
Sep 19, 2026
Merged

kerry-berri merged 4 commits into
mainfrom
litellm_fireworks_cache_read_default_discount

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Fireworks entries without a cache-read rate billed cached tokens at the full input rate
  • Fireworks documents a default 50% discount for serverless cached prompt tokens
  • The per-type cost breakdown and caching savings had the same full-rate gap

How it solves it:

  • New FIREWORKS_AI_DEFAULT_CACHE_READ_RATE_RATIO = 0.5 with the source and access date cited next to it
  • Missing standard or off-peak cache-read rates derive from the matching input rate times 0.5
  • Explicit cache_read_input_token_cost values, standard or off-peak, stay authoritative
  • The derivation lives in litellm/llms/fireworks_ai/cache_pricing.py; shared cost utils only dispatch by provider
  • String rates from config.yaml are coerced before the discount, like the other cost fields
  • One shared dispatcher feeds the total, the token-type breakdown and the caching savings, so they cannot drift

User 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

  1. They send POST http://localhost:4000/v1/chat/completions with a long system prompt to fw-qwen-no-cache-rate, a Fireworks model priced at 9e-7 per input token and no cache-read price
  2. The 200 response reports prompt_tokens_details.cached_tokens: 2564 out of 2565 prompt tokens
  3. The x-litellm-response-cost header reads 0.002313, the same as a fully uncached prompt, and the spend log records that amount

After: the same request is billed at the documented Fireworks cached-token discount

  1. They send the same POST http://localhost:4000/v1/chat/completions to fw-qwen-no-cache-rate
  2. The 200 response again reports prompt_tokens_details.cached_tokens: 2564
  3. The x-litellm-response-cost header reads 0.0011592, with x-litellm-response-cost-cache-read: 0.0011538 (2564 tokens at half the input rate), and the spend log records that amount
  4. A model with an explicit cache-read price (fw-glm-explicit-cache-rate) is billed exactly as before

Relevant 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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to 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 with PYTHONPATH=<checkout> so each arm loads the intended tree

Config (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 explicit cache_read_input_token_cost in the map and acts as the override control:

model_list:
  - model_name: fw-glm-explicit-cache-rate
    litellm_params:
      model: fireworks_ai/accounts/fireworks/models/glm-5p2
      api_key: os.environ/FW_PROOF_KEY
  - model_name: fw-qwen-no-cache-rate
    litellm_params:
      model: fireworks_ai/accounts/fireworks/models/qwen3p8-2p4t-a95b
      api_key: os.environ/FW_PROOF_KEY
    model_info:
      input_cost_per_token: 9e-07
      output_cost_per_token: 9e-07
general_settings:
  master_key: sk-1234

Request loop (run_arm.sh), one warm and one cached leg per body:

for body in body_no_cache_rate.json body_explicit_cache_rate.json; do
  for leg in warm cached; do
    echo "== $1 $body $leg =="
    curl -s -D - -o resp.json localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d @$body | grep -iE "^HTTP|x-litellm-response-cost"
    python3 -c "import json;r=json.load(open('resp.json'));print('usage:',json.dumps(r.get('usage')))"
    sleep 2
  done
done

Before (ff7dc86)

Proxy: PYTHONPATH=/home/ubuntu/repos/litellm-base python litellm/proxy/proxy_cli.py --config config.yaml --port 4000 --detailed_debug

No cache-read rate in the map (fw-qwen-no-cache-rate)

  1. ./run_arm.sh BEFORE
  2. Output, both legs identical:
== BEFORE body_no_cache_rate.json cached ==
HTTP/1.1 200 OK
x-litellm-response-cost: 0.002313
x-litellm-response-cost-input: 8.999999999998592e-07
x-litellm-response-cost-cache-read: 0.0023076
x-litellm-response-cost-tool-usage: 0.0
usage: {"completion_tokens": 5, "prompt_tokens": 2565, "total_tokens": 2570, "completion_tokens_details": {"reasoning_tokens": 5}, "prompt_tokens_details": {"cached_tokens": 2564}, "output_tokens_details": {"reasoning_tokens": 5}}
  1. 2564 cached tokens x 9e-7 = 0.0023076: cached tokens billed at the full input rate

Explicit cache-read rate in the map (fw-glm-explicit-cache-rate)

  1. Same loop, second body
  2. Output:
== BEFORE body_explicit_cache_rate.json cached ==
HTTP/1.1 200 OK
x-litellm-response-cost: 0.00035688
x-litellm-response-cost-input: 1.3999999999999798e-06
x-litellm-response-cost-cache-read: 0.00033348000000000004
x-litellm-response-cost-tool-usage: 0.0
usage: {"completion_tokens": 5, "prompt_tokens": 2383, "total_tokens": 2388, "completion_tokens_details": {"reasoning_tokens": 5}, "prompt_tokens_details": {"cached_tokens": 2382}, "output_tokens_details": {"reasoning_tokens": 5}}

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'))" prints True under that PYTHONPATH

No cache-read rate in the map (fw-qwen-no-cache-rate)

  1. ./run_arm.sh AFTER
  2. Output. The Fireworks cache had expired by the time this arm ran, so the warm leg came back with cached_tokens: 0 and doubles as an uncached control; the cached leg is the fixed case:
== AFTER body_no_cache_rate.json warm ==
HTTP/1.1 200 OK
x-litellm-response-cost: 0.002313
x-litellm-response-cost-input: 0.0023085
x-litellm-response-cost-tool-usage: 0.0
usage: {"completion_tokens": 5, "prompt_tokens": 2565, "total_tokens": 2570, "completion_tokens_details": {"reasoning_tokens": 5}, "prompt_tokens_details": {"cached_tokens": 0}, "output_tokens_details": {"reasoning_tokens": 5}}
== AFTER body_no_cache_rate.json cached ==
HTTP/1.1 200 OK
x-litellm-response-cost: 0.0011592
x-litellm-response-cost-input: 9.000000000000761e-07
x-litellm-response-cost-cache-read: 0.0011538
x-litellm-response-cost-tool-usage: 0.0
usage: {"completion_tokens": 5, "prompt_tokens": 2565, "total_tokens": 2570, "completion_tokens_details": {"reasoning_tokens": 5}, "prompt_tokens_details": {"cached_tokens": 2564}, "output_tokens_details": {"reasoning_tokens": 5}}
  1. 2564 cached tokens x 4.5e-7 = 0.0011538, 1 uncached token x 9e-7, 5 completion tokens x 9e-7: total 0.0011592. An uncached prompt of the same size (warm leg) still costs 0.002313, so only the cached tokens moved

Explicit cache-read rate in the map (fw-glm-explicit-cache-rate)

  1. Same loop, second body
  2. Output, unchanged from Before:
== AFTER body_explicit_cache_rate.json cached ==
HTTP/1.1 200 OK
x-litellm-response-cost: 0.00035688
x-litellm-response-cost-input: 1.3999999999999798e-06
x-litellm-response-cost-cache-read: 0.00033348000000000004
x-litellm-response-cost-tool-usage: 0.0
usage: {"completion_tokens": 5, "prompt_tokens": 2383, "total_tokens": 2388, "completion_tokens_details": {"reasoning_tokens": 5}, "prompt_tokens_details": {"cached_tokens": 2382}, "output_tokens_details": {"reasoning_tokens": 5}}

Scope of the live run: both legs go through the proxy's /v1/chat/completions path into the Fireworks cost calculator and the token-type breakdown. /v1/responses and /v1/messages share 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 rate

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Fireworks entries in the map with an input rate and no cache-read rate now bill cached tokens at 50% instead of 100%: an intended default change scoped to this ticket
  • The 0.5 default is Fireworks' documented default; models with a different discount need an explicit cache_read_input_token_cost in the map

Low

  • Taxonomy audit (A-BB) on the final diff: F3 found and fixed (the breakdown, generic_cost_per_token and 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 uses is None and 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 citation

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/deb1acef3f4249c5874229b6948681c9
Open in Devin Desktop: https://app.devin.ai/desktop/session/deb1acef3f4249c5874229b6948681c9?variant=devin

…discount when the map has no cache-read rate

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 19, 2026 01:08
@CLAassistant

CLAassistant commented Sep 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@codspeed

codspeed Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_fireworks_cache_read_default_discount (05cefb1) with main (4b4042c)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (fc0b37f) during the generation of this report, so 4b4042c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/llms/fireworks_ai/cache_pricing.py 90.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no outstanding correctness, security, or repository-rule issue was identified.

Summary

This PR applies Fireworks’ documented default cached-input discount when pricing metadata omits a cache-read rate.

  • Keeps explicit standard and off-peak cache-read rates authoritative.
  • Derives missing rates from the corresponding input rate without mutating shared model metadata.
  • Routes totals, token-type breakdowns, and caching-savings calculations through the same provider-owned derivation.
  • Adds regression coverage for standard, off-peak, explicit, missing, and string-configured rates.

Reviews (4) · Last reviewed commit: "fix(cost_calc): coerce string fireworks ..."

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…llm/llms

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Addressed the Greptile boundary finding: the Fireworks cache-read derivation now lives under litellm/llms/fireworks_ai, shared utils only dispatch by provider

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…-through

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@kerry-berri
kerry-berri merged commit c4ddea7 into main Sep 19, 2026
89 checks passed
@kerry-berri
kerry-berri deleted the litellm_fireworks_cache_read_default_discount branch September 19, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants