From e6af874b47a0254433f5ca57b6a8d47644f6043d Mon Sep 17 00:00:00 2001 From: Prakersh Maheshwari Date: Thu, 19 Mar 2026 17:07:46 +0530 Subject: [PATCH] fix(usage): include cache tokens in usage history input total (#477) logUsage stored only non-cached input tokens in usage_history.tokens_input. For heavily-cached Claude requests (common with Claude Code), this shows near-zero input when the real total is 150K+, causing the analytics dashboard to severely underreport input token usage. Now sums: input = prompt_tokens + cache_read + cache_creation --- open-sse/utils/usageTracking.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/open-sse/utils/usageTracking.ts b/open-sse/utils/usageTracking.ts index 2ac3199a30..19c97b6fb2 100644 --- a/open-sse/utils/usageTracking.ts +++ b/open-sse/utils/usageTracking.ts @@ -400,8 +400,10 @@ export function logUsage(provider, usage, model = null, connectionId = null, api console.log(msg); // Save to usage DB + // input = total input tokens (non-cached + cache_read + cache_creation) + // This ensures analytics show correct totals for heavily-cached requests const tokens = { - input: inTokens, + input: inTokens + (cacheRead || 0) + (cacheCreation || 0), output: outTokens, cacheRead: cacheRead || 0, cacheCreation: cacheCreation || 0,