pub struct Usage { /* private fields */ }Expand description
Provider-neutral token usage.
Implementations§
Source§impl Usage
impl Usage
Sourcepub const fn new(input_tokens: TokenCount, output_tokens: TokenCount) -> Self
pub const fn new(input_tokens: TokenCount, output_tokens: TokenCount) -> Self
Creates usage with required input and output token counts.
Sourcepub const fn input_tokens(&self) -> TokenCount
pub const fn input_tokens(&self) -> TokenCount
Returns input tokens.
Sourcepub const fn output_tokens(&self) -> TokenCount
pub const fn output_tokens(&self) -> TokenCount
Returns output tokens.
Sourcepub const fn cache_read_tokens(&self) -> Option<TokenCount>
pub const fn cache_read_tokens(&self) -> Option<TokenCount>
Returns cache-read tokens when reported.
Sourcepub const fn cache_write_tokens(&self) -> Option<TokenCount>
pub const fn cache_write_tokens(&self) -> Option<TokenCount>
Returns cache-write tokens when reported.
Sourcepub const fn reasoning_tokens(&self) -> Option<TokenCount>
pub const fn reasoning_tokens(&self) -> Option<TokenCount>
Returns reasoning tokens when reported.
Sourcepub const fn with_cache_read(self, value: TokenCount) -> Self
pub const fn with_cache_read(self, value: TokenCount) -> Self
Adds the cache-read token count.
Sourcepub const fn with_cache_write(self, value: TokenCount) -> Self
pub const fn with_cache_write(self, value: TokenCount) -> Self
Adds the cache-write token count.
Sourcepub fn with_reasoning(self, value: TokenCount) -> Result<Self, UsageError>
pub fn with_reasoning(self, value: TokenCount) -> Result<Self, UsageError>
Adds reasoning tokens, which must be a subset of output tokens.
§Errors
Returns UsageError::ReasoningExceedsOutput when the reasoning count
exceeds the output count.
Sourcepub fn total_tokens(&self) -> Result<TokenCount, UsageError>
pub fn total_tokens(&self) -> Result<TokenCount, UsageError>
Returns the total billable/context token count without double-counting reasoning.
§Errors
Returns UsageError::TotalOverflow when the sum overflows or exceeds
the JSON safe-integer range.
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>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more