-
Notifications
You must be signed in to change notification settings - Fork 11.6k
fix(responses): preserve pre-consume when streamed output lacks usage #7195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
blackdm666
wants to merge
1
commit into
QuantumNous:main
from
blackdm666:codex/fix-responses-missing-usage-billing
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge QuantumNous/new-api /tmp/coderabbit-repo-knowledge/quantumnous-new-api-61b7fca8/learningsLength of output: 10688
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 50376
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 39423
🌐 Web query:
OpenAI Responses API streaming events response.output_text.done response.function_call_arguments.done response.refusal.done response.reasoning_summary_text.done💡 Result:
In the OpenAI Realtime API, streaming "done" events represent the finalization of specific content parts or components within a model response [1][2]. These events are emitted by the server to confirm that a particular stream—such as text, function call arguments, or reasoning summaries—has completed [1][3][4][5][6]. They are also emitted if the response is interrupted, incomplete, or cancelled [3][4]. Key "done" events include: response.output_text.done Emitted when the generation of a text content part is complete [4]. It contains the finalized text, the item and response IDs, and indices [7][4]. response.function_call_arguments.done Emitted when the generation of function call arguments is complete [3]. It includes the final JSON-formatted arguments, the function name, and the associated call ID [3]. response.refusal.done Emitted when the model's refusal text is finalized [5][8]. It provides the complete refusal content [5][9]. response.reasoning_summary_text.done Emitted when the reasoning summary text for a model response is completed [6][10]. It includes the finalized summary text and sequence information [10][11][12]. These events complement the delta events (e.g., response.output_text.delta) used for real-time streaming updates [1][13]. While delta events allow you to render partial content, the corresponding "done" events provide the complete, finalized data necessary for final processing or state synchronization [1][3][4]. [14][1][3][4][5][6][10]
Citations:
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 22084
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 14678
Mark finalized Responses events as billable output.
OaiResponsesStreamHandlerignoresresponse.output_text.done,response.function_call_arguments.done,response.refusal.done, andresponse.reasoning_summary_text.done, althoughResponsesStreamResponseexposes their finalized payloads. Ifresponse.completedthen lacks usable usage and output, the fallback is skipped andcalculateTextQuotaSummarysets the quota to zero. Mark non-empty finalized payloads as billable, use finalized text for token estimation, and add done-only regression tests.🤖 Prompt for AI Agents