test(main): pin what a streamed response costs, end to end - #37812
Merged
yuneng-berri merged 1 commit intoAug 22, 2026
Merged
Conversation
Contributor
Greptile SummaryThis test-only PR adds end-to-end regression coverage for streamed completion cost accounting.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| tests/test_litellm/test_main.py | Adds local streamed-response cost tests without changing production behavior; no eligible follow-up finding remains. |
Reviews (2): Last reviewed commit: "test(main): pin what a streamed response..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
6 tasks
Rebuilding a streamed response and pricing it is the path a spend row comes from, and nothing asserted it end to end. Reversing either half of the usage the provider reported left the file green. Three cases: the rebuilt response bills the usage the last chunk carried, streaming and not streaming bill the same usage the same, and a stream that reported no usage is still billed rather than dropped. The cost is asserted against the catalog prices the run itself reads, with a non-zero guard in front of it so an all-zeros lookup cannot satisfy it vacuously. Pinning the dollar figure as a literal would have made a routine gpt-4o price update fail a test about usage reconstruction.
yuneng-berri
force-pushed
the
litellm_streamed_response_cost_path
branch
from
August 21, 2026 10:58
12321c8 to
34930e8
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:
stream_chunk_buildertest_main.pyasserted a dollar figure on that pathHow it solves it:
User Flow
No end-user behavior changes. A developer streaming a completion keeps seeing the
same spend on https://litellm-domain/ui/?page=logs, and a change that would zero
it now fails before it ships.
Relevant issues
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
Shared setup: the chunk builder is rewritten to discard the token counts the
provider reported in its usage chunk, one field at a time, and the mapped test
file is run against it.
Before (ff02d5c)
uv run pytest tests/test_litellm/test_main.py -qAfter (34930e8)
uv run pytest tests/test_litellm/test_main.py -qType
✅ Test
Caveats (if any)
model_cost, not hard-codedFinal Attestation