pub struct UsageInfo {
pub prompt_tokens: Option<u32>,
pub completion_tokens: Option<u32>,
pub total_tokens: Option<u32>,
pub reasoning_tokens: Option<u32>,
pub cache_read_tokens: Option<u32>,
}Expand description
Token usage information for an LLM call.
Fields§
§prompt_tokens: Option<u32>§completion_tokens: Option<u32>§total_tokens: Option<u32>§reasoning_tokens: Option<u32>Tokens used for reasoning / thinking (DeepSeek, OpenAI o-series, etc.).
Always None on the Anthropic protocol: its usage object has no
thinking breakdown — thinking tokens are folded into
completion_tokens.
cache_read_tokens: Option<u32>Prompt tokens served from the provider’s prefix cache, billed at the
cache-read rate rather than the input rate. Anthropic reports
cache_read_input_tokens; OpenAI reports
prompt_tokens_details.cached_tokens; a protocol whose provider does
not cache reports None. None means “unknown”, never “zero”: a cache
miss and a counter that does not exist look the same from here.
Implementations§
Source§impl UsageInfo
impl UsageInfo
Sourcepub fn merge(&mut self, other: &UsageInfo)
pub fn merge(&mut self, other: &UsageInfo)
Merge a partial usage event into self; the incoming Some field
wins over the existing value, a None leaves it untouched.
Streaming protocols may split usage across several events (Anthropic
sends prompt_tokens in message_start and the final
completion_tokens in message_delta). Replacing the whole struct
on each event would silently zero out fields the last event omits,
so consumers must fold events with this method instead.