Repository navigation
fix(cost_calculator): honour base_model when the deployment provider row has no rates, with a live-proxy integration test - #46318
Conversation
…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>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
Merging this PR will not alter performance
|
|
@litellm-stampbot |
litellm-stampbot: risk highNot approved at Rules (
Judge (gpt-6-luna): high, scoped behavior change, request hot path, moderate diff
Pushes do not re-run this check. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…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.
TLDR
Problem this solves:
chatgpt/deployments withmodel_info.base_modelrecord $0 spendchatgpt/rowtests/integrationcovered base_model pricing across providersHow 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 $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
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
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
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-solwith no rates,cc-subscription-solat $1/M in and $8/M out under openai,azure/cc-subscription-solat $3/M in and $5/M out), registers achatgpt/cc-subscription-soldeployment withmodel_info.base_model, sends POST /v1/responses, and readsLiteLLM_SpendLogsCommand:
Before (22000e1)
The proxy omits
x-litellm-response-costwhen the computed cost is 0, so the header is missing and the spend row is 0 (the final assert now reads the header with a0default, so the message is0.0 == approx(0.0018))After (0f1443b)
0.0018is 1000 x 0.000001 + 100 x 0.000008 from the openai row,0.0035is 1000 x 0.000003 + 100 x 0.000005 from the azure rowType
🐛 Bug Fix
✅ Test
Caveats (if any)
Low
base_modelis set andcustom_pricingis offCHATGPT_TOKEN_DIRand its own cost map), about 15s of setupmake test-unitwas not run locally, only the touched modules,ruffon the test file andscripts/test_quality_gate.pyFinal Attestation
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