mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 11:28:35 -05:00
[PR #22166] [MERGED] fix: persist token usage data for non-streaming chat responses #65382
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/22166
Author: @Classic298
Created: 3/2/2026
Status: ✅ Merged
Merged: 3/7/2026
Merged by: @tjbck
Base:
dev← Head:fix/non-streaming-save-usage📝 Commits (1)
da85e74fix: persist token usage data for non-streaming chat responses📊 Changes
1 file changed (+4 additions, -0 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+4 -0)📄 Description
The non-streaming response handler was saving assistant messages without their usage/token data. While the streaming handler correctly extracted and saved usage information, the non-streaming path discarded it entirely.
This caused assistant messages from non-streaming completions to have NULL usage in the chat_message table, making them invisible to the analytics token aggregation queries and contributing to the '0 tokens' display in Admin Panel Analytics.
Extract and normalize the usage data from the API response and include it in the database upsert, matching the pattern already used by the streaming handler.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.