test(proxy): pin what a failed request records as usage and spend - #37813
Merged
yuneng-berri merged 1 commit intoAug 22, 2026
Merged
Conversation
Contributor
Greptile SummaryThe PR adds focused unit coverage for failed-request usage and spend recording without changing production behavior.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| tests/test_litellm/proxy/test_proxy_utils.py | Adds direct regression tests for failure-usage estimation and spend-log lifting; no blocking issue was found. |
Reviews (2): Last reviewed commit: "test(proxy): pin what a failed request r..." | Re-trigger Greptile
| cost = litellm.completion_cost(completion_response=rebuilt, model=STREAM_COST_MODEL) | ||
|
|
||
| assert cost == pytest.approx(_priced_at(137, 42)) | ||
| assert cost == pytest.approx(0.0007625) |
Contributor
There was a problem hiding this comment.
This assertion duplicates the active gpt-4o catalog price as a literal, so a legitimate pricing-data update will fail the test even when streamed usage reconstruction and cost calculation remain correct.
Suggested change
| assert cost == pytest.approx(0.0007625) |
Knowledge Base Used: Cost Tracking and Budget Enforcement
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Six helpers in `litellm/proxy/utils.py` decide the usage a failed request records, and none of them is named anywhere in the suite. Two of their decisions could be reversed with the file still green: a request with nothing countable in it lifted as a zero-token usage, and a request that never reached a provider billed for input it never sent. Twelve cases asserting those contracts directly, plus a canary pinning the literal no-upstream-call key the module branches on, so a rename cannot pass silently.
yuneng-berri
force-pushed
the
litellm_failed_request_usage_tests
branch
from
August 21, 2026 10:59
a8a33e9 to
df3bb2f
Compare
Contributor
Author
ryan-crabbe-berri
approved these changes
Aug 22, 2026
yucheng-berri
approved these changes
Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
How it solves it:
User Flow
No end-user behavior changes. A proxy admin reading a failed request on
https://litellm-domain/ui/?page=logs keeps seeing the same tokens, and the two
ways that row could silently go wrong now fail in CI first.
Relevant issues
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
Shared setup: ten decisions in
litellm/proxy/utils.pyare rewritten to theiropposite, one at a time, and the mapped test file is run against each.
Before (ff02d5c)
uv run pytest tests/test_litellm/proxy/test_proxy_utils.py -qProxyLogging. The two that survive are the onesthat put a wrong number on a spend row: a request with nothing countable in
it lifted as a zero-token usage, and a request that never reached a provider
billed for input it never sent
After (df3bb2f)
uv run pytest tests/test_litellm/proxy/test_proxy_utils.py -qType
✅ Test
Caveats (if any)
litellm_no_upstream_llm_call, deliberatelyFinal Attestation