Skip to content

fix(logging): report the pay-as-you-go entry billing used on Azure PTU spillover - #47567

Merged
klu-berri merged 1 commit into
mainfrom
litellm_azure_ptu_spillover_logged_price
Oct 20, 2026
Merged

klu-berri merged 1 commit into
mainfrom
litellm_azure_ptu_spillover_logged_price

Conversation

@klu-berri

@klu-berri klu-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • get_standard_logging_object_payload now takes custom_pricing from Logging.custom_pricing_for(result)
  • That is the same helper billing already uses, so both see the x-ms-is-spilled-over header
  • _custom_pricing_for is renamed custom_pricing_for because the payload builder is a module-level function

User 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

  1. They configure gpt-4.1-ptu with ptu_count, cost_per_ptu_per_hour and input_cost_per_token: 0.0 in model_info, with LITELLM_ENABLE_PTU_COST_ATTRIBUTION=True
  2. They send POST http://localhost:4000/v1/chat/completions for gpt-4.1-ptu while Azure spills the request over to pay-as-you-go
  3. The response carries x-litellm-response-cost: 0.0006 and llm_provider-x-ms-is-spilled-over: true
  4. In http://localhost:4000/ui/?page=logs the request shows spend 0.0006, but its model_map_information says input_cost_per_token 0.0 and output_cost_per_token 0.0

After: the same request logs the rates that produced the spend

  1. Same config, same POST http://localhost:4000/v1/chat/completions for gpt-4.1-ptu during spillover
  2. The response still carries x-litellm-response-cost: 0.0006 and llm_provider-x-ms-is-spilled-over: true
  3. The log row shows spend 0.0006 with model_map_information at input_cost_per_token 0.000002 and output_cost_per_token 0.000008, so 100 x 0.000002 + 50 x 0.000008 = 0.0006

Relevant issues

Fixes a regression from #47182, which made model_map_information follow router_model_id into the deployment's own cost-map entry without following the PTU spillover switch billing applies to the same request

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / 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:9811 that returns a chat completion with prompt_tokens 100, completion_tokens 50 and the headers x-ms-is-spilled-over: true and x-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 differs

Shared setup:

model_list:
  - model_name: gpt-4.1-ptu
    litellm_params:
      model: azure/gpt-4.1
      api_base: http://127.0.0.1:9811
      api_key: fake
      api_version: "2024-10-21"
    model_info:
      id: ptu-gpt41-deployment
      base_model: azure/gpt-4.1
      ptu_count: 100
      cost_per_ptu_per_hour: 1.0
      ptu_effective_from: "2026-01-01"
      input_cost_per_token: 0.0
      output_cost_per_token: 0.0

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
LITELLM_ENABLE_PTU_COST_ATTRIBUTION=True LITELLM_LOCAL_MODEL_COST_MAP=True python litellm/proxy/proxy_cli.py --config ptu_config.yaml --detailed_debug

Before (5145250)

  1. Request
