From 4e2e88536120b1a966490ab4b08e46b113033cd4 Mon Sep 17 00:00:00 2001 From: Gurjot Singh Date: Thu, 20 Aug 2026 00:57:53 +0530 Subject: [PATCH 1/2] feat: total cached-content and reasoning tokens in session usage summary The event tab's per-event usage view already renders every usageMetadata field, but the "Usage Summary for Session" totals aggregated only prompt, candidates, and total tokens. Cached-content (cache-read) and thoughts (reasoning) tokens were invisible at the session level, even though they matter for cost tracking. Sum cachedContentTokenCount and thoughtsTokenCount across the session's events and add "Total Cached Content Tokens" and "Total Thoughts Tokens" rows to the session summary. Each row renders only when its total is greater than zero, so sessions without caching or reasoning are unchanged. --- .../components/event-tab/event-tab.component.html | 12 ++++++++++++ src/app/components/event-tab/event-tab.component.ts | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/app/components/event-tab/event-tab.component.html b/src/app/components/event-tab/event-tab.component.html index 9356b690..deab4e20 100644 --- a/src/app/components/event-tab/event-tab.component.html +++ b/src/app/components/event-tab/event-tab.component.html @@ -245,10 +245,22 @@ Total Prompt Tokens {{ sessionUsageMetadata()['Prompt Tokens'] | number }} + @if (sessionUsageMetadata()['Cached Content Tokens'] > 0) { + + Total Cached Content Tokens + {{ sessionUsageMetadata()['Cached Content Tokens'] | number }} + + } Total Candidates Tokens {{ sessionUsageMetadata()['Candidates Tokens'] | number }} + @if (sessionUsageMetadata()['Thoughts Tokens'] > 0) { + + Total Thoughts Tokens + {{ sessionUsageMetadata()['Thoughts Tokens'] | number }} + + } Total Tokens {{ sessionUsageMetadata()['Total Tokens'] | number }} diff --git a/src/app/components/event-tab/event-tab.component.ts b/src/app/components/event-tab/event-tab.component.ts index d3398c99..cb27ba33 100644 --- a/src/app/components/event-tab/event-tab.component.ts +++ b/src/app/components/event-tab/event-tab.component.ts @@ -190,6 +190,8 @@ export class EventTabComponent { const allEvents = Array.from(this.eventDataMap().values()); let totalPromptTokens = 0; let totalCandidatesTokens = 0; + let totalCachedContentTokens = 0; + let totalThoughtsTokens = 0; let totalTokens = 0; allEvents.forEach(ev => { @@ -197,10 +199,14 @@ export class EventTabComponent { if (metadata) { const prompt = metadata.promptTokenCount ?? metadata.promptTokens ?? 0; const candidates = metadata.candidatesTokenCount ?? metadata.candidatesTokens ?? 0; + const cachedContent = metadata.cachedContentTokenCount ?? metadata.cachedContentTokens ?? 0; + const thoughts = metadata.thoughtsTokenCount ?? metadata.thoughtsTokens ?? 0; const total = metadata.totalTokenCount ?? metadata.totalTokens ?? 0; totalPromptTokens += Number(prompt); totalCandidatesTokens += Number(candidates); + totalCachedContentTokens += Number(cachedContent); + totalThoughtsTokens += Number(thoughts); totalTokens += Number(total); } }); @@ -208,6 +214,8 @@ export class EventTabComponent { return { 'Prompt Tokens': totalPromptTokens, 'Candidates Tokens': totalCandidatesTokens, + 'Cached Content Tokens': totalCachedContentTokens, + 'Thoughts Tokens': totalThoughtsTokens, 'Total Tokens': totalTokens }; }); From 9512e349139df755121e74ac4cd305e1722fbed7 Mon Sep 17 00:00:00 2001 From: Gurjot Singh Date: Thu, 20 Aug 2026 01:27:49 +0530 Subject: [PATCH 2/2] feat: show cache-creation (write) token total in session usage summary Extends the session usage summary with a "Total Cache Creation Tokens" row for prompt-cache *write* tokens, complementing the cache-read and reasoning totals. Cache-write is read from the event itself (event.cacheCreationTokenCount) rather than usageMetadata, because google.genai's usage type forbids extra fields; read/reasoning remain usageMetadata fields. The row renders only when the total is greater than zero, so it stays inert until a backend that serializes the field is in use. --- .../event-tab/event-tab.component.html | 16 ++++++++++++++++ .../components/event-tab/event-tab.component.ts | 8 ++++++++ src/app/core/models/types.ts | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/src/app/components/event-tab/event-tab.component.html b/src/app/components/event-tab/event-tab.component.html index deab4e20..86fb92f5 100644 --- a/src/app/components/event-tab/event-tab.component.html +++ b/src/app/components/event-tab/event-tab.component.html @@ -229,6 +229,16 @@ } + @if (selectedEvent()?.cacheCreationTokenCount) { + + cacheCreationTokenCount + + + {{ selectedEvent()!.cacheCreationTokenCount | number }} + + + + } } @else { @@ -251,6 +261,12 @@ } + @if (sessionUsageMetadata()['Cache Creation Tokens'] > 0) { + + + + + } diff --git a/src/app/components/event-tab/event-tab.component.ts b/src/app/components/event-tab/event-tab.component.ts index cb27ba33..55386a95 100644 --- a/src/app/components/event-tab/event-tab.component.ts +++ b/src/app/components/event-tab/event-tab.component.ts @@ -192,6 +192,7 @@ export class EventTabComponent { let totalCandidatesTokens = 0; let totalCachedContentTokens = 0; let totalThoughtsTokens = 0; + let totalCacheCreationTokens = 0; let totalTokens = 0; allEvents.forEach(ev => { @@ -209,12 +210,19 @@ export class EventTabComponent { totalThoughtsTokens += Number(thoughts); totalTokens += Number(total); } + // Cache-write (creation) tokens live on the event itself, not in + // usageMetadata: google.genai's usage type forbids extra fields, so ADK + // surfaces them on the serializable event (alongside cacheMetadata) + // instead. Read/reasoning above are genuine usageMetadata fields. + const cacheCreation = ev.cacheCreationTokenCount ?? ev.cacheCreationTokens ?? 0; + totalCacheCreationTokens += Number(cacheCreation); }); return { 'Prompt Tokens': totalPromptTokens, 'Candidates Tokens': totalCandidatesTokens, 'Cached Content Tokens': totalCachedContentTokens, + 'Cache Creation Tokens': totalCacheCreationTokens, 'Thoughts Tokens': totalThoughtsTokens, 'Total Tokens': totalTokens }; diff --git a/src/app/core/models/types.ts b/src/app/core/models/types.ts index 95b89045..eb46698c 100644 --- a/src/app/core/models/types.ts +++ b/src/app/core/models/types.ts @@ -131,6 +131,10 @@ export declare interface Event extends LlmResponse { inputTranscription?: { text: string; }; outputTranscription?: { text: string; }; usageMetadata?: any; + // Prompt-cache write (creation) tokens. Serialized on the event itself + // rather than inside usageMetadata because google.genai's usage type + // forbids extra fields. + cacheCreationTokenCount?: number; interrupted?: boolean; turnComplete?: boolean; systemInstructionChanged?: boolean;
{{ sessionUsageMetadata()['Cached Content Tokens'] | number }}
Total Cache Creation Tokens{{ sessionUsageMetadata()['Cache Creation Tokens'] | number }}
Total Candidates Tokens {{ sessionUsageMetadata()['Candidates Tokens'] | number }}