Skip to main content

ModelUsage

Struct ModelUsage 

Source
#[non_exhaustive]
pub struct ModelUsage { pub input_tokens: usize, pub output_tokens: usize, pub cache_read_tokens: Option<usize>, pub cache_write_tokens: Option<usize>, pub reasoning_tokens: Option<usize>, }
Expand description

Provider-reported token accounting for one model response.

Reports four non-overlapping raw counts with the same meaning across all wire protocols. Any reasoning or thinking tokens are included in Self::output_tokens.

Serializable for logs and tests; the serialized form is not part of the stable set and may change in any release.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§input_tokens: usize

Input tokens that neither hit nor were written to the prompt cache (uncached input).

The meaning is the same across all wire protocols. This count does not overlap with Self::cache_read_tokens, Self::cache_write_tokens, or Self::output_tokens.

§output_tokens: usize

All tokens generated by the model on the output side of the exchange, including any reasoning or thinking tokens.

The meaning is the same across all wire protocols. This count does not overlap with Self::input_tokens, Self::cache_read_tokens, or Self::cache_write_tokens.

§cache_read_tokens: Option<usize>

Tokens read from the prompt cache, if disclosed by the endpoint.

The meaning is the same across all wire protocols. None indicates the endpoint did not report it (never fabricated as 0). This count does not overlap with Self::input_tokens, Self::cache_write_tokens, or Self::output_tokens.

§cache_write_tokens: Option<usize>

Tokens written to the prompt cache, if disclosed by the endpoint.

The meaning is the same across all wire protocols. None indicates the endpoint did not report it (never fabricated as 0). This count does not overlap with Self::input_tokens, Self::cache_read_tokens, or Self::output_tokens.

§reasoning_tokens: Option<usize>

Reasoning or thinking tokens generated by the model, if disclosed by the endpoint.

The meaning is the same across all wire protocols. None indicates the endpoint did not report it. When present, this count is a subset of Self::output_tokens; hosts must not add it to output or total sums.

Implementations§

Source§

impl ModelUsage

Source

pub fn new(input_tokens: usize, output_tokens: usize) -> Self

Usage with the two counts every provider reports (uncached input tokens and total output tokens); the optional counts start undisclosed (None).

Trait Implementations§

Source§

impl Clone for ModelUsage

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelUsage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModelUsage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ModelUsage

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ModelUsage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.