Skip to content

feat(cost): warn and count $0 cost on billable requests - #42345

Merged
mateo-berri merged 11 commits into
mainfrom
litellm_zero_cost_warning_counter
Sep 22, 2026
Merged

mateo-berri merged 11 commits into
mainfrom
litellm_zero_cost_warning_counter

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • A billable request that prices to $0 is written to spend logs as truth
  • Nothing warns, nothing counts it, so a missing pricing key goes unnoticed for weeks
  • Free models and requests without usage look identical to the mispriced ones

How it solves it:

  • One warning per request naming the model, the pricing entry, and the missing rate
  • New counter litellm_zero_cost_requests_total{requested_model, model, model_id, api_provider, reason}
  • Reasons: missing_pricing_key, pricing_not_applied, cost_calculation_error
  • Free models (every used rate is 0), no-usage requests, unmapped models stay silent
  • The diagnostic rides on the standard logging payload (zero_cost_diagnostic), Grafana panel added

User Flow

Before

The operator only finds out days later, from $0 spend rows on a priced deployment, that a pricing key was missing, and nothing in the logs or metrics pointed at it

  1. The operator adds a deployment per-second-priced-chat (openai/gpt-5.4-nano with input_cost_per_second and output_cost_per_second set, no per-token rate), a deployment free-chat (same model, input_cost_per_token: 0 and output_cost_per_token: 0 in model_info) and a plain gpt-5.4-nano deployment to the proxy config, turns on the prometheus callback and boots the proxy
  2. A user sends POST https://litellm-domain/v1/chat/completions with {"model": "per-second-priced-chat", "messages": [{"role": "user", "content": "Say hi in three words"}]} and gets a 200 whose body carries usage.prompt_tokens: 11 and usage.completion_tokens: 7, with x-litellm-response-cost-input: 0.0 and x-litellm-response-cost-output: 0.0 in the headers
  3. The user sends the same request with "stream": true and "stream_options": {"include_usage": true} and the final chunk carries the same kind of usage, again priced at $0
  4. The user repeats both requests against free-chat and against gpt-5.4-nano: the free-chat responses are $0 too, the gpt-5.4-nano ones carry x-litellm-response-cost: 1.22e-05
  5. The operator opens https://litellm-domain/ui/?page=logs: the per-second-priced-chat rows show spend $0 next to 11 prompt and 7 completion tokens, indistinguishable from the free-chat rows, and only gpt-5.4-nano shows a non-zero spend
  6. The operator greps the proxy log for WARNING or ERROR and finds nothing about any of these requests
  7. The operator scrapes GET https://litellm-domain/metrics/ with the admin key and finds no series about zero-cost requests, so nothing can be alerted on and the $0 rows go into the bill as truth

After

The $0 request on the per-second deployment now logs one warning naming the deployment and the two missing per-token rates and shows up in litellm_zero_cost_requests_total, while free-chat and gpt-5.4-nano stay silent

  1. The operator adds a deployment per-second-priced-chat (openai/gpt-5.4-nano with input_cost_per_second and output_cost_per_second set, no per-token rate), a deployment free-chat (same model, input_cost_per_token: 0 and output_cost_per_token: 0 in model_info) and a plain gpt-5.4-nano deployment to the proxy config, turns on the prometheus callback and boots the proxy
  2. A user sends POST https://litellm-domain/v1/chat/completions with {"model": "per-second-priced-chat", "messages": [{"role": "user", "content": "Say hi in three words"}]} and gets a 200 whose body carries usage.prompt_tokens: 11 and usage.completion_tokens: 7, with x-litellm-response-cost-input: 0.0 and x-litellm-response-cost-output: 0.0 in the headers
  3. The user sends the same request with "stream": true and "stream_options": {"include_usage": true} and the final chunk carries the same kind of usage, again priced at $0
  4. The user repeats both requests against free-chat and against gpt-5.4-nano: the free-chat responses are $0 too, the gpt-5.4-nano ones carry x-litellm-response-cost: 1.22e-05
  5. The operator opens https://litellm-domain/ui/?page=logs: the per-second-priced-chat rows still show spend $0 next to 11 prompt and 7 completion tokens, since this change flags the $0 instead of repricing it
  6. The operator greps the proxy log for WARNING and finds exactly one line per per-second-priced-chat request, Billable request priced at $0 and logged as such (model_group=per-second-priced-chat model=openai/gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=7): pricing entry '<deployment id>' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}, and no such line for free-chat or gpt-5.4-nano
  7. The operator scrapes GET https://litellm-domain/metrics/ with the admin key and finds litellm_zero_cost_requests_total{api_provider="openai",model="openai/gpt-5.4-nano",model_id="<deployment id>",reason="missing_pricing_key",requested_model="per-second-priced-chat"} 2.0, one count per request, and no series for free-chat or gpt-5.4-nano, so the missing rate can be alerted on the day it starts costing money

Relevant issues

Docs: BerriAI/litellm-docs#1608

Affected release

Linear ticket

Resolves LIT-7898

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/test_litellm/<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
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Both legs run the same flow against the same topology and differ only in the commit the proxy is booted from: a fresh Postgres database per leg, --num_workers 2, the prometheus callback, real OpenAI calls, and this config (the four deployments the User Flow names plus the published gpt-5-nano as the priced control)

model_list:
  - model_name: gpt-5.4-nano
    litellm_params:
      model: openai/gpt-5.4-nano
      api_key: os.environ/OPENAI_API_KEY
  - model_name: per-second-priced-chat
    litellm_params:
      model: openai/gpt-5.4-nano
      api_key: os.environ/OPENAI_API_KEY
      input_cost_per_second: 0.000420
      output_cost_per_second: 0.000420
  - model_name: free-chat
    litellm_params:
      model: openai/gpt-5.4-nano
      api_key: os.environ/OPENAI_API_KEY
    model_info:
      input_cost_per_token: 0
      output_cost_per_token: 0
  - model_name: gpt-5-nano
    litellm_params:
      model: openai/gpt-5-nano
      api_key: os.environ/OPENAI_API_KEY

litellm_settings:
  callbacks: ["prometheus"]

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  store_model_in_db: false

The proxy reads its cost map from LITELLM_MODEL_COST_MAP_URL, a locally served copy of model_prices_and_context_window.json where gpt-5.4-nano and gpt-5.4-nano-2026-03-17 had input_cost_per_token and output_cost_per_token removed with their audio rates kept, so the run also covers a published entry that lost its per-token rate. That makes plain gpt-5.4-nano a second $0 deployment here rather than the priced control the User Flow describes, and gpt-5-nano (published rates untouched) plays that priced control instead. PROMETHEUS_MULTIPROC_DIR is set so /metrics/ aggregates both workers

Rates the proxy resolved per deployment, identical on both legs (/model/info, reduced to the relevant keys)

curl -s -H "Authorization: Bearer $LITELLM_MASTER_KEY" http://localhost:$PORT/model/info | python3 -c 'import json,sys
for m in json.load(sys.stdin)["data"]:
    print(m["model_name"], "|", {k: m["model_info"].get(k) for k in ("input_cost_per_token","output_cost_per_token","input_cost_per_audio_token","input_cost_per_second")})'
gpt-5.4-nano | {'input_cost_per_token': None, 'output_cost_per_token': None, 'input_cost_per_audio_token': 1e-05, 'input_cost_per_second': None}
per-second-priced-chat | {'input_cost_per_token': None, 'output_cost_per_token': None, 'input_cost_per_audio_token': 1e-05, 'input_cost_per_second': 0.00042}
free-chat | {'input_cost_per_token': 0.0, 'output_cost_per_token': 0.0, 'input_cost_per_audio_token': 1e-05, 'input_cost_per_second': None}
gpt-5-nano | {'input_cost_per_token': 5e-08, 'output_cost_per_token': 4e-07, 'input_cost_per_audio_token': None, 'input_cost_per_second': None}

