Repository navigation
Fix: Add stream_options.include_usage for Chat Completions API to enable token usage reporting - #3516
Closed
fannnzhang wants to merge 2 commits into
Closed
fannnzhang wants to merge 2 commits into
fannnzhang wants to merge 2 commits into
Conversation
Author
|
I have read the CLA Document and I hereby sign the CLA |
fannnzhang
force-pushed
the
fix/chat-completions-usage
branch
from
September 12, 2025 08:43
775b300 to
aff744a
Compare
…ble token usage reporting
This change adds the missing stream_options: { include_usage: true } field to the Chat Completions API requests, which enables the API to return token usage information in the final streaming chunk. This allows the codex client to properly track and report token usage for billing and monitoring purposes.
Added a test case to verify that the stream_options field is correctly included in the request payload.
fannnzhang
force-pushed
the
fix/chat-completions-usage
branch
from
September 17, 2025 08:30
b1d8c1a to
202b2af
Compare
- Remove duplicate ChatCompletionsUsage struct in favor of protocol::TokenUsage - Add field aliases to TokenUsage to support Chat Completions API field names - Fix token usage tracking in chat completions streaming - Set cached_input_tokens and reasoning_output_tokens to 0 for Chat Completions API This fixes an issue where codex exec was not correctly tracking or using tokenUsage when using the wire::chat protocol.
fannnzhang
force-pushed
the
fix/chat-completions-usage
branch
from
September 17, 2025 08:36
202b2af to
1d19f42
Compare
Contributor
|
Thanks for the contribution, and apologies for the slow response. We've received many PRs, and we don't have the bandwidth on the codex team to review all of them. It looks like this PR is no longer relevant. The linked issue is marked as completed. |
|
@etraut-openai @fannnzhang codex/codex-rs/core/src/chat_completions.rs Line 332 in 6c36318 so the Latest code have not set stream_options.include_usage |
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.
Description
This change adds the missing
stream_options: { include_usage: true }field to the Chat Completions API requests, which enables the API to return token usage information in the final streaming chunk.This allows the Codex client to properly track and report token usage for billing and monitoring purposes.
Additionally, a test case was added to verify that the
stream_optionsfield is correctly included in the request payload.Related Issue
Fixes #3513
Changes
"stream_options": { "include_usage": true }to Chat Completions API request payloads.Impact