#[non_exhaustive]pub struct RunUsage {
pub reported_attempts: usize,
pub input_tokens: u64,
pub cached_input_tokens: u64,
pub cache_write_input_tokens: u64,
pub output_tokens: u64,
pub by_model: BTreeMap<String, TokenUsage>,
pub overflowed: bool,
}Expand description
Cumulative token usage across every provider response in one materialization run.
Providers normally use one model for the whole run, but by_model preserves
accounting if a provider reports different concrete model versions across
retries. Keys use the response’s model identifier when present and the
configured model as a fallback.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.reported_attempts: usizeNumber of attempts whose provider response included token usage.
This can be lower than the number of attempts when a transport error occurs or a provider omits usage metadata.
input_tokens: u64Cumulative input tokens across all reported responses.
cached_input_tokens: u64Cumulative input tokens served from provider prompt caches.
This is a subset of input_tokens.
cache_write_input_tokens: u64Cumulative input tokens written to provider prompt caches.
This is a subset of input_tokens.
output_tokens: u64Cumulative output tokens across all reported responses.
by_model: BTreeMap<String, TokenUsage>Cumulative usage grouped by reported model, or configured-model fallback.
overflowed: boolWhether any cumulative counter exceeded its representable range.
When this is true, affected counters and total_tokens() saturate at
their maximum value rather than panicking or wrapping.
Implementations§
Source§impl RunUsage
impl RunUsage
Sourcepub fn from_response(usage: TokenUsage) -> Self
pub fn from_response(usage: TokenUsage) -> Self
Create cumulative usage from one provider response.
Sourcepub fn record(&mut self, usage: TokenUsage)
pub fn record(&mut self, usage: TokenUsage)
Add one provider response to the cumulative totals.
Sourcepub fn total_tokens(&self) -> u64
pub fn total_tokens(&self) -> u64
Total known tokens used across the run.