Skip to content
providerkit
GitHub

SpeechUsage

Defined in: core/src/speech-core.ts:35

Token counts the provider stated. totalTokens can exceed input plus output: the gap is what the provider counts and does not break out.

cachedInputTokens: number;

Defined in: core/src/types.ts:193

Cache-hit subset of inputTokens. Providers auto-cache repeated prefixes and bill the hit portion far cheaper, so it must be tracked separately to cost a turn correctly. 0 when the provider reports none.

TokenUsage.cachedInputTokens


optional cacheWriteTokens?: number;

Defined in: core/src/types.ts:198

Tokens written to cache, also a subset of inputTokens, so the total stays the whole prompt the window has to hold. Anthropic bills these above the input rate; the OpenAI-shape auto-cachers bill them at it. 0 when not reported.

TokenUsage.cacheWriteTokens


optional contextTokens?: number;

Defined in: core/src/types.ts:232

The prompt of the turn’s LAST model pass, cache included, where the vendor states it (Anthropic’s usage.iterations). A hosted tool loop runs several passes inside one turn and bills their sum, so inputTokens can read far larger than the window ever held. Compaction reads this first.

TokenUsage.contextTokens


optional hostedCalls?: Partial<Record<
| "web_search"
| "web_fetch"
| "code_execution"
| "file_search"
| "image_generation", number>>;

Defined in: core/src/types.ts:225

The hosted tool calls this turn ran, by type: as the vendor states them (Anthropic, OpenRouter), or as the stream showed them. Absent when none ran. Vendors bill these per call, beside the tokens; ModelRate.hosted prices them.

TokenUsage.hostedCalls


inputTokens: number;

Defined in: core/src/types.ts:189

TokenUsage.inputTokens


outputTokens: number;

Defined in: core/src/types.ts:202

TokenUsage.outputTokens


optional reasoningTokens?: number;

Defined in: core/src/types.ts:209

The part of outputTokens spent thinking, when the provider reports it. Already inside outputTokens, so never add it again. It is the number that explains a turn that came back empty with a length finish: the reasoning ate the budget. Anthropic does not report it; absent there.

TokenUsage.reasoningTokens


optional reportedCostUsd?: number;

Defined in: core/src/types.ts:218

What the provider says this call cost, in USD: its bill, not our arithmetic. Only OpenRouter sends one today. It is the one number a rate cannot give, because OpenRouter serves one model id from many hosts at different prices, and only the response knows which host answered. Absent when the provider sent none, or sent one we could not trust. costUsd and UsageTracker bill it over any rate.

TokenUsage.reportedCostUsd


optional toolUsePromptTokens?: number;

Defined in: core/src/types.ts:201

Input tokens added by the provider’s tools, when reported (Gemini). Already included in inputTokens.

TokenUsage.toolUsePromptTokens


optional totalTokens?: number;

Defined in: core/src/speech-core.ts:36