Before (1baa26d)

Proxy booted from 1baa26d36b on port 27790 with --num_workers 2

/v1/chat/completions

  1. non-streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:27790/v1/chat/completions \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "messages": [{"role": "user", "content": "Say hi in three words"}]}'
done
# model=gpt-5.4-nano
x-litellm-call-id: 1cb43601-ebc9-4fe2-bf0d-95ec3951aea2
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"completion_tokens":8,"prompt_tokens":11,"total_tokens":19,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0}
# model=gpt-5-nano
x-litellm-call-id: 62a49bc4-3c72-42b2-bb4c-b99d32ddb1e3
x-litellm-response-cost: 0.00031255
x-litellm-response-cost-input: 5.5e-07
x-litellm-response-cost-output: 0.000312
usage={"completion_tokens":780,"prompt_tokens":11,"total_tokens":791,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":768,"rejected_prediction_tokens":0}
# model=per-second-priced-chat
x-litellm-call-id: 9fa4804a-5915-4214-988a-128cf4557d89
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"completion_tokens":9,"prompt_tokens":11,"total_tokens":20,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0}
# model=free-chat
x-litellm-call-id: 6a01adfb-d7fe-4c4b-a0d4-e57fc6df441a
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"completion_tokens":6,"prompt_tokens":11,"total_tokens":17,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0}
  1. streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:27790/v1/chat/completions \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "messages": [{"role": "user", "content": "Say hi in three words"}], "stream": true, "stream_options": {"include_usage": true}}'
done
# model=gpt-5.4-nano
x-litellm-call-id: e4543743-f3eb-43d9-82a9-b7707fcccec4
usage={"completion_tokens":7,"prompt_tokens":11,"total_tokens":18}
# model=gpt-5-nano
x-litellm-call-id: 831094df-e643-46e8-a007-6c68e8474de5
usage={"completion_tokens":398,"prompt_tokens":11,"total_tokens":409}
# model=per-second-priced-chat
x-litellm-call-id: 9048a94b-cadf-4c21-8f84-bad0bc762ae8
usage={"completion_tokens":7,"prompt_tokens":11,"total_tokens":18}
# model=free-chat
x-litellm-call-id: f20345d5-2ccb-4250-ba95-5636d1f23c47
usage={"completion_tokens":6,"prompt_tokens":11,"total_tokens":17}

/v1/messages

  1. non-streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:27790/v1/messages \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}'
done
# model=gpt-5.4-nano
x-litellm-call-id: cef34355-61bc-46e3-a3c1-f4fa3b999278
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":9}
# model=gpt-5-nano
x-litellm-call-id: cf1b9c04-f852-4a4e-9bb1-0d68ae64c1dc
x-litellm-response-cost: 5.5e-07
x-litellm-response-cost-input: 5.5e-07
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":0}
# model=per-second-priced-chat
x-litellm-call-id: bbf625d9-650b-4344-9f19-930dc354556c
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":8}
# model=free-chat
x-litellm-call-id: a6e70307-9cc4-438b-9027-c94fa2baa0b1
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":9}
  1. streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:27790/v1/messages \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}], "stream": true}'
done
# model=gpt-5.4-nano
x-litellm-call-id: a125a5ed-0b17-441b-aaee-d8c50ffdb046
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null}, "usage": {"input_tokens": 11, "output_tokens": 7}}
# model=gpt-5-nano
x-litellm-call-id: 2997ab31-5793-4e8d-b9d6-5e1431d7b6f2
data: {"type": "message_delta", "delta": {"stop_reason": "max_tokens", "stop_sequence": null}, "usage": {"input_tokens": 11, "output_tokens": 0}}
# model=per-second-priced-chat
x-litellm-call-id: 0cadc094-0f64-476f-8872-f6a68dbcb106
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null}, "usage": {"input_tokens": 11, "output_tokens": 7}}
# model=free-chat
x-litellm-call-id: d6e77dc0-2073-4a47-8be2-1045a9f9670e
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null}, "usage": {"input_tokens": 11, "output_tokens": 7}}

/v1/responses

  1. non-streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:27790/v1/responses \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "input": "Say hi in three words"}'
done
# model=gpt-5.4-nano
x-litellm-call-id: d746a895-cb7f-494b-ba72-5fb3d65169f2
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":0}
# model=gpt-5-nano
x-litellm-call-id: f04b4ca0-4b78-4d53-90d0-5e434b244718
x-litellm-response-cost: 0.0003501499999999999
x-litellm-response-cost-input: 5.5e-07
x-litellm-response-cost-output: 0.00034959999999999993
usage={"input_tokens":11,"output_tokens":0}
# model=per-second-priced-chat
x-litellm-call-id: 84f0496d-72f5-45d6-ac6d-e0812f7c09f2
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":0}
# model=free-chat
x-litellm-call-id: 7da783d9-44d7-4bf3-ba25-6c863cbf003f
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":0}
  1. streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:27790/v1/responses \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "input": "Say hi in three words", "stream": true}'
done
# model=gpt-5.4-nano
x-litellm-call-id: 4925e804-714c-4522-9f9f-791e22b85ce5
usage={"input_tokens":11,"output_tokens":0}
# model=gpt-5-nano
x-litellm-call-id: 3d2a9c0c-dd46-4621-9c72-07f209698c9e
usage={"input_tokens":11,"output_tokens":0}
# model=per-second-priced-chat
x-litellm-call-id: 4c0ec6fe-7e43-4aaf-a5e2-18899d45c114
usage={"input_tokens":11,"output_tokens":0}
# model=free-chat
x-litellm-call-id: 077b7e74-6b36-4a4b-b07a-863f97c2cd31
usage={"input_tokens":11,"output_tokens":0}

Spend logs

  1. every $0 row is still written as $0 on both legs (this PR flags, it does not reprice)
curl -s -H "Authorization: Bearer $LITELLM_MASTER_KEY" "http://localhost:27790/spend/logs?start_date=2026-09-21&end_date=2026-09-22&summarize=false" \
  | python3 -c 'import json,sys
for r in sorted(json.load(sys.stdin), key=lambda r: r["startTime"]):
    print(r["model_group"], "|", r["call_type"], "|", "spend=%s" % r["spend"], "|", "prompt_tokens=%s" % r["prompt_tokens"], "|", "completion_tokens=%s" % r["completion_tokens"], "|", r["request_id"][:40])'
