pub struct TokenUsage {
pub input_tokens: u64,
pub output_tokens: u64,
pub cache_read_input_tokens: u64,
pub cache_creation_input_tokens: u64,
pub cache_creation_5m_input_tokens: u64,
pub cache_creation_1h_input_tokens: u64,
}Expand description
Normalized usage; fields absent from a provider response default to zero.
Fields§
§input_tokens: u64§output_tokens: u64§cache_read_input_tokens: u64§cache_creation_input_tokens: u64§cache_creation_5m_input_tokens: u64Cache-write tokens billed at the 5-minute TTL rate — a refinement of
cache_creation_input_tokens (which stays the authoritative total),
not a replacement for it. skip_serializing_if keeps a payload with
no per-TTL breakdown byte-identical to one from before this field
existed: this struct is persisted in the session log and serialized
into --json/ACP frames, so a zero bucket must stay invisible on
the wire.
cache_creation_1h_input_tokens: u64Cache-write tokens billed at the 1-hour TTL rate (2x input, vs. 1.25x
for the 5-minute default). See cache_creation_5m_input_tokens.
Implementations§
Source§impl TokenUsage
impl TokenUsage
Sourcepub fn hit_ratio(&self) -> Option<f64>
pub fn hit_ratio(&self) -> Option<f64>
Fraction of prompt tokens (input + cache reads + cache writes) served
from the cache. None when there was no cache activity at all (no
reads, no writes) — that is “nothing to report”, not a 0% hit rate,
so a plain uncached request never shows a misleading 0%. Division
by zero never happens: the guard only lets the divide run once the
denominator has a cache-derived term in it.
Trait Implementations§
Source§impl AddAssign for TokenUsage
impl AddAssign for TokenUsage
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl Clone for TokenUsage
impl Clone for TokenUsage
Source§fn clone(&self) -> TokenUsage
fn clone(&self) -> TokenUsage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more