Repository navigation
fix(responses): log completed response, not the event, for non-streaming callers - #36450
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThe PR fixes spend logging when a non-streaming caller drains an SSE Responses API iterator by passing the completed response, rather than its wrapper event, to success handlers
Confidence Score: 5/5The PR appears safe to merge, with the non-streaming logging fix isolated from the existing streaming path The changed branch passes the completed Responses API payload to non-streaming success handlers while preserving the completion event for streaming handlers, and focused tests cover both outcomes
|
| Filename | Overview |
|---|---|
| litellm/responses/streaming_iterator.py | Selectively unwraps completed response events for non-streaming success logging while retaining copied wrapper events for streaming callers |
| tests/test_litellm/responses/test_streaming_iterator.py | Adds focused asynchronous coverage proving the logged object shape for both stream modes |
| ruff-strict-budget.json | Ratchets the S110 allowance down by one after removing the broad exception suppression |
| type-discipline-budget.json | Ratchets the LIT010 allowance down by two for the newly annotated final variables |
Reviews (1): Last reviewed commit: "fix(responses): log completed response, ..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ing callers Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ca767b4 to
6bf2156
Compare
… path When a non-streaming caller drains a Responses API streaming iterator (e.g. the Anthropic /v1/messages -> Responses API bridge against a force-streaming provider like chatgpt/*), _log_completed_response passed the ResponseCompletedEvent wrapper to dispatch_success_handlers. The success handlers only unwrap it in their assembled-stream branch, which a non-streaming caller never reaches — so standard_logging_object was never built, and _PROXY_track_cost_callback raised "Cost tracking failed: standard_logging_object not found". Fix: add _response_for_success_logging() that copies and unwraps .completed_response to the inner ResponsesAPIResponse before passing it to the success handlers. This lets _is_recognized_call_type_for_logging match in the non-streaming branch so standard_logging_object is built. Related: BerriAI#36426, BerriAI#36450
|
Could you please close this PR in favor of #40139? The replacement is now conflict-free. Posted for GP by his AI assistant |
|
Superseded by #41235, which keeps non-streaming callers off the streaming iterator entirely and lands one spend row per call |
TLDR
Problem this solves:
standard_logging_object not foundinsteadHow it solves it:
User Flow
Before: a developer calling a
mode: responsesmodel over/v1/chat/completionswithout streaming gets a good answer that is never billedchatgpt/*model, nostreamfieldusageblock"stream": truedoes show up, so spend silently depends on the request shapeAfter: the same non-streaming request is billed like the streaming one
streamfieldusageRelevant issues
Fixes #36426
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
Reproduced against a local proxy backed by postgres, with a
mode: responsesmodel whose provider always answers/responseswith SSE, which is what forces the bridge to drain a streaming iterator for a non-streaming caller. Not a paid provider call: the failure needs a provider that unconditionally setsstream = Trueon the responses request, so the backend here is a local SSE server returning a fixedresponse.completedpayload withinput_tokens: 11/output_tokens: 7, and the model is priced in the config so a real cost is computed.Before, at 457be8f (parent of this branch):
After, at ca767b4:
Streaming on the same build still bills exactly one row per request, with the same tokens and spend, so the fix does not double count.
Type
🐛 Bug Fix
Caveats (if any)
Link to Devin session: https://app.devin.ai/sessions/5efe36ef464e4140aa82e37d6cf2680d