Skip to content

fix(cost): price base_model deployments past rule-only cost map entries - #47497

Merged
klu-berri merged 3 commits into
mainfrom
litellm_base_model_rule_only_cost
Oct 20, 2026
Merged

klu-berri merged 3 commits into
mainfrom
litellm_base_model_rule_only_cost

Conversation

@klu-berri

@klu-berri klu-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • Only custom_pricing keeps the candidate order now, a plain base_model goes through _priced_candidates_before_unpriced_rules like every other deployment (one line)
  • Regression test in tests/unit/test_cost_calculator.py fails on main (0.0) and passes here

With this change a rule-only base_model bills from the response model's row (the global azure/o3-2025-04-16 rate rather than the EU one), so it is no longer $0. #47561 added the undated azure/eu/ and azure/us/ rows, so base_model: azure/eu/o3 itself is now priced and bills the EU rate. An earlier revision of this PR also logged a startup warning for a base_model with no prices, dropped as not worth the code

User Flow

Before: an admin points an EU Data Zone deployment at base_model: azure/eu/o3 and every request is recorded at $0

  1. The admin adds model_info: {base_model: azure/eu/o3} to the deployment in config.yaml and starts the proxy
  2. A developer sends POST http://localhost:4000/v1/chat/completions with "model": "eu-o3" and gets a normal 200 with usage
  3. The response headers say x-litellm-response-cost-input: 0.0 and x-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 moves

After: the same deployment bills from the response model

  1. The admin adds the same model_info: {base_model: azure/eu/o3} and starts the proxy
  2. The developer sends the same POST http://localhost:4000/v1/chat/completions with "model": "eu-o3" and gets the same 200
  3. The response headers now carry a non-zero x-litellm-response-cost, priced from the response's model, and the logs page shows real spend

Linear ticket

Resolves LIT-9812

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/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 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
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / 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-mini 2025-04-16 returns ServiceModelDeprecating), so the rig is a real gpt-4o Azure deployment whose model_info.base_model is set to azure/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-20 here, azure/o3-2025-04-16 for a real o3 deployment)

config.yaml

model_list:
  - model_name: eu-gpt-4o
    litellm_params:
      model: azure/gpt-4o
      api_key: os.environ/AZURE_AI_API_KEY
      api_base: os.environ/AZURE_AI_API_BASE
      api_version: "2024-10-21"
    model_info:
      base_model: azure/eu/o3

general_settings:
  master_key: sk-1234

Request, same on both sides

curl -s -i localhost:4000/v1/chat/completions \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model":"eu-gpt-4o","messages":[{"role":"user","content":"Say hi in one word"}]}'

Before (da80552)

  1. Response chatcmpl-EawFYvGAjuZPXaQNatd2UIhYtsmMd, 200, usage {"prompt_tokens": 12, "completion_tokens": 2, "total_tokens": 14}, Azure answered with model: gpt-4o-2024-11-20
  2. Headers
x-litellm-response-cost-original: 0.0
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0

After (861105d, same completion_cost line as the current head)

  1. Response chatcmpl-EawFsV8bducSiHk2MUEYzoTzTnqzU, 200, usage {"prompt_tokens": 12, "completion_tokens": 2, "total_tokens": 14}, Azure answered with model: gpt-4o-2024-11-20
  2. Headers, 12 x 2.5e-6 + 2 x 1e-5 from the azure/gpt-4o-2024-11-20 row
x-litellm-response-cost: 5.000000000000001e-05
x-litellm-response-cost-input: 3.0000000000000004e-05
x-litellm-response-cost-output: 2e-05

Type

🐛 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_cost for deployments with base_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_model to a name that only hits a capability rule in the cost map (no token rates). completion_cost used to keep the raw candidate order whenever base_model was set (explicit_pricing), so it stopped on that rule-only entry instead of trying priced fallbacks.

Change: only custom_pricing=True skips _priced_candidates_before_unpriced_rules; a plain base_model now 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_model is 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.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

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

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed

codspeed Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 32 untouched benchmarks


Comparing litellm_base_model_rule_only_cost (df8c4f7) with main (04e9ed4)

Open in CodSpeed

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@klu-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

kerry-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

litellm-stampbot: risk high

Not approved at df8c4f7. risk is high, a human reviewer is needed.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Cursor Bugbot: Medium Risk at df8c4f7. Touches spend/budget accounting in completion_cost for deployments with base_model; behavior change is intentional but affects billing amounts for rule-only base names. Bugbot run requested, finished in 3 min.
Bugbot Low is low, Medium and High are high. The judge model was not called.

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@devin-ai-integration
devin-ai-integration Bot force-pushed the litellm_base_model_rule_only_cost branch from 861105d to 0ca8c96 Compare October 20, 2026 13:52

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

Comment thread litellm/router.py Resolved
Comment thread litellm/router_utils/common_utils.py Resolved
@kerry-berri kerry-berri added the risk:high Sensitive, broad, or high-risk change label Oct 20, 2026
@klu-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@devin-ai-integration devin-ai-integration Bot changed the title fix(cost): price base_model deployments past rule-only cost map entries and warn when base_model has no rates fix(cost): price base_model deployments past rule-only cost map entries Oct 20, 2026

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

@klu-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@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 df8c4f7. Configure here.

@klu-berri
klu-berri merged commit 8d2bf42 into main Oct 20, 2026
143 of 146 checks passed
@klu-berri
klu-berri deleted the litellm_base_model_rule_only_cost branch October 20, 2026 16:26
@ramundomario

Copy link
Copy Markdown

@yuneng-berri Any chance to backport this into the v1.108.x LTS version? Thanks!

@ramundomario

Copy link
Copy Markdown

Just opened it in #51412

ramundomario added a commit to ramundomario/litellm that referenced this pull request Nov 12, 2026
…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>
kerry-berri added a commit that referenced this pull request Nov 16, 2026
…s_1_108_x

fix(cost): backport #47497 to lts/1.108.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high Sensitive, broad, or high-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants