Repository navigation
Conversation
Merging this PR will not alter performance
|
|
The one failing check ( |
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.
742175d to
42d9a86
Compare
TLDR
Documented behaviour
The custom-pricing docs say: "Set
base_modelto 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, pointingbase_modelat 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 withmodel_info.base_modelrecord $0 spendchatgpt/rowHow it solves it:
User Flow
Before: a proxy admin prices a ChatGPT subscription deployment through
base_model, but every request is logged at $0model: chatgpt/gpt-5.6-solwithmodel_info.base_model: gpt-5.6-sol(oropenai/gpt-5.6-sol,azure/gpt-5.6-sol)"model": "gpt-5.6-sol"and gets a 200 with real token countsAfter: the same request is priced from the base model's rates
gpt-5.6-solratesRelevant issues
Fixes #46233
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 moreDelays 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:
Request (one real call per run, against a proxy with Postgres):
Both runs returned
pongwith the same usage:prompt_tokens1637 (of whichcached_tokens1408),completion_tokens5. Spend is read fromLiteLLM_SpendLogs:modelprompt_tokenscompletion_tokensspendghcr.io/berriai/litellm:main-latest(sha256:de5b050c1e9bd7e6c0aebfa126c5df71de071962592ba3e9638b28e45bed3901)chatgpt/gpt-5.6-sollitellm/cost_calculator.pyappliedchatgpt/gpt-5.6-solThe "after" run is an overlay: the nightly image's
cost_calculator.pywith this PR's diff applied, copied into the container, not an image built from the branch.Check against the
gpt-5.6-solrates (input $4/M, cached input $0.40/M, output $20/M):Type
🐛 Bug Fix
Caveats (if any)
Low
base_modelis set andcustom_pricingis offmake test-unitwas not run locally, only the touched modules andmake lintFinal Attestation