#[non_exhaustive]pub struct Usage {
pub input_tokens: u32,
pub output_tokens: u32,
pub cached_input_tokens: u32,
pub cache_creation_input_tokens: u32,
pub reasoning_tokens: u32,
pub safety_ratings: Vec<SafetyRating>,
}Expand description
Per-call accounting from the vendor.
Token fields are u32 with default 0 — every shipping codec
populates them, and 0 is the natural “no cache hit” /
“no reasoning” value. Whether the field is meaningful for the
(codec, model) pair is governed by Capabilities
flags, not by an option/null distinction here.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.input_tokens: u32Tokens consumed from the prompt this call.
output_tokens: u32Tokens produced as output (assistant content).
cached_input_tokens: u32Tokens served from the prompt cache (typically discounted).
cache_creation_input_tokens: u32Tokens written to the prompt cache (typically billed at a premium).
reasoning_tokens: u32Tokens spent on internal reasoning (Anthropic thinking, OpenAI o-series reasoning, Gemini thinking budget).
safety_ratings: Vec<SafetyRating>Per-category safety scores reported by the vendor (Gemini today; empty otherwise).
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn new(input_tokens: u32, output_tokens: u32) -> Self
pub fn new(input_tokens: u32, output_tokens: u32) -> Self
Construct a Usage from the two universally-populated token
counts; cache, reasoning, and safety fields stay at their
defaults (0 / Vec::new()). Use the with_* setters to
override the rest.
Sourcepub const fn with_cached_input_tokens(self, tokens: u32) -> Self
pub const fn with_cached_input_tokens(self, tokens: u32) -> Self
Override cached_input_tokens (prompt-cache reads).
Sourcepub const fn with_cache_creation_input_tokens(self, tokens: u32) -> Self
pub const fn with_cache_creation_input_tokens(self, tokens: u32) -> Self
Override cache_creation_input_tokens (prompt-cache writes).
Sourcepub const fn with_reasoning_tokens(self, tokens: u32) -> Self
pub const fn with_reasoning_tokens(self, tokens: u32) -> Self
Override reasoning_tokens (Anthropic thinking, OpenAI o-series
reasoning, Gemini thinking budget).
Sourcepub fn with_safety_ratings(self, ratings: Vec<SafetyRating>) -> Self
pub fn with_safety_ratings(self, ratings: Vec<SafetyRating>) -> Self
Attach the vendor-reported per-category safety ratings.
Sourcepub const fn billable_input(&self) -> u32
pub const fn billable_input(&self) -> u32
Billable input tokens — fresh prompt input plus cache writes (which vendors typically charge at a premium). Cache reads are excluded because vendors discount them, often heavily.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Usage
impl<'de> Deserialize<'de> for Usage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Usage
impl StructuralPartialEq for Usage
Auto Trait Implementations§
impl Freeze for Usage
impl RefUnwindSafe for Usage
impl Send for Usage
impl Sync for Usage
impl Unpin for Usage
impl UnsafeUnpin for Usage
impl UnwindSafe for Usage
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.