pub struct Usage {
pub requests: u64,
pub input_tokens: u64,
pub cache_write_tokens: u64,
pub cache_write_1h_tokens: u64,
pub cache_read_tokens: u64,
pub output_tokens: u64,
pub total_tokens: u64,
pub tool_calls: u64,
}Expand description
Token and request usage accumulated by model and runtime layers.
Fields§
§requests: u64Number of provider requests.
input_tokens: u64Input or prompt tokens.
Provider adapters should normalize this as total provider-billed input tokens for the request, including cache-write and cache-read tokens when those subtotals are present. Pricing helpers subtract the cache subtotals before applying cache-specific rates.
cache_write_tokens: u64Provider-reported total tokens written to a prompt cache across all durations.
Use Self::effective_cache_write_tokens for derived accounting because
externally constructed or deserialized usage may contain inconsistent counters.
cache_write_1h_tokens: u64Provider-reported one-hour cache writes included in Self::cache_write_tokens.
Providers without a one-hour cache-write breakdown leave this at zero. Use
Self::effective_cache_write_1h_tokens for derived accounting.
cache_read_tokens: u64Tokens read from a provider prompt cache.
output_tokens: u64Output or completion tokens.
total_tokens: u64Total tokens.
tool_calls: u64Number of successful function tool calls executed by the runtime.
Implementations§
Source§impl Usage
impl Usage
Sourcepub const fn effective_cache_write_tokens(&self) -> u64
pub const fn effective_cache_write_tokens(&self) -> u64
Return the effective aggregate cache-write tokens for derived accounting.
Provider counters remain raw evidence. This projection repairs a one-hour subset larger than the reported aggregate, then caps writes at the inclusive input total so malformed counters cannot create additional billed tokens.
Sourcepub const fn effective_cache_write_1h_tokens(&self) -> u64
pub const fn effective_cache_write_1h_tokens(&self) -> u64
Return effective one-hour cache-write tokens for derived accounting.
Sourcepub const fn effective_cache_read_tokens(&self) -> u64
pub const fn effective_cache_read_tokens(&self) -> u64
Return effective cache-read tokens for derived accounting.
Cache writes take precedence when malformed write and read subtotals exceed inclusive input. Reads are capped at the input remaining after effective writes.
Sourcepub const fn effective_standard_input_tokens(&self) -> u64
pub const fn effective_standard_input_tokens(&self) -> u64
Return input tokens not assigned to an effective cache-write or read category.
Sourcepub const fn add_assign(&mut self, other: &Self)
pub const fn add_assign(&mut self, other: &Self)
Add another usage value into this one.
Sourcepub const fn with_additional_tool_calls(self, tool_calls: u64) -> Self
pub const fn with_additional_tool_calls(self, tool_calls: u64) -> Self
Return a copy with additional successful tool calls applied.