pub struct ModelUsage {
pub input_tokens: u64,
pub cached_input_tokens: Option<u64>,
pub output_tokens: u64,
pub reasoning_output_tokens: Option<u64>,
pub total_tokens: u64,
}Expand description
Token usage reported by a model provider for one response.
Fields§
§input_tokens: u64§cached_input_tokens: Option<u64>§output_tokens: u64§reasoning_output_tokens: Option<u64>§total_tokens: u64Implementations§
Source§impl ModelUsage
impl ModelUsage
Sourcepub fn new(input_tokens: u64, output_tokens: u64) -> Self
pub fn new(input_tokens: u64, output_tokens: u64) -> Self
Creates usage with no optional provider sub-counts.
Sourcepub const fn with_details(
input_tokens: u64,
cached_input_tokens: Option<u64>,
output_tokens: u64,
reasoning_output_tokens: Option<u64>,
total_tokens: u64,
) -> Self
pub const fn with_details( input_tokens: u64, cached_input_tokens: Option<u64>, output_tokens: u64, reasoning_output_tokens: Option<u64>, total_tokens: u64, ) -> Self
Creates usage from provider-reported counts.
Sourcepub const fn input_tokens(&self) -> u64
pub const fn input_tokens(&self) -> u64
Input token count.
Sourcepub const fn cached_input_tokens(&self) -> Option<u64>
pub const fn cached_input_tokens(&self) -> Option<u64>
Cached input token count if the provider reported it.
Sourcepub const fn output_tokens(&self) -> u64
pub const fn output_tokens(&self) -> u64
Output token count.
Sourcepub const fn reasoning_output_tokens(&self) -> Option<u64>
pub const fn reasoning_output_tokens(&self) -> Option<u64>
Reasoning output token count if the provider reported it.
Sourcepub const fn total_tokens(&self) -> u64
pub const fn total_tokens(&self) -> u64
Provider-reported or provider-derived total token count.
Sourcepub fn checked_add(self, other: Self) -> Option<Self>
pub fn checked_add(self, other: Self) -> Option<Self>
Returns the checked sum of two usage values.
Trait Implementations§
Source§impl Clone for ModelUsage
impl Clone for ModelUsage
impl Copy for ModelUsage
Source§impl Debug for ModelUsage
impl Debug for ModelUsage
Source§impl<'de> Deserialize<'de> for ModelUsage
impl<'de> Deserialize<'de> for ModelUsage
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
impl Eq for ModelUsage
Source§impl JsonSchema for ModelUsage
impl JsonSchema for ModelUsage
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreSource§impl PartialEq for ModelUsage
impl PartialEq for ModelUsage
Source§impl Serialize for ModelUsage
impl Serialize for ModelUsage
impl StructuralPartialEq for ModelUsage
Auto Trait Implementations§
impl Forget for ModelUsage
impl Freeze for ModelUsage
impl Move for ModelUsage
impl RefUnwindSafe for ModelUsage
impl Send for ModelUsage
impl Sync for ModelUsage
impl Unpin for ModelUsage
impl UnsafeUnpin for ModelUsage
impl UnwindSafe for ModelUsage
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