gpt-5.4-nano | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | chatcmpl-EQhptC00RYqU7q6LURoaXpbPGOeDd
gpt-5.4-nano | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | chatcmpl-EQhpvDNLnGqbay8axo3JZzad9gcnu
gpt-5.4-nano | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
gpt-5.4-nano | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | msg_dec83c9f-dd82-4bd8-b03e-baa025c6d94b
gpt-5.4-nano | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | resp_sZGTrdgqoC0s5uzc0pU3h7DVzFjb6hkdVHn
gpt-5.4-nano | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
gpt-5-nano | acompletion | spend=0.00031255 | prompt_tokens=11 | completion_tokens=780 | chatcmpl-EQhpyL1SeqbHO4HBic8I5wtKvAjls
gpt-5-nano | acompletion | spend=0.00015975 | prompt_tokens=11 | completion_tokens=398 | chatcmpl-EQhq2q9glRguWK8NPJb6cvPnExbEt
gpt-5-nano | anthropic_messages | spend=5.5e-07 | prompt_tokens=11 | completion_tokens=0 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
gpt-5-nano | anthropic_messages | spend=5.5e-07 | prompt_tokens=11 | completion_tokens=0 | msg_3dce5332-91dd-4d23-b3c4-461bb57e788b
gpt-5-nano | aresponses | spend=0.0003501499999999999 | prompt_tokens=11 | completion_tokens=874 | resp_fYIY1sjsfXa_Qjw-xf5SXoycOvdzBC9tiP5
gpt-5-nano | aresponses | spend=0.00031135 | prompt_tokens=11 | completion_tokens=777 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
per-second-priced-chat | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | chatcmpl-EQhqJORZVAKKecRLcdMX8hxo8O0eg
per-second-priced-chat | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | chatcmpl-EQhqKaRxMI7ob5d7uUyG0Yl3bp7Xb
per-second-priced-chat | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
per-second-priced-chat | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | msg_e97f5c47-a947-48fb-9d18-6fcb2315d6b5
per-second-priced-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_ly14AG53EXnoasUx-XsRSs8djaStNup-9rV
per-second-priced-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
free-chat | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=6 | chatcmpl-EQhqOBfK9JNUKCn7NmMxmwwjOEaKZ
free-chat | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=6 | chatcmpl-EQhqOcBPFTcjgBYvBRkXqA4ANQAQs
free-chat | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
free-chat | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | msg_561f0cbf-8fae-4526-9f9b-93d139b51e06
free-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_MNFfJqSMDWd1HJMc10US_gXOlTEuvoLoqmX
free-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV

Metrics

  1. the zero-cost counter series
curl -s -H "Authorization: Bearer $LITELLM_MASTER_KEY" http://localhost:27790/metrics/ | grep -E '^litellm_zero_cost_requests_total'
(no output: the series does not exist at 1baa26d36b)
  1. the spend counter per requested model, reduced to that label (litellm_spend_metric_total is split per service tier, so two series per deployment)
curl -s -H "Authorization: Bearer $LITELLM_MASTER_KEY" http://localhost:27790/metrics/ | grep -E '^litellm_spend_metric_total' \
  | sed -E 's/^litellm_spend_metric_total\{.*(requested_model="[^"]*").*\} /litellm_spend_metric_total{\1} /' | sort
litellm_spend_metric_total{requested_model="free-chat"} 0.0
litellm_spend_metric_total{requested_model="free-chat"} 0.0
litellm_spend_metric_total{requested_model="gpt-5-nano"} 0.00015975
litellm_spend_metric_total{requested_model="gpt-5-nano"} 0.0009751499999999998
litellm_spend_metric_total{requested_model="gpt-5.4-nano"} 0.0
litellm_spend_metric_total{requested_model="gpt-5.4-nano"} 0.0
litellm_spend_metric_total{requested_model="per-second-priced-chat"} 0.0
litellm_spend_metric_total{requested_model="per-second-priced-chat"} 0.0

Proxy log

  1. warnings about $0 requests (timestamps and logger prefix trimmed)
grep -c 'priced at \$0' proxy.log; grep 'priced at \$0' proxy.log | sed -E 's/^.*litellm_logging\.py:[0-9]+ - //'
0

After (fb9c202)

The litellm/ tree of fb9c2020dd is byte-identical to 4088ac4982, which touches only tests/test_litellm/. The tip 95266607bc is that tree plus the merge of main at ccafff8b68 (bringing #42385, which prices a terminal Responses stream event by its inner response; _response_cost_calculator hands that same priced_result to the diagnostic, so it judges what the calculator priced), a regression test for that routing at 2fccf559df, and the generated OpenAPI snapshot restored at 95266607bc. The one cell of this run the merge can change is /v1/responses streaming, where the completed event now carries usage into the diagnostic: test_terminal_responses_stream_event_is_judged_by_its_inner_response covers it for the per-second and free deployments and fails when the diagnostic is handed the event wrapper instead, and CircleCI's integration-cost job at ccafff8b68 (483 tests, 0 failures, 12 of them Responses API cases against the live provider through the proxy) shows the priced path unchanged. The /v1/responses at 95266607bc block below re-runs that surface live at the tip

Proxy booted from fb9c2020dd on port 46283 with --num_workers 2

/v1/chat/completions

  1. non-streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:46283/v1/chat/completions \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "messages": [{"role": "user", "content": "Say hi in three words"}]}'
done
# model=gpt-5.4-nano
x-litellm-call-id: 4654d998-fcc9-41ba-99b1-138ddb99ab25
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"completion_tokens":8,"prompt_tokens":11,"total_tokens":19,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0}
# model=gpt-5-nano
x-litellm-call-id: a2dd9b24-a6e4-4909-a200-0f619c5a98b3
x-litellm-response-cost: 0.00026175
x-litellm-response-cost-input: 5.5e-07
x-litellm-response-cost-output: 0.0002612
usage={"completion_tokens":653,"prompt_tokens":11,"total_tokens":664,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":640,"rejected_prediction_tokens":0}
# model=per-second-priced-chat
x-litellm-call-id: 13299fb1-b394-4b90-93cc-01756e3b1313
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"completion_tokens":6,"prompt_tokens":11,"total_tokens":17,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0}
# model=free-chat
x-litellm-call-id: c9039e1c-0281-4413-863d-8f16cf3822cd
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"completion_tokens":9,"prompt_tokens":11,"total_tokens":20,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0}
  1. streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:46283/v1/chat/completions \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "messages": [{"role": "user", "content": "Say hi in three words"}], "stream": true, "stream_options": {"include_usage": true}}'
done
# model=gpt-5.4-nano
x-litellm-call-id: 0045b295-aa18-4cf8-9bf2-1ed3f9b8c9e0
usage={"completion_tokens":8,"prompt_tokens":11,"total_tokens":19}
# model=gpt-5-nano
x-litellm-call-id: 4df2c91b-6d06-4ba9-bf4b-4e06acb2c405
usage={"completion_tokens":525,"prompt_tokens":11,"total_tokens":536}
# model=per-second-priced-chat
x-litellm-call-id: a2897f86-8af3-4180-af08-237bd6a136e8
usage={"completion_tokens":7,"prompt_tokens":11,"total_tokens":18}
# model=free-chat
x-litellm-call-id: 2aa9b018-3c7a-4b31-bc67-b4332c400c0e
usage={"completion_tokens":8,"prompt_tokens":11,"total_tokens":19}

/v1/messages

  1. non-streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:46283/v1/messages \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}'
done
# model=gpt-5.4-nano
x-litellm-call-id: 873edb7d-fa41-4ecc-abac-8578db548500
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":8}
# model=gpt-5-nano
x-litellm-call-id: 2275bf20-80db-41b2-9408-743d3ced9f88
x-litellm-response-cost: 5.5e-07
x-litellm-response-cost-input: 5.5e-07
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":0}
# model=per-second-priced-chat
x-litellm-call-id: 2a8399ed-c952-4b42-8ace-9ee9302bb130
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":10}
# model=free-chat
x-litellm-call-id: 138259fc-167a-4546-b28a-abe8cf2679dc
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":8}
  1. streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:46283/v1/messages \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}], "stream": true}'
done
# model=gpt-5.4-nano
x-litellm-call-id: 0a15c089-81e4-4ee8-a5bc-86bd2b153199
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null}, "usage": {"input_tokens": 11, "output_tokens": 9}}
# model=gpt-5-nano
x-litellm-call-id: 51b7db1f-b572-4463-b0f9-e7ad433f26a0
data: {"type": "message_delta", "delta": {"stop_reason": "max_tokens", "stop_sequence": null}, "usage": {"input_tokens": 11, "output_tokens": 0}}
# model=per-second-priced-chat
x-litellm-call-id: dae2f946-ef1c-4551-b56c-fdc7c58d2e46
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null}, "usage": {"input_tokens": 11, "output_tokens": 9}}
# model=free-chat
x-litellm-call-id: 88c787bc-339b-4742-a101-08d5b2763923
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null}, "usage": {"input_tokens": 11, "output_tokens": 10}}

