pub struct TokenCounts {
pub input_tokens: u64,
pub cache_creation_input_tokens: u64,
pub cache_read_input_tokens: u64,
pub output_tokens: u64,
pub reasoning_output_tokens: u64,
pub total_tokens: u64,
pub cost_usd: f64,
}Expand description
Immutable token count snapshot with pre-computed total.
This is the serialisable form of UsageAccumulator, used in report
output (JSON, table rows, etc.). The total_tokens field is eagerly
computed so consumers do not need to sum the components themselves.
Implements Serialize + Deserialize for JSON round-tripping.
Fields§
§input_tokens: u64Fresh (non-cached) prompt tokens.
cache_creation_input_tokens: u64Tokens written to the prompt cache.
cache_read_input_tokens: u64Tokens served from the prompt cache.
output_tokens: u64Model output tokens (includes reasoning tokens unless billed separately).
reasoning_output_tokens: u64Reasoning/chain-of-thought tokens (subset of output).
total_tokens: u64Pre-computed input + cache_creation + cache_read + output.
cost_usd: f64Estimated cost in US dollars.
Implementations§
Source§impl TokenCounts
impl TokenCounts
Sourcepub fn add_assign(&mut self, other: TokenCounts)
pub fn add_assign(&mut self, other: TokenCounts)
Accumulate another TokenCounts into this one (mutable addition).
Trait Implementations§
Source§impl Clone for TokenCounts
impl Clone for TokenCounts
Source§fn clone(&self) -> TokenCounts
fn clone(&self) -> TokenCounts
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TokenCounts
impl Debug for TokenCounts
Source§impl Default for TokenCounts
impl Default for TokenCounts
Source§fn default() -> TokenCounts
fn default() -> TokenCounts
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for TokenCounts
impl<'de> Deserialize<'de> for TokenCounts
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 TokenCounts
impl RefUnwindSafe for TokenCounts
impl Send for TokenCounts
impl Sync for TokenCounts
impl Unpin for TokenCounts
impl UnsafeUnpin for TokenCounts
impl UnwindSafe for TokenCounts
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,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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