da85e74 fix: 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.
Note
Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.
🔄 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/22166
**Author:** [@Classic298](https://github.com/Classic298)
**Created:** 3/2/2026
**Status:** ✅ Merged
**Merged:** 3/7/2026
**Merged by:** [@tjbck](https://github.com/tjbck)
**Base:** `dev` ← **Head:** `fix/non-streaming-save-usage`
---
### 📝 Commits (1)
- [`da85e74`](https://github.com/open-webui/open-webui/commit/da85e740ce2faca86a72f7d83a38cd21dedfd6d8) fix: persist token usage data for non-streaming chat responses
### 📊 Changes
**1 file changed** (+4 additions, -0 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/utils/middleware.py` (+4 -0)
</details>
### 📄 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
<!--
🚨 DO NOT DELETE THE TEXT BELOW 🚨
Keep the "Contributor License Agreement" confirmation text intact.
Deleting it will trigger the CLA-Bot to INVALIDATE your PR.
-->
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.
> [!NOTE]
> Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 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.