/v1/responses

  1. non-streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:46283/v1/responses \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "input": "Say hi in three words"}'
done
# model=gpt-5.4-nano
x-litellm-call-id: f445c87c-c6db-4967-b395-1827763872e5
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":0}
# model=gpt-5-nano
x-litellm-call-id: 9b70f72a-3148-4ec1-9011-10632a9c978f
x-litellm-response-cost: 0.00023455
x-litellm-response-cost-input: 5.5e-07
x-litellm-response-cost-output: 0.000234
usage={"input_tokens":11,"output_tokens":0}
# model=per-second-priced-chat
x-litellm-call-id: 5de41f37-bd24-4425-a22a-2bba8ec7dfdb
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":0}
# model=free-chat
x-litellm-call-id: d48cc04b-5a6a-40fd-9c5e-356e32018acd
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
usage={"input_tokens":11,"output_tokens":0}
  1. streaming, one request per deployment (output filtered to the x-litellm-* headers and the usage object)
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:46283/v1/responses \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "input": "Say hi in three words", "stream": true}'
done
# model=gpt-5.4-nano
x-litellm-call-id: 0a197b35-dd1d-43ee-9e89-2a7a4ecf992d
usage={"input_tokens":11,"output_tokens":0}
# model=gpt-5-nano
x-litellm-call-id: f44b6db8-ad78-4114-87c4-56ce58ec499e
usage={"input_tokens":11,"output_tokens":0}
# model=per-second-priced-chat
x-litellm-call-id: ac389847-090d-408c-8e64-a05f53f0f278
usage={"input_tokens":11,"output_tokens":0}
# model=free-chat
x-litellm-call-id: aa9bbac0-7174-40e7-80d7-bcf6e11a2552
usage={"input_tokens":11,"output_tokens":0}

/v1/responses at 9526660

Same config, cost map, and prompt as above, against a proxy booted from the tip 95266607bc on port 36318 with --num_workers 1 and a fresh spend database, so the merge of #42385's terminal-event routing is proven on the wire and not only by its unit test. Output filtered to the x-litellm-* headers; the usage line is dropped here because the display filter above mis-captures output_tokens (it prints 0 for every call), and the spend rows below carry the token counts the proxy logged

  1. non-streaming and streaming, one request each per deployment
for model in gpt-5.4-nano gpt-5-nano per-second-priced-chat free-chat; do
  curl -s -D - http://localhost:36318/v1/responses \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "input": "Say hi in three words"}'
  curl -s -D - http://localhost:36318/v1/responses \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d '{"model": "'"$model"'", "input": "Say hi in three words", "stream": true}'
done
# model=gpt-5.4-nano stream=false
x-litellm-call-id: 4d88c6f9-ea4c-46b4-8860-80bf28d2ab50
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
# model=gpt-5.4-nano stream=true
x-litellm-call-id: af1e4b0d-775c-4bd6-88c2-2225ee04f5fe
# model=gpt-5-nano stream=false
x-litellm-call-id: cbb3d523-f0f1-40d3-897f-bb38ab48e569
x-litellm-response-cost: 0.00021495
x-litellm-response-cost-input: 5.5e-07
x-litellm-response-cost-output: 0.00021439999999999998
# model=gpt-5-nano stream=true
x-litellm-call-id: 01bc70fb-d3da-4b40-bd05-bb4e1e4bf68e
# model=per-second-priced-chat stream=false
x-litellm-call-id: 23dfd63f-3af3-4088-97c6-09aea71cf8ce
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
# model=per-second-priced-chat stream=true
x-litellm-call-id: 3130cee7-568e-49e1-9370-0b6592d336ab
# model=free-chat stream=false
x-litellm-call-id: d1ec0142-8bcb-4ac0-927c-3fa1b0936c4e
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
# model=free-chat stream=true
x-litellm-call-id: be2e76b9-9a57-4dde-a15e-46f2bf70b95c
  1. spend rows (GET /spend/logs?start_date=<today>&end_date=<tomorrow>&summarize=false, one per request, streams included)
gpt-5.4-nano | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_d9X4-QEsB8C7tHFAiQOm0X7RxLP-YkFADfa
gpt-5.4-nano | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
gpt-5-nano | aresponses | spend=0.00021495 | prompt_tokens=11 | completion_tokens=536 | resp_fJvoTUcrtGIq73K2UBBNVz2IGM9oZ66-hHt
gpt-5-nano | aresponses | spend=0.00032335 | prompt_tokens=11 | completion_tokens=807 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
per-second-priced-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp__aPFKvi7IyOstgfvX8v4NbnwxtLPwvpxzni
per-second-priced-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
free-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_tDdu4E8995iT5M0wAcPtXqN9MsjOT9EZc77
free-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
  1. the counter (GET /metrics/, filtered to litellm_zero_cost_requests_total): one increment per $0 request on the two deployments whose pricing entry lacks the per-token rates, both streams counted, nothing for free-chat or gpt-5-nano
litellm_zero_cost_requests_total{api_provider="openai",model="gpt-5.4-nano",model_id="df6a8a76a5a7f3b6eb5ac1d393b82a1266c52b78ee2da9692b8affe6d1f6bb9c",reason="missing_pricing_key",requested_model="gpt-5.4-nano"} 2.0
litellm_zero_cost_requests_total{api_provider="openai",model="gpt-5.4-nano",model_id="89998275f9a2fc586ac28dee35f8e7bff018e6915d7f93271afa09201afe2382",reason="missing_pricing_key",requested_model="per-second-priced-chat"} 2.0
  1. the proxy log (grep 'priced at \$0'): exactly four warnings, one per $0 request on those two deployments, each naming the model, the pricing entry, and the two missing keys; no line for free-chat (every rate 0) or gpt-5-nano (priced)
19:44:31 - LiteLLM:WARNING: litellm_logging.py:1915 - Billable request priced at $0 and logged as such (model_group=gpt-5.4-nano model=openai/gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=9): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
19:44:33 - LiteLLM:WARNING: litellm_logging.py:1915 - Billable request priced at $0 and logged as such (model_group=gpt-5.4-nano model=gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=7): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
19:44:44 - LiteLLM:WARNING: litellm_logging.py:1915 - Billable request priced at $0 and logged as such (model_group=per-second-priced-chat model=openai/gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=9): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
19:44:45 - LiteLLM:WARNING: litellm_logging.py:1915 - Billable request priced at $0 and logged as such (model_group=per-second-priced-chat model=gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=8): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}

Spend logs

  1. every $0 row is still written as $0 on both legs (this PR flags, it does not reprice)
curl -s -H "Authorization: Bearer $LITELLM_MASTER_KEY" "http://localhost:46283/spend/logs?start_date=2026-09-21&end_date=2026-09-22&summarize=false" \
  | python3 -c 'import json,sys
for r in sorted(json.load(sys.stdin), key=lambda r: r["startTime"]):
    print(r["model_group"], "|", r["call_type"], "|", "spend=%s" % r["spend"], "|", "prompt_tokens=%s" % r["prompt_tokens"], "|", "completion_tokens=%s" % r["completion_tokens"], "|", r["request_id"][:40])'
