pub struct ContextUsage {
pub usage_ratio: Option<f64>,
pub context_limit: Option<u32>,
pub input_tokens: u32,
pub output_tokens: u32,
pub cache_read_tokens: Option<u32>,
pub cache_creation_tokens: Option<u32>,
pub reasoning_tokens: Option<u32>,
pub total_input_tokens: u64,
pub total_output_tokens: u64,
pub total_cache_read_tokens: u64,
pub total_cache_creation_tokens: u64,
pub total_reasoning_tokens: u64,
}Expand description
Context/token usage reported after an LLM call.
Fields§
§usage_ratio: Option<f64>Current usage ratio (0.0 - 1.0), if context window is known.
context_limit: Option<u32>Maximum context limit, if known.
input_tokens: u32Input tokens on the most recent API call (the current context size).
output_tokens: u32Output tokens on the most recent API call.
cache_read_tokens: Option<u32>Prompt tokens served from cache on the most recent API call.
cache_creation_tokens: Option<u32>Prompt tokens written to cache on the most recent API call.
reasoning_tokens: Option<u32>Reasoning tokens spent on the most recent API call.
total_input_tokens: u64Cumulative input tokens since the agent started.
total_output_tokens: u64Cumulative output tokens since the agent started.
total_cache_read_tokens: u64Cumulative cache-read tokens since the agent started.
total_cache_creation_tokens: u64Cumulative cache-creation tokens since the agent started.
total_reasoning_tokens: u64Cumulative reasoning tokens since the agent started.
Implementations§
Source§impl ContextUsage
impl ContextUsage
Sourcepub fn total_tokens(&self) -> u64
pub fn total_tokens(&self) -> u64
Sum of cumulative input + output tokens.
Trait Implementations§
Source§impl Clone for ContextUsage
impl Clone for ContextUsage
Source§fn clone(&self) -> ContextUsage
fn clone(&self) -> ContextUsage
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 ContextUsage
impl Debug for ContextUsage
Source§impl Default for ContextUsage
impl Default for ContextUsage
Source§fn default() -> ContextUsage
fn default() -> ContextUsage
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for ContextUsage
impl<'de> Deserialize<'de> for ContextUsage
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
Source§impl JsonSchema for ContextUsage
impl JsonSchema for ContextUsage
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 ContextUsage
impl PartialEq for ContextUsage
Source§fn eq(&self, other: &ContextUsage) -> bool
fn eq(&self, other: &ContextUsage) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for ContextUsage
impl Serialize for ContextUsage
impl StructuralPartialEq for ContextUsage
Auto Trait Implementations§
impl Freeze for ContextUsage
impl RefUnwindSafe for ContextUsage
impl Send for ContextUsage
impl Sync for ContextUsage
impl Unpin for ContextUsage
impl UnsafeUnpin for ContextUsage
impl UnwindSafe for ContextUsage
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