Struct TokenUsage
pub struct TokenUsage {
pub model: String,
pub input_tokens: u64,
pub output_tokens: u64,
pub cached_input_tokens: u64,
pub total_tokens: u64,
pub cost_usd: f64,
pub pricing_available: bool,
pub timestamp: DateTime<Utc>,
}Fields§
§model: StringModel identifier (e.g., “anthropic/claude-sonnet-4-20250514”)
input_tokens: u64Input/prompt tokens
output_tokens: u64Output/completion tokens
cached_input_tokens: u64Cached input tokens (Anthropic cache_read_input_tokens, OpenAI
prompt_tokens_details.cached_tokens). Subset of input_tokens
when reported by the provider; the rate sheet’s
cached_input_per_mtok applies to these.
total_tokens: u64Total tokens (input + output, ignoring the cached subset).
cost_usd: f64Calculated cost in USD
pricing_available: bool§timestamp: DateTime<Utc>Timestamp of the request
Implementations§
Source§impl TokenUsage
impl TokenUsage
pub fn billable_input_tokens(&self) -> u64
pub fn new( model: impl Into<String>, input_tokens: u64, output_tokens: u64, cached_input_tokens: u64, input_price_per_million: f64, output_price_per_million: f64, cached_input_price_per_million: f64, ) -> Self
Trait Implementations§
Source§impl Clone for TokenUsage
impl Clone for TokenUsage
Source§fn clone(&self) -> TokenUsage
fn clone(&self) -> TokenUsage
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · §fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TokenUsage
impl Debug for TokenUsage
Source§impl<'de> Deserialize<'de> for TokenUsage
impl<'de> Deserialize<'de> for TokenUsage
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
Auto Trait Implementations§
impl Freeze for TokenUsage
impl RefUnwindSafe for TokenUsage
impl Send for TokenUsage
impl Sync for TokenUsage
impl Unpin for TokenUsage
impl UnsafeUnpin for TokenUsage
impl UnwindSafe for TokenUsage
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more