pub struct Usage {
pub input_tokens: u32,
pub output_tokens: u32,
pub cache_read_tokens: Option<u32>,
pub cache_creation_tokens: Option<u32>,
}Expand description
Token usage for one model response.
For every provider, input_tokens is the full, cache-inclusive prompt
size: cache_read_tokens and cache_creation_tokens are subsets of it
(the latter absent for providers that do not report cache writes). So
Usage::total (input + output) is the context-window occupancy.
The cache buckets bill at their own rates, so subtract them before
applying the input rate:
cost = (input - cache_read - cache_creation)·p_in + cache_read·p_cache_read + cache_creation·p_cache_write + output·p_out.
Fields§
§input_tokens: u32Full prompt tokens, cache-inclusive (a superset of the two cache fields).
output_tokens: u32Generated output (completion) tokens.
cache_read_tokens: Option<u32>Subset of input_tokens served from the prompt cache (cheaper rate).
cache_creation_tokens: Option<u32>Subset of input_tokens written into the prompt cache (surcharge rate).
Implementations§
Trait Implementations§
Source§impl AddAssign for Usage
impl AddAssign for Usage
Source§fn add_assign(&mut self, other: Usage)
fn add_assign(&mut self, other: Usage)
+= operation. Read more