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.
Per-call fields (input_tokens, output_tokens, cache_read_tokens,
cache_creation_tokens, reasoning_tokens) come from the most recent
API response. The total_* fields are cumulative across the agent’s
lifetime. The optional fields are None when the provider doesn’t
expose that dimension; this is semantically distinct from Some(0).
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
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
Source§impl<'de> Deserialize<'de> for ContextUsage
impl<'de> Deserialize<'de> for ContextUsage
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ContextUsage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ContextUsage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for ContextUsage
impl JsonSchema for ContextUsage
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 inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more