Repository navigation
fix(logging): report the pay-as-you-go entry billing used on Azure PTU spillover - #47567
Conversation
…U spillover get_standard_logging_object_payload decided custom_pricing from litellm_params alone, so on an Azure PTU spillover response model_map_information kept the deployment's zeroed PTU entry while response_cost already used the standard model rate. Reuse the billing side LitellmLogging._custom_pricing_for so both read the same decision
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
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 |
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 84c9a25. Configure here.
kerry-berri
left a comment
There was a problem hiding this comment.
Low risk by rule and by judgement at 84c9a25
…U spillover (BerriAI#47567) Backport of BerriAI#47567 to stable/1.103.x Cherry-picked from 4222523 (main)
…U spillover (BerriAI#47567) get_standard_logging_object_payload decided custom_pricing from litellm_params alone, so on an Azure PTU spillover response model_map_information kept the deployment's zeroed PTU entry while response_cost already used the standard model rate. Reuse the billing side LitellmLogging._custom_pricing_for so both read the same decision Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Backport of BerriAI#47567 to stable/1.106.x Cherry-picked from 4222523 (main)
…U spillover (#47567) get_standard_logging_object_payload decided custom_pricing from litellm_params alone, so on an Azure PTU spillover response model_map_information kept the deployment's zeroed PTU entry while response_cost already used the standard model rate. Reuse the billing side LitellmLogging._custom_pricing_for so both read the same decision Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 4222523)
…U spillover (BerriAI#47567) get_standard_logging_object_payload decided custom_pricing from litellm_params alone, so on an Azure PTU spillover response model_map_information kept the deployment's zeroed PTU entry while response_cost already used the standard model rate. Reuse the billing side LitellmLogging._custom_pricing_for so both read the same decision Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Backport of BerriAI#47567 to stable/1.105.x. Cherry-picked from 4222523 (main).
TLDR
Problem this solves:
response_costbills the standard rate,model_map_informationlogs the PTU $0 rateHow it solves it:
get_standard_logging_object_payloadnow takescustom_pricingfromLogging.custom_pricing_for(result)x-ms-is-spilled-overheader_custom_pricing_foris renamedcustom_pricing_forbecause the payload builder is a module-level functionUser Flow
Before: a proxy admin running a $0-per-token Azure PTU deployment sees a spillover request billed at the standard rate but logged at $0 rates
gpt-4.1-ptuwithptu_count,cost_per_ptu_per_hourandinput_cost_per_token: 0.0inmodel_info, withLITELLM_ENABLE_PTU_COST_ATTRIBUTION=Truegpt-4.1-ptuwhile Azure spills the request over to pay-as-you-gox-litellm-response-cost: 0.0006andllm_provider-x-ms-is-spilled-over: truespend0.0006, but itsmodel_map_informationsaysinput_cost_per_token0.0 andoutput_cost_per_token0.0After: the same request logs the rates that produced the spend
gpt-4.1-ptuduring spilloverx-litellm-response-cost: 0.0006andllm_provider-x-ms-is-spilled-over: truespend0.0006 withmodel_map_informationatinput_cost_per_token0.000002 andoutput_cost_per_token0.000008, so 100 x 0.000002 + 50 x 0.000008 = 0.0006Relevant issues
Fixes a regression from #47182, which made
model_map_informationfollowrouter_model_idinto the deployment's own cost-map entry without following the PTU spillover switch billing applies to the same requestPre-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
Real Azure PTU spillover cannot be triggered on demand (Azure decides when a PTU deployment spills over), so the upstream here is a scripted local Azure-shaped server on
http://127.0.0.1:9811that returns a chat completion withprompt_tokens100,completion_tokens50 and the headersx-ms-is-spilled-over: trueandx-ms-spillover-from-deployment: ptu-gpt41. Everything after that header is the real proxy with local Postgres. Same config, same request and same DB query on both sides, only the checkout differsShared setup:
Before (5145250)
After (84c9a25)
Regression test
TestAzurePTUSpilloverCost::test_spillover_payload_reports_the_pay_as_you_go_entry_billing_usedon the merge base (5145250), with the test file copied over:Type
🐛 Bug Fix
Caveats (if any)
Low
model_map_keystill readsazure/gpt-4.1on both sides, onlymodel_map_valuechangedazure_spilloverpathFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/677fc12fc9c448328b4baed75c10dd83
Open in Devin Desktop: https://app.devin.ai/desktop/session/677fc12fc9c448328b4baed75c10dd83?variant=devin
Requested by: @kerrylu-berri
Note
Low Risk
Scoped logging/cost-metadata alignment for PTU spillover; billing logic is reused rather than changed, with a targeted unit test.
Overview
Fixes a mismatch where Azure PTU spillover requests were billed at pay-as-you-go rates but
model_map_informationin spend logs still showed the deployment’s $0 PTU token rates (regression from #47182).get_standard_logging_object_payloadnow derivescustom_pricingfromLogging.custom_pricing_for(result)—the same helper used forresponse_cost—so spillover (x-ms-is-spilled-over) switches logging to the standard cost-map entry instead of only reading deploymentlitellm_params._custom_pricing_foris renamedcustom_pricing_forso the module-level payload builder can call it.Adds
test_spillover_payload_reports_the_pay_as_you_go_entry_billing_usedto assert logged input/output rates match the billed spillover cost.Reviewed by Cursor Bugbot for commit 84c9a25. Bugbot is set up for automated code reviews on this repo. Configure here.