mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #23556] [CLOSED] fix: always include stream_options for usage tracking in streaming requests #50301
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23556
Author: @smorello87
Created: 4/10/2026
Status: ❌ Closed
Base:
dev← Head:fix/stream-options-usage📝 Commits (1)
379b6dafix: always include stream_options for usage tracking in streaming requests📊 Changes
1 file changed (+6 additions, -0 deletions)
View changed files
📝
backend/open_webui/routers/openai.py(+6 -0)📄 Description
devfix:Changelog Entry
Fixed
stream_options: { include_usage: true }in streaming chat completion requests so providers that require explicit opt-in (e.g., AWS Bedrock) return token usage data for analyticsDescription
Providers like AWS Bedrock only return token usage data in streaming responses when the client sends
stream_options: { include_usage: true }. Without this, the analytics dashboard shows zero tokens for these models.Currently, the frontend only sends
stream_optionswhen a model's metadata includescapabilities.usage = true, which requires manual admin configuration viaDEFAULT_MODEL_METADATA. This change injects it server-side so analytics work out of the box for all providers.OpenRouter and OpenAI already return usage by default and safely ignore the extra field. The Responses API is excluded since it doesn't support
stream_options.Related: #21347, #23322
Changes
One-line addition in
backend/open_webui/routers/openai.py— before serializing the payload, injectstream_options: { include_usage: true }for streaming requests that don't already have it set.Testing
Tested on an ECS Fargate deployment with three providers:
Verified via CloudWatch logs that raw provider responses include
prompt_tokensandcompletion_tokensafter the change.Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.