gpt-5.4-nano | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | chatcmpl-EQiHQntChbFR0eWarea6tY40tUvac
gpt-5.4-nano | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | chatcmpl-EQiHQMdhhwBVOzSoqMmxhd5xvo93o
gpt-5.4-nano | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
gpt-5.4-nano | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | msg_d3a600de-02bb-494f-84c9-20bcb7240f6b
gpt-5.4-nano | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_mrwKhwruyHEbHhL2NZiEu4u-d9TgJrCjwhP
gpt-5.4-nano | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
gpt-5-nano | acompletion | spend=0.00026175 | prompt_tokens=11 | completion_tokens=653 | chatcmpl-EQiHXJOU9fmPWi5PzPCmWM4LnsWN9
gpt-5-nano | acompletion | spend=0.00021055 | prompt_tokens=11 | completion_tokens=525 | chatcmpl-EQiHds3U1xfCkUbT8nHKgFQJhESL0
gpt-5-nano | anthropic_messages | spend=5.5e-07 | prompt_tokens=11 | completion_tokens=0 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
gpt-5-nano | anthropic_messages | spend=5.5e-07 | prompt_tokens=11 | completion_tokens=0 | msg_d1c9e25c-3f0c-48de-aa7a-cbf3ae529d83
gpt-5-nano | aresponses | spend=0.00023455 | prompt_tokens=11 | completion_tokens=585 | resp_XuMQE0LQOy1scCNXuZyCJ4xGsIAgtLMMAyG
gpt-5-nano | aresponses | spend=0.00025295 | prompt_tokens=11 | completion_tokens=631 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
per-second-priced-chat | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=6 | chatcmpl-EQiHuRbjxM14AhliVPUAEwrub2Pm1
per-second-priced-chat | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | chatcmpl-EQiHv0TLxzczqShiniBnI2sZgXBPm
per-second-priced-chat | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=10 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
per-second-priced-chat | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | msg_dda35722-4e2f-4941-b6e1-787b666bbe65
per-second-priced-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | resp_jlMpq026OqaqMvbObTOurh5miKj7xZwrnh6
per-second-priced-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
free-chat | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=9 | chatcmpl-EQiHzeSlcrIXSDOfGnE3rQpRPlQBN
free-chat | acompletion | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | chatcmpl-EQiHz2VRZih49lsqn9ilZ3dka4WBL
free-chat | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=8 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV
free-chat | anthropic_messages | spend=0.0 | prompt_tokens=11 | completion_tokens=10 | msg_fbaa230a-40ad-4a35-9b2b-4e7d6ba30427
free-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=10 | resp_5QLzMc9318Ddhk2Qqzhc0dOqgpm9Gl9d3v0
free-chat | aresponses | spend=0.0 | prompt_tokens=11 | completion_tokens=7 | resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGV

Metrics

  1. the zero-cost counter series
curl -s -H "Authorization: Bearer $LITELLM_MASTER_KEY" http://localhost:46283/metrics/ | grep -E '^litellm_zero_cost_requests_total'
litellm_zero_cost_requests_total{api_provider="openai",model="gpt-5.4-nano",model_id="df6a8a76a5a7f3b6eb5ac1d393b82a1266c52b78ee2da9692b8affe6d1f6bb9c",reason="missing_pricing_key",requested_model="gpt-5.4-nano"} 6.0
litellm_zero_cost_requests_total{api_provider="openai",model="gpt-5.4-nano",model_id="89998275f9a2fc586ac28dee35f8e7bff018e6915d7f93271afa09201afe2382",reason="missing_pricing_key",requested_model="per-second-priced-chat"} 6.0
  1. the spend counter per requested model, reduced to that label (litellm_spend_metric_total is split per service tier, so two series per deployment)
curl -s -H "Authorization: Bearer $LITELLM_MASTER_KEY" http://localhost:46283/metrics/ | grep -E '^litellm_spend_metric_total' \
  | sed -E 's/^litellm_spend_metric_total\{.*(requested_model="[^"]*").*\} /litellm_spend_metric_total{\1} /' | sort
litellm_spend_metric_total{requested_model="free-chat"} 0.0
litellm_spend_metric_total{requested_model="free-chat"} 0.0
litellm_spend_metric_total{requested_model="gpt-5-nano"} 0.00021055
litellm_spend_metric_total{requested_model="gpt-5-nano"} 0.00075035
litellm_spend_metric_total{requested_model="gpt-5.4-nano"} 0.0
litellm_spend_metric_total{requested_model="gpt-5.4-nano"} 0.0
litellm_spend_metric_total{requested_model="per-second-priced-chat"} 0.0
litellm_spend_metric_total{requested_model="per-second-priced-chat"} 0.0

Proxy log

  1. warnings about $0 requests (timestamps and logger prefix trimmed)
grep -c 'priced at \$0' proxy.log; grep 'priced at \$0' proxy.log | sed -E 's/^.*litellm_logging\.py:[0-9]+ - //'
12
Billable request priced at $0 and logged as such (model_group=gpt-5.4-nano model=openai/gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=8): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=gpt-5.4-nano model=gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=8): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=gpt-5.4-nano model=openai/gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=8): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=gpt-5.4-nano model=gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=9): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=gpt-5.4-nano model=openai/gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=9): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=gpt-5.4-nano model=gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=8): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=per-second-priced-chat model=openai/gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=6): pricing entry '89998275f9a2fc586ac28dee35f8e7bff018e6915d7f93271afa09201afe2382' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=per-second-priced-chat model=gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=7): pricing entry '89998275f9a2fc586ac28dee35f8e7bff018e6915d7f93271afa09201afe2382' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=per-second-priced-chat model=openai/gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=10): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=per-second-priced-chat model=gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=9): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=per-second-priced-chat model=openai/gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=7): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}
Billable request priced at $0 and logged as such (model_group=per-second-priced-chat model=gpt-5.4-nano provider=openai prompt_tokens=11 completion_tokens=9): pricing entry 'gpt-5.4-nano-2026-03-17' has no input_cost_per_token, output_cost_per_token. Set the missing rate in the deployment's model_info or in the model cost map, or set every rate to 0 to mark the model free. Counted in litellm_zero_cost_requests_total{reason="missing_pricing_key"}

Surprises

  • Custom pricing ignored on /v1/messages, /v1/responses: PR leaves alone
  • Per-second pricing token-priced there too, PR fix(cost): compute timing metrics before response_cost for input_cost_per_second pricing #31558 open: leaves alone
  • x-litellm-response-cost header absent on $0 responses: PR leaves alone
  • litellm_spend_metric_total split per service_tier, two series each: leaves alone
  • Warning model= and pricing entry vary between passes: PR causes
  • gpt-5-nano on /v1/messages reports output_tokens: 0, priced 5.5e-07: leaves alone
  • autorouter_baseline_cache.py:180 warning on every boot: PR leaves alone

Type

🆕 New Feature

Caveats (if any)

