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 timestamp: DateTime<Utc>,
}Expand description
Token usage information from a single API call.
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
timestamp: DateTime<Utc>Timestamp of the request
Implementations§
Source§impl TokenUsage
impl TokenUsage
Sourcepub 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
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
Create a new token usage record. Cached input tokens are billed at
cached_input_price_per_million; the rest of input_tokens at the
standard input_price_per_million. When cached_input_price is 0
the cached subset bills at the standard rate (no discount), so
providers that don’t surface a cached rate still produce a sane
total.
Trait Implementations§
Source§impl Clone for TokenUsage
impl Clone for TokenUsage
Source§fn clone(&self) -> TokenUsage
fn clone(&self) -> TokenUsage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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>,
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
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>
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>
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