pub struct TokenUsage {
pub prompt_tokens: u64,
pub completion_tokens: u64,
pub total_tokens: u64,
pub context_window: u64,
pub cache_read_input_tokens: u64,
pub cache_creation_input_tokens: u64,
}Expand description
Token usage statistics from a model response.
Fields§
§prompt_tokens: u64Number of tokens in the prompt/input.
For providers with prompt caching (Anthropic), this is the
non-cached prefix only — the tokens after the last cache
breakpoint. The cached portion is reported separately in
Self::cache_read_input_tokens / Self::cache_creation_input_tokens,
so the true input total is the sum of all three. Pricing those
three buckets at the same rate over- or under-counts cost; see
crate::outcome::ModelProfile::usd_per_success.
completion_tokens: u64Number of tokens in the completion/output.
total_tokens: u64Total tokens (prompt + completion).
context_window: u64Model’s maximum context window size.
cache_read_input_tokens: u64Prompt-cache hit: input tokens read from a previously written cache
entry. Billed at ~0.1× the base input rate. 0 when the provider
has no prompt caching, caching was disabled, or nothing hit.
(Anthropic usage.cache_read_input_tokens.)
cache_creation_input_tokens: u64Prompt-cache write: input tokens written into the cache this request.
Billed at ~1.25× (5-minute TTL) or ~2× (1-hour TTL) the base input
rate. 0 when caching is off or nothing was written.
(Anthropic usage.cache_creation_input_tokens.)
Trait Implementations§
Source§impl Clone for TokenUsage
impl Clone for TokenUsage
Source§impl Debug for TokenUsage
impl Debug for TokenUsage
Source§impl Default for TokenUsage
impl Default 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>,
Source§impl JsonSchema for TokenUsage
impl JsonSchema for TokenUsage
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read moreAuto 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
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> ErasedDestructor for Twhere
T: 'static,
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> ⓘ
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