mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-15 21:19:39 -05:00
[PR #17421] [CLOSED] fix: Return usage information correctly for google models #79295
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/17421
Author: @aleprj
Created: 9/13/2025
Status: ❌ Closed
Base:
dev← Head:fix-usage-google📝 Commits (2)
f2e8867fix: don't assume usage is sent only when there is no delta. Some providers will send everything together.000ca48fix errors in the logic.📊 Changes
1 file changed (+16 additions, -14 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+16 -14)📄 Description
…viders will send everything together.
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Added
Changed
Deprecated
Removed
Fixed
Security
Breaking Changes
Additional Information
The code assumed the usage information would be always sent by the provider separated from the choices tag (as OpenAI usually does). But Google often just sends everything together when the generation is small:
{ "choices": [ { "delta": { "content": "Olá! Como posso ajudar?", "role": "assistant" }, "finish_reason": "stop", "index": 0 } ], "created": 1757736622, "id": "ru7EaIjuDKWgz7IP48a6kAM", "model": "gemini-2.5-flash", "object": "chat.completion.chunk", "usage": { "completion_tokens": 6, "prompt_tokens": 3, "total_tokens": 41 } }Even when it's big, it sends the usage with every iteration, updating the token values as it goes. The last iteration contains both the last chunk and the last usage information.
Screenshots or Videos
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.
It's a simple fix but It's important for people that use filters to register the usage with langfuse or other tools.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.