From fbff252b62894a83bef0f3b5f596e32ec679949a Mon Sep 17 00:00:00 2001 From: Zireael <3856578+Zireael@users.noreply.github.com> Date: Fri, 19 Jun 2026 01:00:36 +0200 Subject: [PATCH 1/4] feat(usage): add cached tokens and cache hit % metrics Surface cache token data that was already captured but not displayed: Backend (usageRepo.js): - Add cacheReadTokens to addToCounter, aggregateEntryToDay, all byProvider/byModel/byAccount/byApiKey/byEndpoint aggregations - Add totalCacheReadTokens and cacheHitRatio to getUsageStats output - Add cachedTokens, promptTokens, cacheHitRatio to getChartData buckets Frontend: - OverviewCards: add Cached Tokens and Cache Hit % summary cards - UsageChart: add Cached and Cache % view modes with filter dropdown - UsageTable: add Cached Tokens and Cache Hit % columns in tokens mode - RequestDetailsTab: add cache columns to table and detail drawer - UsageStats orchestrator: propagate cache data through sortData and groupDataByKey to all child components --- .../usage/components/OverviewCards.js | 13 +- .../usage/components/RequestDetailsTab.js | 34 +++++- .../dashboard/usage/components/UsageChart.js | 114 +++++++++++++++--- .../dashboard/usage/components/UsageTable.js | 9 ++ src/lib/db/repos/usageRepo.js | 75 ++++++++---- src/shared/components/UsageStats.js | 11 +- 6 files changed, 210 insertions(+), 46 deletions(-) diff --git a/src/app/(dashboard)/dashboard/usage/components/OverviewCards.js b/src/app/(dashboard)/dashboard/usage/components/OverviewCards.js index 5d08933de9..dfb47d29e2 100644 --- a/src/app/(dashboard)/dashboard/usage/components/OverviewCards.js +++ b/src/app/(dashboard)/dashboard/usage/components/OverviewCards.js @@ -5,10 +5,13 @@ import Card from "@/shared/components/Card"; const fmt = (n) => new Intl.NumberFormat().format(n || 0); const fmtCost = (n) => `$${(n || 0).toFixed(2)}`; +const fmtPct = (n) => `${(n * 100).toFixed(1)}%`; export default function OverviewCards({ stats }) { + const cacheHitRatio = stats.totalPromptTokens > 0 ? stats.totalCacheReadTokens / stats.totalPromptTokens : 0; + return ( -