[PR #23556] [CLOSED] fix: always include stream_options for usage tracking in streaming requests #42883

Closed
opened 2026-04-25 14:39:28 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/23556
Author: @smorello87
Created: 4/10/2026
Status: Closed

Base: devHead: fix/stream-options-usage


📝 Commits (1)

  • 379b6da fix: 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

  • Target branch: dev
  • Description: See below
  • Testing: Manually tested on ECS deployment with OpenRouter, Bedrock Gateway, and Bedrock Mantle
  • Code review: Self-reviewed
  • Title Prefix: fix:

Changelog Entry

Fixed

  • Always include 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 analytics

Description

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_options when a model's metadata includes capabilities.usage = true, which requires manual admin configuration via DEFAULT_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, inject stream_options: { include_usage: true } for streaming requests that don't already have it set.

Testing

Tested on an ECS Fargate deployment with three providers:

  • OpenRouter — already returned usage, continues to work (field is ignored if already present)
  • AWS Bedrock (via bedrock-access-gateway sidecar) — previously showed 0 tokens in analytics, now correctly reports input/output tokens
  • AWS Bedrock Mantle — same fix, now returns usage data

Verified via CloudWatch logs that raw provider responses include prompt_tokens and completion_tokens after the change.

Contributor License Agreement


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/23556 **Author:** [@smorello87](https://github.com/smorello87) **Created:** 4/10/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/stream-options-usage` --- ### 📝 Commits (1) - [`379b6da`](https://github.com/open-webui/open-webui/commit/379b6da343070e91e8d9e6bb13560252d149c015) fix: always include stream_options for usage tracking in streaming requests ### 📊 Changes **1 file changed** (+6 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/routers/openai.py` (+6 -0) </details> ### 📄 Description <!-- ⚠️ CRITICAL CHECKS FOR CONTRIBUTORS (READ, DON'T DELETE) ⚠️ 1. Target the `dev` branch. PRs targeting `main` will be automatically closed. 2. Do NOT delete the CLA section at the bottom. It is required for the bot to accept your PR. --> - [x] **Target branch:** `dev` - [x] **Description:** See below - [x] **Testing:** Manually tested on ECS deployment with OpenRouter, Bedrock Gateway, and Bedrock Mantle - [x] **Code review:** Self-reviewed - [x] **Title Prefix:** `fix:` # Changelog Entry ### Fixed - Always include `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 analytics --- ### Description 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_options` when a model's metadata includes `capabilities.usage = true`, which requires manual admin configuration via `DEFAULT_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, inject `stream_options: { include_usage: true }` for streaming requests that don't already have it set. ### Testing Tested on an ECS Fargate deployment with three providers: - **OpenRouter** — already returned usage, continues to work (field is ignored if already present) - **AWS Bedrock (via bedrock-access-gateway sidecar)** — previously showed 0 tokens in analytics, now correctly reports input/output tokens - **AWS Bedrock Mantle** — same fix, now returns usage data Verified via CloudWatch logs that raw provider responses include `prompt_tokens` and `completion_tokens` after the change. ### Contributor License Agreement - [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 14:39:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#42883