$ curl -s -D - http://localhost:4000/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"gpt-4.1-ptu","messages":[{"role":"user","content":"hi"}],"user":"spill"}'
x-litellm-call-id: 5e708ad4-24d8-4752-8ca1-58ad49817e68
x-litellm-response-cost: 0.0006
llm_provider-x-ms-is-spilled-over: true
llm_provider-x-ms-spillover-from-deployment: ptu-gpt41
{"id":"chatcmpl-fake-spill-1","created":1760000000,"model":"gpt-4.1-ptu","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"ok","role":"assistant"},"provider_specific_fields":{}}],"usage":{"completion_tokens":50,"prompt_tokens":100,"total_tokens":150}}
  1. Spend log row, billed 0.0006 but logged at the PTU $0 rates
$ psql "$DATABASE_URL" -c "select spend, metadata->'model_map_information'->'model_map_value'->>'input_cost_per_token' as logged_input_rate, metadata->'model_map_information'->'model_map_value'->>'output_cost_per_token' as logged_output_rate, metadata->'model_map_information'->>'model_map_key' as model_map_key, metadata->'azure_spillover' as azure_spillover, prompt_tokens, completion_tokens from \"LiteLLM_SpendLogs\" where request_id = 'chatcmpl-fake-spill-1';"
 spend  | logged_input_rate | logged_output_rate | model_map_key |         azure_spillover          | prompt_tokens | completion_tokens
--------+-------------------+--------------------+---------------+----------------------------------+---------------+-------------------
 0.0006 | 0.0               | 0.0                | azure/gpt-4.1 | {"from_deployment": "ptu-gpt41"} |           100 |                50
(1 row)

After (84c9a25)

  1. Request
$ curl -s -D - http://localhost:4000/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"gpt-4.1-ptu","messages":[{"role":"user","content":"hi"}],"user":"spill"}'
x-litellm-call-id: 6483edbf-d6ed-4113-a7f1-709042cd2601
x-litellm-response-cost: 0.0006
llm_provider-x-ms-is-spilled-over: true
llm_provider-x-ms-spillover-from-deployment: ptu-gpt41
{"id":"chatcmpl-fake-spill-8f23b972","created":1760000000,"model":"gpt-4.1-ptu","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"ok","role":"assistant"},"provider_specific_fields":{}}],"usage":{"completion_tokens":50,"prompt_tokens":100,"total_tokens":150}}
  1. Spend log row, billed 0.0006 and logged at the azure/gpt-4.1 rates that produce it (100 x 0.000002 + 50 x 0.000008)
$ psql "$DATABASE_URL" -c "select spend, metadata->'model_map_information'->'model_map_value'->>'input_cost_per_token' as logged_input_rate, metadata->'model_map_information'->'model_map_value'->>'output_cost_per_token' as logged_output_rate, metadata->'model_map_information'->>'model_map_key' as model_map_key, metadata->'azure_spillover' as azure_spillover, prompt_tokens, completion_tokens from \"LiteLLM_SpendLogs\" where request_id = 'chatcmpl-fake-spill-8f23b972';"
 spend  | logged_input_rate | logged_output_rate | model_map_key |         azure_spillover          | prompt_tokens | completion_tokens
--------+-------------------+--------------------+---------------+----------------------------------+---------------+-------------------
 0.0006 | 0.000002          | 0.000008           | azure/gpt-4.1 | {"from_deployment": "ptu-gpt41"} |           100 |                50
(1 row)

Regression test TestAzurePTUSpilloverCost::test_spillover_payload_reports_the_pay_as_you_go_entry_billing_used on the merge base (5145250), with the test file copied over:

FAILED tests/unit/litellm_core_utils/test_litellm_logging.py::TestAzurePTUSpilloverCost::test_spillover_payload_reports_the_pay_as_you_go_entry_billing_used
E       assert 0.0 == 2e-06
1 failed, 667 deselected, 10 warnings in 3.28s

Type

🐛 Bug Fix

Caveats (if any)

Low

  • model_map_key still reads azure/gpt-4.1 on both sides, only model_map_value changed
  • The proof upstream is scripted because Azure does not spill over on demand, the header handling it exercises is the shipped azure_spillover path

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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_information in spend logs still showed the deployment’s $0 PTU token rates (regression from #47182).

get_standard_logging_object_payload now derives custom_pricing from Logging.custom_pricing_for(result)—the same helper used for response_cost—so spillover (x-ms-is-spilled-over) switches logging to the standard cost-map entry instead of only reading deployment litellm_params. _custom_pricing_for is renamed custom_pricing_for so the module-level payload builder can call it.

Adds test_spillover_payload_reports_the_pay_as_you_go_entry_billing_used to 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.

…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
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed

codspeed Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 32 untouched benchmarks


Comparing litellm_azure_ptu_spillover_logged_price (84c9a25) with main (5145250)

Open in CodSpeed

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@klu-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

kerry-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

litellm-stampbot: risk low

Approved at 84c9a25.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Cursor Bugbot: Low Risk at 84c9a25. Scoped logging/cost-metadata alignment for PTU spillover; billing logic is reused rather than changed, with a targeted unit test. Bugbot run requested, finished in 4 min.
Bugbot Low is low, Medium and High are high. The judge model was not called.

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 kerry-berri added the risk:low Small, isolated, low-risk change label Oct 20, 2026

@kerry-berri kerry-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low risk by rule and by judgement at 84c9a25

@klu-berri
klu-berri merged commit 4222523 into main Oct 20, 2026
97 checks passed
@klu-berri
klu-berri deleted the litellm_azure_ptu_spillover_logged_price branch October 20, 2026 15:02
pamanseau pushed a commit to KubeTEE-AI/litellm that referenced this pull request Oct 25, 2026
…U spillover (BerriAI#47567)

Backport of BerriAI#47567 to stable/1.103.x

Cherry-picked from 4222523 (main)
Cartofante pushed a commit to CartoDB/litellm that referenced this pull request Oct 26, 2026
…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)
yuneng-berri pushed a commit that referenced this pull request Oct 28, 2026
…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)
haowang1013 pushed a commit to directivegames/litellm that referenced this pull request Nov 3, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Small, isolated, low-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants