feat: track cache tokens for accurate cost reporting (#9752)

Signed-off-by: Filip Kujawa <filip.j.kujawa@gmail.com>
Signed-off-by: Douwe M Osinga <douwe@sidewalklabs.com>
Signed-off-by: Douwe Osinga <douwe@sidewalklabs.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Douwe M Osinga <douwe@sidewalklabs.com>
This commit is contained in:
filip
2026-06-19 06:56:15 -07:00
committed by GitHub
parent e6da0c6a14
commit 093d134b0a
42 changed files with 1175 additions and 660 deletions
File diff suppressed because one or more lines are too long
+24 -6
View File
@@ -1364,28 +1364,24 @@ export type ScheduledJob = {
export type Session = {
accumulated_cost?: number | null;
accumulated_input_tokens?: number | null;
accumulated_output_tokens?: number | null;
accumulated_total_tokens?: number | null;
accumulated_usage?: Usage;
archived_at?: string | null;
conversation?: Conversation | null;
created_at: string;
extension_data: ExtensionData;
goose_mode?: GooseMode;
id: string;
input_tokens?: number | null;
last_message_snippet?: string | null;
message_count: number;
model_config?: ModelConfig | null;
name: string;
output_tokens?: number | null;
project_id?: string | null;
provider_name?: string | null;
recipe?: Recipe | null;
schedule_id?: string | null;
session_type?: SessionType;
total_tokens?: number | null;
updated_at: string;
usage?: Usage;
user_recipe_values?: {
[key: string]: string;
} | null;
@@ -1563,10 +1559,14 @@ export type ThinkingContent = {
export type ThinkingEffort = 'off' | 'low' | 'medium' | 'high' | 'max';
export type TokenState = {
accumulatedCacheReadTokens?: number;
accumulatedCacheWriteTokens?: number;
accumulatedCost?: number | null;
accumulatedInputTokens: number;
accumulatedOutputTokens: number;
accumulatedTotalTokens: number;
cacheReadTokens?: number;
cacheWriteTokens?: number;
inputTokens: number;
outputTokens: number;
totalTokens: number;
@@ -1776,6 +1776,24 @@ export type UpsertPermissionsQuery = {
tool_permissions: Array<ToolPermission>;
};
/**
* `input_tokens` is the total input including cache read/write tokens;
* the cache fields are breakdown subsets of it. Parsers for providers
* that report cache tokens separately from input (e.g. Anthropic,
* Bedrock) must fold them into `input_tokens`.
*/
export type Usage = {
cache_read_input_tokens?: number | null;
cache_write_input_tokens?: number | null;
/**
* All prompt tokens, including any served from or written to cache.
* `cache_read_input_tokens` and `cache_write_input_tokens` are subsets of this.
*/
input_tokens?: number | null;
output_tokens?: number | null;
total_tokens?: number | null;
};
export type WhisperModelResponse = {
/**
* Description