mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[GH-ISSUE #23926] feat: Track token usage analytics for API-key requests without chat_id #35641
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?
Originally created by @pvyswiss on GitHub (Apr 21, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/23926
Feature Request
The
/admin/analyticsdashboard shows zero token usage for models used exclusively via API clients (OpenCode Desktop, Continue.dev, curl). Models used from the Web UI browser show correct analytics.Related to: #23917 (Bug 6)
Root Cause
The analytics pipeline requires
event_emitterto be non-None, which requireschat_id,session_id, andmessage_id. API clients don't send these -- they manage their own conversation state.When
event_emitteris None, the streaming handler falls to a simple passthrough branch with NO usage tracking and NO DB writes. The usage data IS present in the SSE stream but nobody reads it.Suggested Fix
In the passthrough branch, extract usage from the final SSE chunk and write to DB:
Impact
File
backend/open_webui/utils/middleware.py@gaby commented on GitHub (Apr 22, 2026):
Duplicate of https://github.com/open-webui/open-webui/issues/21675?issue=open-webui%7Copen-webui%7C21652
Related to https://github.com/open-webui/open-webui/issues/21675?issue=open-webui%7Copen-webui%7C21675