pub struct Usage {
pub input_tokens: u64,
pub output_tokens: u64,
pub cache_read_input_tokens: u64,
pub cache_creation_input_tokens: u64,
}Expand description
Token accounting for a request/response pair.
Counts are cumulative within a single stream. A turn folds these across
every provider call its tool-calling loop makes; the folded total is what
polychrome_turn_prompt_tokens_total{token_kind} (polyc-agent’s
per-turn prompt-cache-effectiveness counter, #1299) surfaces — this
per-call struct itself is not exported to Prometheus directly.
Fields§
§input_tokens: u64Tokens consumed by the prompt (system + messages + tools).
output_tokens: u64Tokens produced by the model.
cache_read_input_tokens: u64Prompt tokens served from the provider’s cache — the portion of
input_tokens a cached stable prefix satisfied, so
this is a SUBSET of input_tokens, not an addition to it. The Phase 0
exit metric (prompt-cache hit rate) is this over input_tokens. Zero when
the provider reports no cache read or has no caching.
cache_creation_input_tokens: u64Prompt tokens the provider wrote INTO its cache on this call (a
cache-creation / cache-write count), when the provider distinguishes them
from a cache read. Also a subset of input_tokens. Zero when the provider
reports no cache write or does not surface the count.
Implementations§
Source§impl Usage
impl Usage
Sourcepub const fn total_tokens(self) -> u64
pub const fn total_tokens(self) -> u64
Total tokens billed for this exchange (input_tokens + output_tokens).
Saturates rather than overflowing; real responses never approach
u64::MAX, but the arithmetic is total so callers need no guard. The
cache counts are subsets of input_tokens, so they are NOT added in.
Trait Implementations§
Source§impl AddAssign for Usage
impl AddAssign for Usage
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Folds other into self, field by field — every field named
explicitly, never a ..Default::default() spread (which would
silently leave a newly-added field un-summed instead of failing to
compile when one side gains a field; see #1241/#1238). The single
canonical accumulation every caller across the workspace should use
instead of hand-rolling the same four-field fold at each call site.