Repository navigation
fix(proxy): price earlier timed-out retry attempts at their own deployment's model rate - #47648
Conversation
…loyment's model rate
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
|
@litellm-stampbot |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
litellm-stampbot: risk highNot approved at Rules (
Cursor Bugbot: Medium Risk at Pushes do not re-run this check. Comment |
|
bugbot run |
Merging this PR will not alter performance
|
|
@BugBot run |
… base_model helper as covered through log_retry
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 f578c6e. Configure here.
…yment's model rate (BerriAI#47648) * fix(proxy): bill every earlier timed-out retry attempt at its own deployment's model rate * fix(router): read the retry record's base_model through the typed metadata helper * fix(router): keep the four-record retry breadcrumb cap * fix(router): carry a deployment's litellm_params base_model on its retry record * chore(router): place the cast-ok reason on the cast line and list the base_model helper as covered through log_retry --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Backport of BerriAI#47648 to stable/1.106.x Cherry-picked from 27efc38 (main)
…yment's model rate (#47648) * fix(proxy): bill every earlier timed-out retry attempt at its own deployment's model rate * fix(router): read the retry record's base_model through the typed metadata helper * fix(router): keep the four-record retry breadcrumb cap * fix(router): carry a deployment's litellm_params base_model on its retry record * chore(router): place the cast-ok reason on the cast line and list the base_model helper as covered through log_retry --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 27efc38)
…yment's model rate (BerriAI#47648) * fix(proxy): bill every earlier timed-out retry attempt at its own deployment's model rate * fix(router): read the retry record's base_model through the typed metadata helper * fix(router): keep the four-record retry breadcrumb cap * fix(router): carry a deployment's litellm_params base_model on its retry record * chore(router): place the cast-ok reason on the cast line and list the base_model helper as covered through log_retry --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Backport of BerriAI#47648 to stable/1.105.x. Cherry-picked from 27efc38 (main).
When a request times out on its first model group and the fallback group times out too, the proxy writes one spend row per attempt the provider billed. Since #47490 the rows for the first group's attempts were priced at the final group's model rate, so a gpt-5.4-mini attempt was billed as gpt-5.4. Each earlier attempt is now priced at the model that actually served it
Details
TLDR
Problem this solves:
How it solves it:
modelandbase_model(frommodel_infoorlitellm_params)git stash push -- litellm/the three new or changed tests fail, with the fix they passThe router still keeps the last 4 retry records per request, so only those earlier attempts get rows, same as before this PR
User Flow
Before: a developer whose
timeout-minigroup (gpt-5.4-mini) falls back to gpt-5.4 sees the gpt-5.4-mini attempt billed at gpt-5.4's rate"model": "timeout-mini", every attempt times out after 1s, and they get a 408 after 9sAfter: the same request bills the gpt-5.4-mini attempt at gpt-5.4-mini's rate
"model": "timeout-mini"and get the same 408 after 9sAffected release
regression since #47490
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
Live proxy started from the checkout with
python litellm/proxy/proxy_cli.py --config ~/lit145/config.yaml --detailed_debug --port 4000, a local Postgres 16database_url, and real OpenAI calls. Every attempt is cut by the 1stimeout, so each attempt is a real provider call that OpenAI bills for the promptConfig (
~/lit145/config.yaml):Rates from the cost map: gpt-5.4 input 2.5e-06 per token (28 tokens = 7e-05), gpt-5.4-mini input 7.5e-07 per token (28 tokens = 2.1e-05). The request makes 2 attempts on dep-mini then 2 on dep-fb-big. The router keeps the last 4 retry records and the fallback handler re-logs the attempt that exhausted the first group, so the surviving earlier attempts are dep-mini retry 1 and dep-fb-big retry 0, and the request's own failure row bills the last dep-fb-big attempt
Spend rows read with:
Before (5c341e7)
After (3b7504f)
Type
🐛 Bug Fix
Caveats (if any)
Medium
model_idandattempted_retries(dep-mini / 1 above) while billing the last fallback attempt. Pre-existing, same on main, not touched hereLow
modelhas no provider prefix and is not a known model name is billed $0 and debug-logged, the same as the final row for such a deploymentFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/a1707ff54b964dc6b83086ab5a47ab56
Open in Devin Desktop: https://app.devin.ai/desktop/session/a1707ff54b964dc6b83086ab5a47ab56?variant=devin
Requested by: @kerrylu-berri
Note
Medium Risk
Changes proxy spend accounting for multi-hop retries and fallbacks; incorrect pricing would affect billing visibility but not request routing or auth.
Overview
Fixes a spend-log regression where earlier timed-out retry attempts were priced at the final model’s input rate after router fallbacks (e.g. a mini model attempt billed like the larger fallback model).
Router retry breadcrumbs now store each failed hop’s deployment
modelandbase_modelonRetryAttemptRecord(log_retry), including Azurebase_modelfrom deploymentlitellm_paramswhen it isn’t on metadata. Proxy failure billing uses new_record_pricing/_billed_earlier_attempthelpers so each earlier timeout row is costed from that record’s model andbase_model, not from the final attempt’smodel_call_details.Unit tests cover cross-model fallback pricing and
log_retryfield population.Reviewed by Cursor Bugbot for commit f578c6e. Bugbot is set up for automated code reviews on this repo. Configure here.