pub struct Usage {
pub input_tokens: u64,
pub output_tokens: u64,
pub cache_read_tokens: Option<u64>,
pub cache_creation_tokens: Option<u64>,
pub reasoning_tokens: Option<u64>,
}Expand description
Token accounting parsed from the provider’s terminal usage event.
Fields§
§input_tokens: u64Input (prompt) tokens.
output_tokens: u64Output (completion) tokens.
cache_read_tokens: Option<u64>Tokens served from the prompt cache. None = this wire/provider does
not report the counter; Some(0) = reported as zero (a real signal:
no cache hit). ADR-0009 amendment 2026-07-19 — zero-as-N/A rejected.
cache_creation_tokens: Option<u64>Tokens written to the prompt cache (None on wires that never report
writes, e.g. the OpenAI family).
reasoning_tokens: Option<u64>Reasoning/thinking tokens (None on wires that fold them into
output_tokens, e.g. Anthropic).
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn context_tokens(&self) -> u64
pub fn context_tokens(&self) -> u64
Everything this turn put on the wire and got back: the full prompt (input plus both cache counters) plus the completion.
Both cache counters belong in the total. A cached read and a cache write are prompt tokens that a provider bills differently — they occupy the context window exactly like uncached input, so leaving either out under-reports how full it is.
Trait Implementations§
Source§impl AddAssign for Usage
impl AddAssign for Usage
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Accumulate another turn’s usage field-wise (the engine sums across turns).