Usage

class Usage(val inputTokens: Usage.InputTokenBreakdown = InputTokenBreakdown(), val outputTokens: Usage.OutputTokenBreakdown = OutputTokenBreakdown(), val raw: JsonElement? = null)(source)

Token-usage tracking, surfaced on completed steps and final results. Per historical parity gap #19, the shape mirrors v6's rich tree — input tokens split into noCache / cacheRead / cacheWrite and output tokens split into text / reasoning plus a raw slot for provider-specific payloads.

Provider prompt caching needs explicit cache-hit metrics; before this split there was no surface for cache-hit metrics.

Backwards compatibility. A secondary constructor accepts the old (promptTokens, completionTokens, totalTokens?) shape and maps each value into inputTokens.total / outputTokens.total. Computed properties promptTokens / completionTokens / totalTokens read back from the nested tree so existing accumulators and assertions keep working unchanged.

Constructors

Link copied to clipboard
constructor(inputTokens: Usage.InputTokenBreakdown = InputTokenBreakdown(), outputTokens: Usage.OutputTokenBreakdown = OutputTokenBreakdown(), raw: JsonElement? = null)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class InputTokenBreakdown(val total: Int = 0, val noCache: Int = 0, val cacheRead: Int = 0, val cacheWrite: Int = 0)
Link copied to clipboard
class OutputTokenBreakdown(val total: Int = 0, val text: Int = 0, val reasoning: Int = 0)

Properties

Link copied to clipboard

Legacy flat accessor — outputTokens.total.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Legacy flat accessor — inputTokens.total.

Link copied to clipboard
Link copied to clipboard

Legacy flat accessor — promptTokens + completionTokens.

Functions

Link copied to clipboard
operator fun Usage.plus(other: Usage): Usage