pub struct UsageInfo {
pub prompt_tokens: Option<u32>,
pub completion_tokens: Option<u32>,
pub total_tokens: Option<u32>,
pub reasoning_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.
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UsageInfo
impl RefUnwindSafe for UsageInfo
impl Send for UsageInfo
impl Sync for UsageInfo
impl Unpin for UsageInfo
impl UnsafeUnpin for UsageInfo
impl UnwindSafe for UsageInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more