Low

  • Custom per-second pricing on an openai/ chat deployment prices to $0 today (pre-existing: cost_per_token dispatches openai to its per-token calculator before the generic branch that honors per-second rates, so this PR only surfaces it, as the QA flow shows). Left unfixed here because repricing is a cost-calculation decision the ticket did not ask for (whether chat honors per-second rates at all, or config load should reject them) and the warning now names the two per-token keys to set; tracked as LIT-8315

  • pricing_not_applied covers "entry has the rate, cost still $0": it names no key, so the log line and the reason label are the lead. Left as is because the only way to name more would be re-deriving why the calculator returned $0 inside the warning path, which duplicates the calculator for a case no run has hit yet, while the pricing entry, model, provider, and usage in the line already narrow it

  • The counter is unbounded only by model labels the other metrics already carry, reason has three values

  • x-litellm-response-cost is absent (not 0.0) on a $0 response, pre-existing and untouched here

  • CircleCI integration-cost (23 failures, job 2198806) and integration-providers (1 failure, job 2198811) were red at 4088ac4982 and identically red on main's own pipelines 90021 (ef8103a, jobs 2198752/2198753) and 90023 (9fad216, jobs 2198864/2198859), which carry none of this PR's code: 22 Responses API streams (native and chat-bridged) logging an all-zero cost_breakdown while spend is right, traced to feat(edenai): add Eden AI provider across chat, Responses, Messages, embeddings, audio, images and video #41101's copy of litellm's own stamped usage.cost into the provider-cost hidden param (LIT-8313, fixed on main by fix(logging): price terminal Responses stream events from their inner response #42385), the gpt-5.6-responses_previous_response_id case test(integration): endpoint, breakdown component and failure support in the cost harness #41999 added, and the fal H3 video wire test from feat(fal_ai): add MiniMax H3 text-to-video and reference-to-video #42286 and fix(fal_ai): surface fal errors in video status and content instead of completed and generic 500 #42306 (LIT-8312). Since the merge of main at ccafff8b68 both jobs are green on this branch (integration-cost, 483 tests, 0 failures; integration-providers, 27 tests, 0 failures)

  • Four build_and_test jobs, none a required check, are red at the tip with the failure sets main's own pipelines 90021 and 90023 carry: llm_translation_testing, 12 failures (ten fireworks_ai translation cases, a hosted_vllm optional-params unhashable list, a bedrock moonshot stream; branch, main); local_testing_part1, 2 bedrock capability-parity cases in test_get_model_info (branch, main); unit, 1 timing budget, test_scan_message_stays_linear_on_adversarial_credential_lines[assignment-flood] at 11.5s against 10s (branch, main); and using_litellm_on_windows, whose Install Dependencies step (uv sync downloads) hit the 10-minute no-output timeout before any test ran (branch, main, the same step and timeout). litellm_router_unit_testing is green at the tip (job 2199359) and failed once at ccafff8b68 (job 2199271) on test_acompletion_stream_counts_request_before_headers_and_tokens_once_on_completion with (11, 0) == (11, 1): the router keys rpm and tpm by %H-%M, so a run that straddles a minute boundary counts the request in one minute and the tokens in the next, which is that exact shape; the file is untouched by this PR, passes 151/151 locally at the tip, and is green on main's 90021 and 90023

  • Two CodeQL alerts stay open at the tip, both answered in their review threads and neither blocking (the CodeQL check-run is green): py/mixed-returns on _cause in zero_cost_diagnostic.py, where every match arm returns explicitly with assert_never in the fallback arm and CodeQL does not model match exhaustiveness, and py/log-injection on the warning line in litellm_logging.py, where the logged value is the pricing entry's name, reachable from request text only through a wildcard deployment that carries custom pricing

