Add stream_options.include_usage for OpenAI-compatible API token usage#45812
Merged
benbrandt merged 2 commits intozed-industries:mainfrom Mar 17, 2026
Merged
Conversation
This enables token usage reporting in streaming responses for OpenAI-compatible APIs (OpenAI, xAI/Grok, etc). Without this parameter, APIs do not return usage data during streaming, which prevents the token counter UI from displaying current usage. Changes: - Add StreamOptions struct with include_usage field to open_ai crate - Add stream_options field to Request struct - Set stream_options to include_usage: true when stream is enabled - Update edit_prediction requests with stream_options: None (non-streaming)
56b1b98 to
c7be54d
Compare
Co-authored-by: Smit Barmase <[email protected]>
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.
Summary
This PR enables token usage reporting in streaming responses for OpenAI-compatible APIs (OpenAI, xAI/Grok, OpenRouter, etc).
Problem
Currently, the token counter UI in the Agent Panel doesn't display usage for some OpenAI-compatible providers because they don't return usage data during streaming by default. According to OpenAI's API documentation, the
stream_options.include_usageparameter must be set totrueto receive usage statistics in streaming responses.Solution
include_usagefield to the open_ai cratestream_optionsfield to the Request structstream_options: { include_usage: true }whenstream: truestream_options: None(non-streaming)Testing
Tested with xAI Grok models - token counter now correctly shows usage after sending a message.
References
Release Notes: