Repository navigation
fix(proxy): price a billed failure row at the deployment's own rate like the success path - #47437
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
77b4f1a to
aa22488
Compare
…ike the success path
9ae4d8f to
f49a368
Compare
|
@litellm-stampbot |
litellm-stampbot: risk highNot approved at Rules (
Cursor Bugbot: Medium Risk at Pushes do not re-run this check. Comment |
|
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 f49a368. Configure here.
…ike the success path (BerriAI#47437) Backport of BerriAI#47437 to stable/1.103.x Cherry-picked from fb555b0 (main)
…ike the success path (BerriAI#47437) Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Backport of BerriAI#47437 to stable/1.106.x Cherry-picked from fb555b0 (main)
…ike the success path (BerriAI#47437) Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Backport of BerriAI#47437 to stable/1.105.x. Cherry-picked from fb555b0 (main).
TLDR
Problem this solves:
input_cost_per_tokenregistered under itsmodel_info.id) and, for an Azure deployment whose name is not in the cost map, at itsmodel_info.base_model; a failure row priced differently disagrees with the success row for the same prompt, or stays at $0 for an Azure aliasHow it solves it:
_failure_fields_to_liftresolves the deployment the way the success path does:Logging.get_router_model_id()for the deployment id (checkslitellm_metadatathenmetadata, tolerates theNonelitellm_metadatathatget_litellm_params()always writes) andget_base_model_from_metadataforbase_model_estimated_input_costpricesbase_model or modeland passescustom_cost_per_tokenfromdeployment_pricing_model_info(model_id, deployment_model), the same helper the success path'sget_router_deployment_model_infouses;Nonemeans the cost maplitellm_params, never from the flattenedmodel_call_detailscopy a request body key namedlitellm_paramscan overwriteThird PR of the LIT-145 stack; #47435, #47456 and #47436 are merged, so this one is on
main.User Flow
Before: a timed-out request on a deployment with its own rate is priced at the public rate
input_cost_per_token: 0.00001on thegpt-4.1deployment withtimeout: 1.5"model": "gpt-4.1"and a long promptAfter: the failure row uses the deployment's rate
prompt_tokens24 and $0.00024 spend (24 x 0.00001)Linear ticket
Resolves LIT-145
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/proxy/test_proxy_utils_model_creation_and_error_logging.py -v(146 passed)Screenshots / Proof of Fix
Real OpenAI, local proxy with Postgres. Same config and curl as the read-timeout PR, with the deployment's own rate added:
Before (origin/main 4bafebb, $0; with the first PR of the stack it would be 26 x 0.000002 = 5.2e-05)
After (run at this PR's tip f49a368)
spendis 24 x 0.00001 from the deployment, not the cost map's 0.000002:Unit tests cover the other sources: a deployment registered under its
model_info.idwith the realget_litellm_params()shape (test_the_deployment_rate_is_found_on_the_logging_objects_real_litellm_params), an Azure deployment priced at itsbase_model(test_an_azure_deployment_is_priced_at_its_base_model_like_the_success_path), and a request body{"litellm_params": {"input_cost_per_token": 0}}that cannot zero the price (test_a_litellm_params_key_in_the_request_body_cannot_zero_the_timeout_price).Type
🐛 Bug Fix
Caveats (if any)
Low
model_info.idand has nobase_model, keeps its failure row atspend0base_modelis read frommodel_call_details["litellm_params"]throughget_base_model_from_metadata, exactly as the success path reads it, so the two rows agree by constructionLink to Devin session: https://app.devin.ai/sessions/5070f71a202048649b9467fc681744c4
Open in Devin Desktop: https://app.devin.ai/desktop/session/5070f71a202048649b9467fc681744c4?variant=devin
Requested by: @kerrylu-berri
Note
Medium Risk
Changes proxy spend accounting for failed requests; logic is aligned with existing success-path pricing but affects reported spend and billing visibility.
Overview
Provider-billed failure rows (timeouts, client disconnects after dispatch) now use the same pricing rules as successful requests, instead of only the public cost map rate for the deployment model name.
_failure_fields_to_liftpassesLogging.get_router_model_id()andget_base_model_from_metadata()into the estimate path._estimated_input_costpricesbase_model or modeland suppliescustom_cost_per_tokenfrom a new_deployment_cost_per_tokenhelper (viadeployment_pricing_model_info). Deployment id is taken from the logging object’slitellm_params, not frommodel_call_detailswhere a request-bodylitellm_paramskey could overwrite it.Unit tests cover router-registered deployment rates, Azure aliases via
base_model, and the spoofed-body case.Reviewed by Cursor Bugbot for commit f49a368. Bugbot is set up for automated code reviews on this repo. Configure here.