Decisions

  1. Reason enum. missing_pricing_key when the usage needs a rate the entry does not declare, pricing_not_applied when the entry declares every rate the usage needs but the total still came out $0, cost_calculation_error when the calculator raised on a request that carried usage against a known pricing entry. Alternative considered: one reason, rejected because the fix differs per reason
  2. Free model check is per used key, not per entry. A request is silent only when every rate key its usage needs (input_cost_per_token, output_cost_per_token, and the audio variants when audio tokens are present) is explicitly 0 in the entry. Cached tokens count as text input. Alternative: "all rates in the entry are 0", rejected because a Gemini audio request against a text-only entry would look free
  3. Missing keys are detected on the raw entry (litellm.model_cost[key], or the deployment's model_info when not registered), never on get_model_info, which defaults absent rates to 0 and hides the gap. An entry "declares a rate" when any key containing cost or pricing holds a positive number, recursively through nested mappings and lists (tiered pricing), validated with a pydantic TypeAdapter instead of a cast
  4. Unmapped models and entries declaring no rate stay silent. There is nothing to compare against, and the unmapped case already writes response_cost_failure_debug_information. cost_calculation_error therefore requires a resolved pricing entry
  5. Hook placement: after the direct cost calculation (success and exception branch) and at the hidden_params["response_cost"] copy-through, so a $0 precomputed early (LIT-3057) is flagged too. Both sites skip unbilled non-inference call types (get_responses, list_input_items, vector store reads, and so on) the same way the calculator does
  6. The value judged is the total response cost, model cost plus additional_response_cost, so a $0 model cost with a positive additional cost is not flagged
  7. response_cost = None means "not computed", not $0: the hook stays silent on it
  8. One request is priced more than once on the same logging object (the direct calculation, the hidden_params copy-through, and on the Anthropic and Responses bridges a second pass that resolves a different cost-map key, gpt-5.4-nano-2026-03-17 then gpt-5.4-nano), and router retries reuse it too. The diagnostic stored is the last evaluation, so a later evaluation that prices above $0 clears it and a retry that lands on a priced deployment is not counted. The warning is emitted on the first $0 finding and a zero_cost_warned flag on the logging object keeps every later finding silent, whatever was evaluated in between. Alternatives: warn whenever the diagnostic changes, rejected because the bridged routes then logged two lines per request; warn whenever a finding lands while no diagnostic is stored, rejected because the streaming bridges evaluate the usage-less completed event between two findings and logged two lines per streamed request (both caught by QA at earlier tips)
  9. Pricing resolution is deployment first (registered router id entry, else the deployment model_info dict), then the cost map by the selected cost model, the response model, and the requested model, in that order, matching what the calculator prices against
  10. The hook never raises: any failure inside it is a debug log and cost tracking proceeds unchanged. A malformed usage object (prompt_tokens: "n/a") is covered by a regression test
  11. Counter labels are requested_model, model, model_id, api_provider, reason. reason is added only when prometheus_metrics_config label filters keep it, so a filtered config does not raise on .labels()
  12. The diagnostic is a field on StandardLoggingPayload (zero_cost_diagnostic), so every logging integration can consume it, not only Prometheus
  13. The warning is logged at WARNING on the LiteLLM logger once per request and names the counter and reason label, so the log line and the metric cross-reference each other
  14. cost_calculator._get_usage_object became public get_usage_object instead of a private cross-module import
  15. No base PR. The per-second pricing surprise (custom input_cost_per_second on an openai/ chat deployment prices to $0, open PR fix(cost): compute timing metrics before response_cost for input_cost_per_second pricing #31558) is out of scope and only surfaced by this change
  16. Rate detection walks nested pricing (tiered tables, per-region maps) to a fixed depth of four with a bounded reduce instead of recursion, so a malformed entry can never loop or overflow the stack
  17. A free-by-configuration entry, and an entry that declares no rate at all, stay silent even when the calculator raised: the explicit-zero check and the no-rate guard both run before the cost_calculation_error branch, so a free model whose cost calculation errored, or a metadata-only entry with nothing to compare against, is not counted as a mispriced request (review findings at the two previous tips)
  18. With custom pricing and no registered router id, the deployment's own model_info is the pricing entry the request is judged against; the global cost-map entry keyed by the model name is consulted only for a registered router id, so an operator-declared free deployment is never judged by the published rates (review finding at the previous tip)
  19. The diagnostic judges the request against the pricing entry the calculator priced it with. A request Azure spilled onto pay-as-you-go capacity is priced by the cost-map entry instead of the deployment's zeroed PTU rates, so it is judged by that entry too: a spillover onto an entry with no per-token rate is flagged, a spillover onto a priced entry is not, and the deployment's own explicit zeros keep a non-spilled PTU request silent. One shared helper resolves custom_pricing for both the calculation and the diagnostic so the two cannot drift again (review finding at the previous tip)
  20. A cache hit is never a zero-cost finding. The saved-cost evaluation on a cache hit prices the cached response against the same entry, and the diagnostic clears itself when cache_hit is set instead of warning about a request the provider was never billed for (dependency walk at the previous tip)
  21. Failure rows count too. A request that fails after usage was recorded (a stream cut mid-way) runs the same diagnostic, so the Prometheus failure event now increments litellm_zero_cost_requests_total the way the success event does, and the warning's "Counted in" line holds on both paths. The failure event's label values gained requested_model and api_provider so the counter carries the same labels on both paths; the other failure metrics filter to their own label sets and are unchanged (dependency walk at the previous tip)

/live-pr-risk

Verdict: no breaking change and no regression on any dependent path this run drove live; the additive contract changes are listed below for the record. The dependency graph was walked at fb9c2020dd twice (one sweep over the hidden reference kinds, one target list built from the diff alone, reconciled here), the code that commit added got its own walk, 4088ac4982 and 2fccf559df change only tests/test_litellm/, and 95266607bc restores a generated file. Merge-ref drift: main moved 165 commits from the merge base 1baa26d36b to 9cc5b78c33 with none touching the seven code files this PR changes, then #42385 (3bbbf7f693) changed litellm_logging.py under this PR's hook, so main at b720909dac was merged in at ccafff8b68: _response_cost_calculator now prices a terminal Responses stream event by its inner response, and the conflict was resolved by handing that priced_result to _custom_pricing_for, to the cost calculation, and to all three _record_zero_cost_diagnostic calls, so the diagnostic judges the response the calculator priced (regression test test_terminal_responses_stream_event_is_judged_by_its_inner_response at 2fccf559df, which fails when the event wrapper is passed instead). Since that merge main gained five commits to 5d3d99eb9f; two touch litellm/types/utils.py in hunks disjoint from this PR's (echoed_cost_map_fields from #41944, image serialization from #42336), and git merge-tree of the tip onto origin/main is clean

Breaking

None observed. Evidence: run 5 above, base 1baa26d36b vs head fb9c2020dd, each on two uvicorn workers, over /v1/chat/completions, /v1/messages and /v1/responses, streaming and non-streaming, against the same three deployments. Both legs answer 200 with the same usage and the same x-litellm-response-cost* headers, both write 24 spend rows with the same spend values (/spend/logs?summarize=false), and the head differs only by the 12 warning lines and the two litellm_zero_cost_requests_total series it adds. The SDK path was A/B'd the same way at 1baa26d36b and 4088ac4982: litellm.completion and the streamed variant under both trees, with a CustomLogger capturing standard_logging_object, report response_cost: 0.0 on both sides, and only the head carries zero_cost_diagnostic (missing_pricing_key, gpt-5.4-nano-2026-03-17, input_cost_per_token and output_cost_per_token) and one warning line per call

Backward incompatible

  • litellm.cost_calculator._get_usage_object is now the public get_usage_object. At the merge base the name has zero references outside cost_calculator.py across the repo (ui/, tests/, enterprise/, cookbook/, notebooks) and both docs checkouts, so no caller, patch(...) string, or docs page depends on the old one
  • StandardLoggingPayload gains zero_cost_diagnostic (None, or reason / pricing_model / missing_pricing_keys, the last a tuple that serializes as a JSON array). Additive: every whole-payload sink goes through safe_json_dumps (Datadog, Azure Sentinel, SQS, S3, PostHog, generic API, Azure Storage) or json.dumps(default=str) (GCS); the whole-payload forwarders (Braintrust metadata, LangSmith inputs, Rubrik, Noma) ship it as JSON; OTEL sets attributes by explicit key and never enumerates the payload; the fixed-field mappers (MLflow, PostHog, New Relic, Datadog LLM Obs, Langfuse, Argilla, Literal AI, PagerDuty, Datadog cost management) read named keys only. No payload-shaped pydantic model forbids extras (the one extra: "forbid" under integrations/ is the OTEL config object). Traced, not driven
  • The Prometheus failure event's UserAPIKeyLabelValues gains requested_model and api_provider. litellm_llm_api_failed_requests_metric filters to its own label set and is unchanged (test_prometheus_zero_cost_metric.py, test_prometheus_invalid_key_filtering.py); _extract_status_code and _should_skip_metrics_for_invalid_key read only status_code
  • New metric litellm_zero_cost_requests_total, registered in DEFINED_PROMETHEUS_METRICS and PrometheusMetricLabels. Under a prometheus_metrics_config allowlist that excludes it the counter factory returns a no-op metric, and a label filter that drops reason still counts (test_label_filter_that_drops_reason_still_counts_the_request). It is deliberately not in _org_label_metrics, so it never gets the auto-appended org labels litellm_spend_metric carries
  • One new WARNING line per $0 billable request on the LiteLLM logger, ungated by set_verbose. On the Anthropic and Responses bridges its model= names the cost-map key the bridge priced with (Decision 8, the "vary between passes" surprise above)

Regression risk

  • Router fallbacks and retries reuse one Logging object (router.py threads litellm_logging_obj through both). The stored diagnostic is the last evaluation, so a retry that lands on a priced deployment is not counted, but a warning already printed for the $0 attempt stays printed. Unit-tested on the logging object (TestZeroCostDiagnostic), not driven through a live fallback config
  • The enterprise background responses cost poller reuses the create call's Logging object through _reset_success_emission_dedupe, which pops the success dedupe markers and not zero_cost_warned: the settled poll's payload and counter are right, a second warning line is not printed. Not booted here
  • pricing_entry_for_cost_calc runs once more per $0-priced response, in the response path: two litellm.model_cost lookups plus model-name selection. Not measured; a proxy with a large custom cost map and mostly $0 traffic is the shape that would notice
  • Streaming failures with partial usage (_record_partial_usage_for_failure, the Responses iterator's _record_failed_response_usage, the realtime websocket) reach the counter through the failure event added at fb9c2020dd. Covered by the hand-built failure payload test, not by a provider stream cut mid-way

Dependency graph

tested = unit test through the changed code; live = driven base vs head in run 5; traced = read, not run; unreachable = no environment in this run

  • _response_cost_calculator via update_response_metadata (chat, completions, embeddings, images, audio, moderations, rerank, responses non-stream): live for /v1/chat/completions and /v1/responses, tested at method level for the rest
  • _process_hidden_params_and_response_cost copy-through (the second pass, LIT-3057's precomputed $0): live on all six route and stream cells, tested
  • SSE cost injection _logging_obj_cost_or_none and the streaming success handler: live (streaming cells with stream_options.include_usage)
  • _response_cost_from_logging_obj for dict responses: live for /v1/messages, Google :generateContent traced
  • Responses streaming iterator _stamp_responses_usage_cost: live (/v1/responses streaming)
  • Cache-hit saved-cost recompute in get_standard_logging_object_payload: tested (the cache_hit guard clears the diagnostic), not live
  • Failure rows (_record_partial_usage_for_failure, _record_failed_response_usage, realtime partial usage, guardrail-rejected stream via record_assembled_response_for_failure): tested at the Prometheus failure event, not live
  • Pass-through handlers that precompute 0.0 (/anthropic/*, /vertex_ai/*, /bedrock/*): traced, same copy-through site
  • Vertex Live passthrough _turn_cost (once per turn): unreachable
  • SDK litellm.completion with a callback: live base vs head (below); SDK streaming _stamp_streaming_usage_cost and _response_cost_calculator_async: traced
  • _custom_pricing_for (added at fb9c2020dd): two callers, both private in litellm_logging.py; PTU spillover tested both ways (test_ptu_deployment_is_judged_by_the_entry_the_calculator_priced_with)
  • cache_hit read by _record_zero_cost_diagnostic: written in _success_handler_helper_fn, tested
  • Prometheus registration, label resolution, no-op counter factory, reason label filter: tested (four tests) and live (/metrics/ scrape, two series at 6.0)
  • Standard logging payload consumers (the list under Backward incompatible): traced, all survive
  • SpendLogs and ui/: the field is written to no column and ui/litellm-dashboard/src has no reference to it; spend rows compared live, 24 rows each leg with identical spend
  • get_usage_object rename: tested (import and call), zero external dependents
  • Grafana dashboard JSON (cookbook/litellm_proxy_server/grafana_dashboard/dashboard_all_metrics/): additive panel, file parses, not imported into a Grafana
  • Docs: litellm-docs PR [Bug]: Petals + LiteLLM + MemGPT - API Connection Error #1608 (cost_tracking.md, prometheus.md, logging_spec.md)

Not verified

  • Vertex Live passthrough (BidiGenerateContent websocket): no Vertex Live session in this run
  • Azure PTU spillover: no PTU deployment, unit tests only
  • Cache hit with litellm.cache on: unit test only
  • Mid-stream provider failure with partial usage, /v1/realtime, guardrail-rejected streams: unit test at the failure event only
  • Enterprise background responses cost poller: not booted
  • Pass-through routes precomputing 0.0: not driven
  • Outbound provider request: no forwarding recorder in front of OpenAI. The diff touches no code that builds the provider request (cost_calculator.py, litellm_logging.py, prometheus.py, llm_cost_calc/, types), so base vs head parity of the wire request is read off the diff, not recorded
  • Router fallback config: not driven

Final Attestation

Every required check is green at the tip. CircleCI's integration workflow (integration-cost, integration-providers) is green on this branch since the merge of main at ccafff8b68; the four non-required build_and_test reds are classified in the Low caveats above, each with its identical failure on main's own pipelines

  • 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
  • 9526660 passes /live-pr-risk

A request that carries usage but prices to $0 on a model whose pricing
entry has a non-zero rate now logs one warning naming the model, the
pricing entry, and the missing rate, and increments
litellm_zero_cost_requests_total{requested_model, model, model_id,
api_provider, reason}. Free models (every used rate is 0), requests
without usage, and unmapped models stay silent. The diagnostic rides on
the standard logging payload as zero_cost_diagnostic
@devin-ai-integration

devin-ai-integration Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

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

@codspeed

codspeed Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_zero_cost_warning_counter (9526660) with main (5a76420)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge with no outstanding correctness or repository-rule violations.

Summary

This PR detects billable requests logged at zero cost, emits one warning per request, exposes a labeled Prometheus counter, and adds a Grafana panel and regression coverage.

  • Distinguishes missing pricing keys, unapplied pricing, and calculation failures.
  • Suppresses diagnostics for free models, cache hits, requests without usage, and unresolved pricing entries.
  • Handles success and failure metric events, custom deployment pricing, PTU spillover, and terminal Responses streaming events.
  • All previous findings are resolved, including the custom-pricing precedence, free-model error handling, and test-helper typing issues.

Reviews (7) · Last reviewed commit: "chore: restore the lazy OpenAPI snapshot..."

Comment thread litellm/cost_calculator.py Resolved
)


def _cause(diagnostic: StandardLoggingZeroCostDiagnostic) -> str:

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.

Fixed in 535b442: the exhaustive match now returns assert_never in its fallback arm, so every path returns explicitly.

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.

Correction: CodeQL still flags this at the tip because it does not model match exhaustiveness. Every arm returns explicitly, assert_never included

@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.76543% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...m_core_utils/llm_cost_calc/zero_cost_diagnostic.py 97.40% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-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.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-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.

Stale Bugbot comment from a previous run.

if finding is None or self.zero_cost_warned:
return
self.zero_cost_warned = True
verbose_logger.warning(finding[1])

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.

Fires only when the model resolved to a pricing entry; free-form request text reaches it only via a wildcard deployment with custom pricing

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 22, 2026

@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.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-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.

Stale Bugbot comment from a previous run.

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 22, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 22, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 22, 2026
@mateo-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 9526660. Configure here.

@mateo-berri mateo-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.

LGTM

@mateo-berri
mateo-berri merged commit 537e8ac into main Sep 22, 2026
148 of 153 checks passed
@mateo-berri
mateo-berri deleted the litellm_zero_cost_warning_counter branch September 22, 2026 02:49
mateo-berri added a commit that referenced this pull request Sep 22, 2026
…aying at $0

The zero-cost diagnostic tests from #42345 used a per-second-only entry as their
misconfigured fixture, which this branch now bills. Switch that fixture to a
per-query-only entry, which is still selected as the deployment's own pricing and
still prices chat usage at $0, and add a per-second test asserting the call
duration is billed with no diagnostic

Also let a caller's explicit total_time outrank the logging window in
completion_cost, so the SDK precedence stays stamped response, caller, logging
mateo-berri added a commit that referenced this pull request Sep 22, 2026
…ery provider (#42403)

* fix(cost): honor per-second custom pricing on chat completions for every provider

* test(cost): assert a per-second priced deployment bills instead of staying at $0

The zero-cost diagnostic tests from #42345 used a per-second-only entry as their
misconfigured fixture, which this branch now bills. Switch that fixture to a
per-query-only entry, which is still selected as the deployment's own pricing and
still prices chat usage at $0, and add a per-second test asserting the call
duration is billed with no diagnostic

Also let a caller's explicit total_time outrank the logging window in
completion_cost, so the SDK precedence stays stamped response, caller, logging

* test(response_metadata): move the per-second pricing regression into the mapped tests/unit file

* fix(cost_calculator): keep media-mode per-second rates off the wall-clock path

A video, transcription, speech, or realtime entry's per-second rates price media seconds, which
their dedicated cost paths bill from the media itself. The generic per-second branch now skips
those modes, so a video status poll on a per-second video model bills nothing instead of the
seconds the poll took to answer.

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
mateo-berri added a commit that referenced this pull request Oct 29, 2026
…v1/messages (#42417)

* fix(cost): honor per-second custom pricing on chat completions for every provider

* test(cost): assert a per-second priced deployment bills instead of staying at $0

The zero-cost diagnostic tests from #42345 used a per-second-only entry as their
misconfigured fixture, which this branch now bills. Switch that fixture to a
per-query-only entry, which is still selected as the deployment's own pricing and
still prices chat usage at $0, and add a per-second test asserting the call
duration is billed with no diagnostic

Also let a caller's explicit total_time outrank the logging window in
completion_cost, so the SDK precedence stays stamped response, caller, logging

* test(response_metadata): move the per-second pricing regression into the mapped tests/unit file

* fix(cost): bill a deployment's per-second rates on /v1/responses and /v1/messages

The proxy builds the request's logging state before the router picks a
deployment, and only the chat path re-read the deployment's
input_cost_per_second / output_cost_per_second afterwards. The shared
update step every other route runs (Logging.update_from_kwargs) now
seeds those custom pricing keys from the router-merged kwargs too, so
custom_pricing flips on and the cost calculator prices the call against
the router-registered deployment id on every surface.

* fix(cost): price a /v1/messages call off the response time the proxy reports

A /v1/messages result is a plain dict, so the proxy keeps its response time on
the logging object. The cost step now reads it there for a non-streamed call,
so the cost header and the spend log bill the same duration.

* fix(anthropic): bill a deployment's per-second rate only on the native /v1/messages route

Move the custom pricing copy from the shared logging refresh into the native
Messages handler, reusing the helper the Responses handler already had, so
generateContent and other routes keep their current billing

* fix(cost): pass only per-second rates to native /v1/messages cost tracking

Other deployment overrides keep billing as on main, matching chat's per-second gate

* test(anthropic): pin per-second-only pricing on native /v1/messages with a long-context-rate deployment

* fix(cost): bill native /v1/messages from logging setup, as main did, to the end the proxy reports

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants