Struct TokenUsage
pub struct TokenUsage {
pub model: String,
pub input_tokens: u64,
pub output_tokens: u64,
pub cached_input_tokens: u64,
pub cache_creation_input_tokens: u64,
pub total_tokens: u64,
pub cost_usd: f64,
pub unpriced_tokens: u64,
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.
cache_creation_input_tokens: u64Cache-write tokens (Anthropic cache_creation_input_tokens,
OpenAI-compatible prompt_tokens_details.cache_creation_input_tokens).
Subset of the uncached input that the provider wrote into its prompt
cache on this request; the rate sheet’s cache_write_per_mtok applies
to these when set, otherwise they stay priced at the plain input rate.
total_tokens: u64Total tokens (input + output, ignoring the cached subset).
cost_usd: f64Calculated cost in USD
unpriced_tokens: u64Token-bearing dimensions that had no valid resolved price when this
record was created. This is the canonical exposure count for new rows;
pricing_available remains as a compatibility projection for older
ledgers written before dimension-level provenance existed.
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, ) -> TokenUsage
Sourcepub fn new_with_cache(
model: impl Into<String>,
input_tokens: u64,
cached_input_tokens: u64,
output_tokens: u64,
input_price_per_million: f64,
cached_input_price_per_million: f64,
output_price_per_million: f64,
) -> TokenUsage
pub fn new_with_cache( model: impl Into<String>, input_tokens: u64, cached_input_tokens: u64, output_tokens: u64, input_price_per_million: f64, cached_input_price_per_million: f64, output_price_per_million: f64, ) -> TokenUsage
Create a new token usage record with cache-aware input pricing.
Sourcepub fn new_with_cache_write(
model: impl Into<String>,
input_tokens: u64,
cached_input_tokens: u64,
cache_creation_input_tokens: u64,
output_tokens: u64,
input_price_per_million: f64,
cached_input_price_per_million: f64,
cache_write_price_per_million: f64,
output_price_per_million: f64,
) -> TokenUsage
pub fn new_with_cache_write( model: impl Into<String>, input_tokens: u64, cached_input_tokens: u64, cache_creation_input_tokens: u64, output_tokens: u64, input_price_per_million: f64, cached_input_price_per_million: f64, cache_write_price_per_million: f64, output_price_per_million: f64, ) -> TokenUsage
Create a new token usage record that also prices the cache-write
band: cache_creation_input_tokens at cache_write_price_per_million.
A non-positive write rate keeps the historical behavior — cache
writes stay inside the plain uncached-input band at the input rate —
so sheets without a write rate reproduce yesterday’s totals exactly.
Trait Implementations§
Source§impl Clone for TokenUsage
impl Clone for TokenUsage
Source§fn clone(&self) -> TokenUsage
fn clone(&self) -> TokenUsage
1.0.0 (const: unstable) · §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<TokenUsage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<TokenUsage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for TokenUsage
impl Serialize for TokenUsage
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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