fix(databricks): delegate to generic_cost_per_token for cache/audio/reasoning - #35616
Closed
michaelxer wants to merge 3 commits into
Closed
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
Author
|
Fixed the lint failure on this branch: swapped |
…easoning Resolves litellm/litellm#35608 — Databricks cost_calculator ignored cached tokens, audio tokens, and reasoning tokens. The old hand-rolled arithmetic charged every prompt token at the full input rate. The generic_cost_per_token path (already used by DeepSeek, XAI, Perplexity, etc.) correctly applies cache_read_input_token_cost, audio, and reasoning rates when present in Usage. Added regression tests that pin the generic path and verify the new behavior. Pricing integrity test still passes. PR body updated with the same human style as previous directus fix (detailed explanation + verification steps).
CI lint failed because ruff format --check wanted single-line startswith/generic_cost_per_token calls.
Replace typing.Tuple with tuple[] to satisfy the strict ruff UP006/UP035 budget on this path.
michaelxer
force-pushed
the
michaelxer/fix-databricks-generic-cost-20260803
branch
from
August 4, 2026 22:56
310c6b0 to
6fcf7e8
Compare
Contributor
Author
|
Closing this draft — #37975 already landed the same Databricks cost path on staging ( |
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
Problem this solves:
How it solves it:
Relevant issues
Fixes #35608
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@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
Local unit verification (no mocks of the cost math itself; synthetic Usage objects exercise the real generic path):
What the new tests pin:
cache_read_input_token_costinstead of the full input rate (the old path would have charged full rate for every token)_resolve_databricks_base_modelI do not have Databricks credentials on this machine, so I could not hit a live Databricks endpoint for an e2e spend proof. Happy to re-run against a live proxy if a maintainer wants that.
Type
🐛 Bug Fix
Changes
litellm/llms/databricks/cost_calculator.pyused to do:That ignores
prompt_tokens_details.cached_tokens, cache-creation tokens, audio tokens, and reasoning tokens. Issue #35608 called this out as the same shape as the Fireworks bug fixed in #33714.This PR keeps the existing Databricks deployment-name remapping (dbrx / llama / mixtral / embeddings aliases), then hands billing to
generic_cost_per_token(..., custom_llm_provider="databricks"), which already handles those Usage fields for DeepSeek, XAI, and other OpenAI-compatible providers.Today no Databricks pricing-table entry publishes
cache_read_input_token_cost, so there is no active mis-billing in production numbers. The risk is latent: the moment a Databricks entry gains a cache-read rate (as Fireworks did), cached tokens would silently bill at the full input rate without this change. The regression tests inject a temporary cache-read rate so that path is covered now.Final Attestation