From 397f7f0862d4105b874523e1a0105ae036db18ec Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sun, 1 Feb 2026 10:48:31 +0100 Subject: [PATCH] fix(ui): take account of reasoning in token count calculation (#8324) We were skipping reasoning traces when counting tokens, yielding to a wrong sum count. Signed-off-by: Ettore Di Giacinto --- core/http/static/chat.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/http/static/chat.js b/core/http/static/chat.js index 6314f4f43..aacf061f4 100644 --- a/core/http/static/chat.js +++ b/core/http/static/chat.js @@ -1404,6 +1404,11 @@ async function promptGPT(systemPrompt, input) { case "reasoning": hasReasoningFromAPI = true; // Mark that we're receiving reasoning from API if (eventData.content) { + // Count tokens for rate calculation (thinking/reasoning) + const reasoningRequest = activeRequests.get(chatId); + if (reasoningRequest) { + reasoningRequest.tokensReceived += Math.ceil(eventData.content.length / 4); + } const currentChat = chatStore.getChat(chatId); if (!currentChat) break; // Chat was deleted const isMCPMode = currentChat.mcpMode || false; @@ -1959,6 +1964,11 @@ async function promptGPT(systemPrompt, input) { if (reasoningDelta && reasoningDelta.trim() !== "") { hasReasoningFromAPI = true; // Mark that we're receiving reasoning from API reasoningContent += reasoningDelta; + // Count tokens for rate calculation (thinking/reasoning) + const reasoningRequest = activeRequests.get(chatId); + if (reasoningRequest) { + reasoningRequest.tokensReceived += Math.ceil(reasoningDelta.length / 4); + } const currentChat = chatStore.getChat(chatId); if (!currentChat) { // Chat was deleted, skip this line