Skip to content

fix(cost_calculator): honour base_model when the deployment provider row has no rates - #46244

Closed
sla55er wants to merge 1 commit into
BerriAI:mainfrom
sla55er:bugfix/base-model-cost-chatgpt-provider
Closed

sla55er wants to merge 1 commit into
BerriAI:mainfrom
sla55er:bugfix/base-model-cost-chatgpt-provider

Conversation

@sla55er

@sla55er sla55er commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Documented behaviour

The custom-pricing docs say: "Set base_model to the key you want LiteLLM to use for pricing lookup" (https://docs.litellm.ai/docs/proxy/custom_pricing, section "Set 'base_model' for Cost Tracking"), without restricting it to a provider. The ChatGPT provider page notes that these models "have no price in the cost map, so recorded spend is $0" (https://docs.litellm.ai/docs/providers/chatgpt). Per the first page, pointing base_model at a priced key should give that provider a cost; today it does not, because the provider's unpriced row is resolved first.

Problem this solves:

  • chatgpt/ deployments with model_info.base_model record $0 spend
  • The base model resolves back to the unpriced chatgpt/ row

How it solves it:

  • Check whether the deployment provider's row for the base model has rates
  • If it has none, price under the base model's own row and provider
  • Deployments whose provider row declares rates keep today's pricing

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

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

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

Config:

model_list:
  - model_name: chatgpt/gpt-5.6-sol
    litellm_params:
      model: chatgpt/gpt-5.6-sol
    model_info:
      mode: responses
      base_model: gpt-5.6-sol

Request (one real call per run, against a proxy with Postgres):

curl http://localhost:4000/v1/chat/completions \
  -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" \
  -d '{"model":"chatgpt/gpt-5.6-sol","messages":[{"role":"user","content":"Reply with the single word pong."}],"max_tokens":5}'

Both runs returned pong with the same usage: prompt_tokens 1637 (of which cached_tokens 1408), completion_tokens 5. Spend is read from LiteLLM_SpendLogs:

Run model prompt_tokens completion_tokens spend
Before: ghcr.io/berriai/litellm:main-latest (sha256:de5b050c1e9bd7e6c0aebfa126c5df71de071962592ba3e9638b28e45bed3901) chatgpt/gpt-5.6-sol 1637 5 0
After: same image with only this PR's change to litellm/cost_calculator.py applied chatgpt/gpt-5.6-sol 1637 5 0.0015792

The "after" run is an overlay: the nightly image's cost_calculator.py with this PR's diff applied, copied into the container, not an image built from the branch.

Check against the gpt-5.6-sol rates (input $4/M, cached input $0.40/M, output $20/M):

  • uncached input: (1637 - 1408) x $4/M = 229 x 0.000004 = $0.000916
  • cached input: 1408 x $0.40/M = 1408 x 0.0000004 = $0.0005632
  • output: 5 x $20/M = 5 x 0.00002 = $0.0001
  • total: $0.0015792, equal to the logged spend

Type

🐛 Bug Fix

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
  • make test-unit was not run locally, only the touched modules and make lint

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

@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 sla55er:bugfix/base-model-cost-chatgpt-provider (42d9a86) with main (784581b)

Open in CodSpeed

@sla55er

sla55er commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

The one failing check (unit / root) is tests/unit/test_model_prices_schema.py::test_price_map_has_no_duplicate_keys: gemini-4-argon and vertex_ai/gemini-4-argon are each defined twice in model_prices_and_context_window.json on main after #46228 and #46237 both added them. This branch does not touch the price map; I'll rebase once main is deduplicated so the check reruns.

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

…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.
@github-actions

Copy link
Copy Markdown
Contributor

#46233 was fixed by #46318 on main, so this pull request is closed. Reopen it if something was missed.

@github-actions github-actions Bot closed this Oct 14, 2026
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.

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

1 participant