Repository navigation
fix(cost): price base_model deployments past rule-only cost map entries - #47497
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@litellm-stampbot |
litellm-stampbot: risk highNot approved at Rules (
Cursor Bugbot: Medium Risk at Pushes do not re-run this check. Comment |
|
bugbot run |
…es and warn when base_model has no rates
861105d to
0ca8c96
Compare
…honour model_info prices
|
@litellm-stampbot |
|
bugbot run |
…e one-line ladder fix
|
@litellm-stampbot |
|
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 df8c4f7. Configure here.
|
@yuneng-berri Any chance to backport this into the |
|
Just opened it in #51412 |
…es (BerriAI#47497) * fix(cost): price base_model deployments past rule-only cost map entries and warn when base_model has no rates * fix(router): warn on unpriced base_model from add_deployment too and honour model_info prices * refactor(cost): drop the unpriced base_model startup warning, keep the one-line ladder fix --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 8d2bf42) Co-authored-by: Kerry Lu <klu@berri.ai>
…s_1_108_x fix(cost): backport #47497 to lts/1.108.x
TLDR
Problem this solves:
model_info.base_model: azure/eu/o3(oro4-mini,o1,o3-mini) bills $0 on every requestcompletion_coststops there becausebase_modelskipped the priced-first reorder from fix(cost): price exact cost-map names before price-free capability rules, and fix SCIM and MCP integration tests on CircleCI #47037How it solves it:
custom_pricingkeeps the candidate order now, a plainbase_modelgoes through_priced_candidates_before_unpriced_ruleslike every other deployment (one line)tests/unit/test_cost_calculator.pyfails on main (0.0) and passes hereWith this change a rule-only
base_modelbills from the response model's row (the globalazure/o3-2025-04-16rate rather than the EU one), so it is no longer $0. #47561 added the undatedazure/eu/andazure/us/rows, sobase_model: azure/eu/o3itself is now priced and bills the EU rate. An earlier revision of this PR also logged a startup warning for abase_modelwith no prices, dropped as not worth the codeUser Flow
Before: an admin points an EU Data Zone deployment at
base_model: azure/eu/o3and every request is recorded at $0model_info: {base_model: azure/eu/o3}to the deployment in config.yaml and starts the proxy"model": "eu-o3"and gets a normal 200 with usagex-litellm-response-cost-input: 0.0andx-litellm-response-cost-output: 0.0, and http://localhost:4000/ui/?page=logs shows the request at $0, so no key, team or user budget movesAfter: the same deployment bills from the response model
model_info: {base_model: azure/eu/o3}and starts the proxy"model": "eu-o3"and gets the same 200x-litellm-response-cost, priced from the response'smodel, and the logs page shows real spendLinear ticket
Resolves LIT-9812
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<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 moreScreenshots / Proof of Fix
Live proxy on localhost:4000, no database,
LITELLM_LOCAL_MODEL_COST_MAP=True, real Azure OpenAI spend. Azure no longer lets you create o-series deployments (o4-mini2025-04-16 returnsServiceModelDeprecating), so the rig is a realgpt-4oAzure deployment whosemodel_info.base_modelis set toazure/eu/o3. The cost ladder it exercises is the same one an existing EU o3 deployment hits, only the row it falls back to differs (azure/gpt-4o-2024-11-20here,azure/o3-2025-04-16for a real o3 deployment)config.yaml
Request, same on both sides
Before (da80552)
chatcmpl-EawFYvGAjuZPXaQNatd2UIhYtsmMd, 200, usage{"prompt_tokens": 12, "completion_tokens": 2, "total_tokens": 14}, Azure answered withmodel: gpt-4o-2024-11-20After (861105d, same
completion_costline as the current head)chatcmpl-EawFsV8bducSiHk2MUEYzoTzTnqzU, 200, usage{"prompt_tokens": 12, "completion_tokens": 2, "total_tokens": 14}, Azure answered withmodel: gpt-4o-2024-11-20azure/gpt-4o-2024-11-20rowType
🐛 Bug Fix
Link to Devin session: https://app.devin.ai/sessions/108f1ade091d4518b6bb1dc991c462e7
Open in Devin Desktop: https://app.devin.ai/desktop/session/108f1ade091d4518b6bb1dc991c462e7?variant=devin
Requested by: @kerrylu-berri
Note
Medium Risk
Touches spend/budget accounting in
completion_costfor deployments withbase_model; behavior change is intentional but affects billing amounts for rule-only base names.Overview
Fixes $0 billing when a proxy deployment sets
model_info.base_modelto a name that only hits a capability rule in the cost map (no token rates).completion_costused to keep the raw candidate order wheneverbase_modelwas set (explicit_pricing), so it stopped on that rule-only entry instead of trying priced fallbacks.Change: only
custom_pricing=Trueskips_priced_candidates_before_unpriced_rules; a plainbase_modelnow gets the same priced-first reorder as other deployments, so billing can use the response model (or other priced candidates) when the base name has no rates.Adds a unit regression (LIT-9812) for an Azure deployment whose undated
base_modelis rule-only while the response names a priced model.Reviewed by Cursor Bugbot for commit df8c4f7. Bugbot is set up for automated code reviews on this repo. Configure here.