Skip to content

fix(cost_calculator): honour base_model when the deployment provider row has no rates, with a live-proxy integration test - #46318

Merged
klu-berri merged 2 commits into
mainfrom
litellm_base_model_cross_provider_spend
Oct 14, 2026
Merged

klu-berri merged 2 commits into
mainfrom
litellm_base_model_cross_provider_spend

Conversation

@klu-berri

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • chatgpt/ deployments with model_info.base_model record $0 spend
  • The base model resolves back to the unpriced chatgpt/ row
  • Nothing in tests/integration covered base_model pricing across providers

How it solves it:

This PR is #46244 rebased on current main plus the integration test. Merging either one is fine: if #46244 lands first this PR shrinks to the test commit

User Flow

Before: a proxy admin prices a ChatGPT subscription deployment through base_model, but every request is logged at $0

  1. The admin sets model: chatgpt/gpt-5.6-sol with model_info.base_model: gpt-5.6-sol (or openai/gpt-5.6-sol, azure/gpt-5.6-sol)
  2. A developer sends POST http://localhost:4000/v1/responses with "model": "gpt-5.6-sol" and gets a 200 with real token counts
  3. http://localhost:4000/ui/?page=logs shows that request at $0 spend

After: the same request is priced from the base model's rates

  1. The admin keeps the same config
  2. The developer sends the same POST http://localhost:4000/v1/responses and gets the same 200
  3. http://localhost:4000/ui/?page=logs shows non-zero spend matching the gpt-5.6-sol rates

Relevant issues

Fixes #46233

Supersedes #46244 when merged first (its commit is carried here with the original authorship)

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

The live curl run against the real ChatGPT backend (1637 prompt, 5 completion tokens, spend 0 before and 0.0015792 after) is in #46244's description. Below is the same bug through the new integration test, which boots a real proxy with Postgres and Redis, serves a three-row cost map (chatgpt/cc-subscription-sol with no rates, cc-subscription-sol at $1/M in and $8/M out under openai, azure/cc-subscription-sol at $3/M in and $5/M out), registers a chatgpt/cc-subscription-sol deployment with model_info.base_model, sends POST /v1/responses, and reads LiteLLM_SpendLogs

Command:

INTEGRATION_WORKERS=2 .venv/bin/python tests/integration/run.py cost --results /tmp/integ tests/integration/cost_calculation/test_base_model_cross_provider_spend.py

Before (22000e1)

  1. Run the command above with the test file copied onto main
  2. Observed:
FAILED ...[cc-subscription-sol-0.0018]
FAILED ...[openai/cc-subscription-sol-0.0018]
FAILED ...[azure/cc-subscription-sol-0.0035]
E   KeyError: 'x-litellm-response-cost'
3 failed in 38.17s

The proxy omits x-litellm-response-cost when the computed cost is 0, so the header is missing and the spend row is 0 (the final assert now reads the header with a 0 default, so the message is 0.0 == approx(0.0018))

After (0f1443b)

  1. Run the same command
  2. Observed:
PASSED ...[cc-subscription-sol-0.0018]
PASSED ...[openai/cc-subscription-sol-0.0018]
PASSED ...[azure/cc-subscription-sol-0.0035]
3 passed in 41.17s

0.0018 is 1000 x 0.000001 + 100 x 0.000008 from the openai row, 0.0035 is 1000 x 0.000003 + 100 x 0.000005 from the azure row

Type

🐛 Bug Fix
✅ Test

Caveats (if any)

Low

  • Only applies when base_model is set and custom_pricing is off
  • Discounts and margins still key on the deployment provider
  • The integration test boots its own proxy (needs CHATGPT_TOKEN_DIR and its own cost map), about 15s of setup
  • make test-unit was not run locally, only the touched modules, ruff on the test file and scripts/test_quality_gate.py

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/bc6afa35154243d8819fca3295b5c826
Open in Devin Desktop: https://app.devin.ai/desktop/session/bc6afa35154243d8819fca3295b5c826?variant=devin
Requested by: @kerrylu-berri

sla55er and others added 2 commits October 13, 2026 23:18
…hen the deployment provider row has no rates

A chatgpt/ deployment with model_info.base_model recorded zero spend because the
base model was looked up under the chatgpt provider, which resolves to the
deliberately unpriced chatgpt/ row. When the deployment provider's row for the
base model declares no rates, price it under the provider of the base model's
own row instead. Deployments whose provider row declares rates are unchanged.

(cherry picked from commit 42d9a86)
…ed row on a live proxy

Co-authored-by: sla55er <stiliyanmarkov@gmail.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@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 all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ sla55er
❌ devin-ai-integration[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed

codspeed Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing litellm_base_model_cross_provider_spend (0f1443b) with main (365c488)1

Open in CodSpeed

Footnotes

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

@klu-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@litellm-stampbot

Copy link
Copy Markdown

litellm-stampbot: risk high

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

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Judge (gpt-6-luna): high, scoped behavior change, request hot path, moderate diff

  • tier: high (confidence 1.00)
  • change_kind: scoped_behavior_change (confidence 0.99)
  • blast_radius: request_hot_path (confidence 0.97)
  • complexity: moderate (confidence 0.82)

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

@litellm-stampbot litellm-stampbot Bot added the risk:high Sensitive, broad, or high-risk change label Oct 13, 2026
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

LGTM. Thanks!

@klu-berri
klu-berri merged commit ccdca3d into main Oct 14, 2026
88 checks passed
@klu-berri
klu-berri deleted the litellm_base_model_cross_provider_spend branch October 14, 2026 00:10
Cartofante pushed a commit to CartoDB/litellm that referenced this pull request Oct 26, 2026
…erriAI#47419)

Backport of BerriAI#47419 to stable/1.106.x.
Cherry-picked from 3124797 (main).
Adapted to the line without BerriAI#41523. Registered rates are tracked per cost-map key in litellm.utils (_registered_pricing_fields, reset when litellm.model_cost is replaced, so a request-scoped registration does not outlive its catalog) instead of AliasedCostEntry.registered_fields. AliasedCostEntry and get_model_cost_map.py are untouched. The register_model replay now merges successive registrations as on main. An inference-profile ARN model_id is reduced to its profile id inside _invoked_model_id_for_cost rather than backporting the get_model_info ARN handling from BerriAI#46128. Only BerriAI#47419's lines are taken in completion_cost; base_model_pricing_provider (BerriAI#46318) and configured search cost (BerriAI#46571) are not. Tests: CONVERSE_ANSWER added to the slow_upstream helper (it came with BerriAI#47162, which is not backported), the isolated_pricing_registry fixture and custom-pricing helpers come from main's test file, and the ignore_stamped_cost assertion uses the line's response_cost_calculator signature.
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.

[Bug]: model_info.base_model ignored for cost tracking on the chatgpt provider (spend stays 0)

4 participants