Repository navigation
fix(logging): report the cost-map entry billing used in model_map_information - #47182
Conversation
…ormation Billing resolved the deployment's own cost-map entry and logging ran a second, name-only lookup, so callbacks and spend logs showed the catalog rates for a custom-priced deployment. completion_cost now stores the entry it billed from on the logging object and the standard logging payload reads it, falling back to the old lookup only when billing never ran.
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Drop the logging-object plumbing and keep the lookup where it was: get_standard_logging_object_payload now hands the deployment id to get_model_cost_information as router_model_id, the same id billing uses, so the deployment's own cost-map entry is reported instead of the catalog entry.
Merging this PR will not alter performance
|
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@litellm-stampbot |
litellm-stampbot: risk lowApproved at Rules (
Cursor Bugbot: Low Risk at Pushes do not re-run this check. Comment |
|
bugbot run |
|
@litellm-stampbot |
|
bugbot run |
There was a problem hiding this comment.
✅ 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 1554428. Configure here.
kerry-berri
left a comment
There was a problem hiding this comment.
Low risk by rule and by judgement at 1554428
…ormation (BerriAI#47182) Backport of BerriAI#47182 to stable/1.103.x. Cherry-picked from 1212260 (main). Test-file conflict resolved by keeping the line's file and appending this PR's tests. Calls the line's _select_model_name_for_cost_calc, which is the private name on this line.
…ormation (BerriAI#47182) Backport of BerriAI#47182 to stable/1.106.x. Cherry-picked from 1212260 (main). Test conflict resolved by keeping the line's file plus this PR's own tests.
…ormation (#47182) * fix(logging): report the cost-map entry billing used in model_map_information Billing resolved the deployment's own cost-map entry and logging ran a second, name-only lookup, so callbacks and spend logs showed the catalog rates for a custom-priced deployment. completion_cost now stores the entry it billed from on the logging object and the standard logging payload reads it, falling back to the old lookup only when billing never ran. * fix(logging): pass the deployment id into the logging cost-map lookup Drop the logging-object plumbing and keep the lookup where it was: get_standard_logging_object_payload now hands the deployment id to get_model_cost_information as router_model_id, the same id billing uses, so the deployment's own cost-map entry is reported instead of the catalog entry. * test(logging): mirror the proxy metadata in the deployment-price regression test * fix(logging): keep the catalog model_map_key, report only the deployment's own rates --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 1212260)
…ormation (BerriAI#47182) Backport of BerriAI#47182 to stable/1.105.x. Cherry-picked from 1212260 (main). Adapted to the line: calls the line's _select_model_name_for_cost_calc (public on main) and the test uses the line's _response_cost_calculator and a local payload import; the test is appended since its main-side neighbours are not on the line.
TLDR
Problem this solves:
input_cost_per_token/output_cost_per_tokenis billed at that pricemodel_map_informationand the spend log metadata show the catalog price of the modelHow it solves it:
select_model_name_for_cost_calc, which returns the deployment entry only when given the deployment idget_standard_logging_object_payloadnow passeslogging_obj.get_router_model_id()intoget_model_cost_information, which uses it only to pick the entry behindmodel_map_valuemodel_map_keystays the catalog name it is today (openai/gpt-6-luna), so nothing grouping on that key changesPseudo-diff:
No change to
model_map_key: for every deployment it stays the catalog name (openai/gpt-6-luna). Onlymodel_map_valuechanges, and only for a deployment with its own price, where it is now that deployment's entry (1e-06 / 2e-06for the priced one,0 / 0for the zero-priced one). Deployments without their own price are unchangedUser Flow
Before: a proxy admin prices a deployment themselves, the bill is right, but their logging destination and the spend logs disagree with it
model_info: {id: priced-deployment, input_cost_per_token: 0.000001, output_cost_per_token: 0.000002}to a deployment ofopenai/gpt-6-lunaand restart the proxy"model": "priced-alias"and get 200 withx-litellm-response-cost: 2.2e-05for 10 input and 6 output tokensmodel_map_informationsayingopenai/gpt-6-lunaat1e-07in and5e-07out, which would make the bill4e-06, not2.2e-052.2e-05with the same catalog rates in its metadata, and a deployment priced at 0 shows those non-zero rates tooAfter: the same request is logged at the price it was billed at
model_infoprices to the deployment and restart the proxy"model": "priced-alias"and get 200 withx-litellm-response-cost: 2.2e-05model_map_informationstill keyedopenai/gpt-6-lunabut at1e-06in and2e-06out, which multiplies out to the2.2e-05they were charged0and0Relevant issues
Fixes #46651
Linear ticket
Resolves LIT-9660
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
Shared setup: a local proxy with a local Postgres, three deployments of the same model pointed at a local OpenAI-compatible server that answers every chat completion with
usage: {prompt_tokens: 10, completion_tokens: 6}, and a 15-line CustomLogger that appendsstandard_logging_object.model_map_informationtoslo.jsonl. Expected bills: custom price10 * 1e-06 + 6 * 2e-06 = 2.2e-05, catalog price10 * 1e-07 + 6 * 5e-07 = 4e-06Test mutation check: with
litellm/litellm_core_utils/litellm_logging.pyreverted to main and the new test kept,test_standard_logging_payload_reports_the_deployment_entry_the_request_was_billed_fromfails in both parametrizations onmodel_map_information(catalog key and rates come back), and passes at the tipBefore (4bafebb)
Custom-priced deployment (priced-alias, 1e-06 in / 2e-06 out)
Send the request
Read what the callback received in
standard_logging_object.model_map_information(the callback appends it toslo.jsonl)Read the spend log row
Explicit zero-priced deployment (zero-alias, 0 / 0)
Send the request
Read what the callback received in
standard_logging_object.model_map_information(the callback appends it toslo.jsonl)Read the spend log row
Deployment with no price of its own (plain-alias)
Send the request
Read what the callback received in
standard_logging_object.model_map_information(the callback appends it toslo.jsonl)Read the spend log row
After (1554428)
Custom-priced deployment (priced-alias, 1e-06 in / 2e-06 out)
Send the request
Read what the callback received in
standard_logging_object.model_map_information(the callback appends it toslo.jsonl)Read the spend log row
Explicit zero-priced deployment (zero-alias, 0 / 0)
Send the request
Read what the callback received in
standard_logging_object.model_map_information(the callback appends it toslo.jsonl)Read the spend log row
Deployment with no price of its own (plain-alias)
Send the request
Read what the callback received in
standard_logging_object.model_map_information(the callback appends it toslo.jsonl)Read the spend log row
Type
🐛 Bug Fix
Caveats (if any)
Low
model_map_valuefor a custom-priced deployment now carries that deployment's entry instead of the catalog entry, so fields other than the two rates (max_input_tokens,supported_openai_params, and so on) come from the deployment's registered entry.model_map_keyis unchangedFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/a2d63811dfbf4b969587ba4e1eae1f65
Open in Devin Desktop: https://app.devin.ai/desktop/session/a2d63811dfbf4b969587ba4e1eae1f65?variant=devin
Requested by: @kerrylu-berri
Note
Low Risk
Logging metadata only; billing logic is unchanged and
model_map_keybehavior is preserved.Overview
Standard logging payloads were showing catalog token rates in
model_map_informationeven when a router deployment billed at custom or zero prices, so spend logs and callbacks disagreed withresponse_cost.get_model_cost_informationnow acceptsrouter_model_idand, when present, resolvesmodel_map_valuevia the sameselect_model_name_for_cost_calcpath billing already uses (deployment id in the cost map).model_map_keyis unchanged (still the catalog model name for grouping).get_standard_logging_object_payloadpasseslogging_obj.get_router_model_id()into that helper. A parametrized unit test covers custom and explicit zero deployment pricing in the payload.Reviewed by Cursor Bugbot for commit 1554428. Bugbot is set up for automated code reviews on this repo. Configure here.