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 moreSource§impl PartialEq for ContextUsage
impl PartialEq for ContextUsage
Source§impl Serialize for ContextUsage
impl Serialize for ContextUsage
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
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>,
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 moreSource§impl<T> IntoMaybeUndefined<T> for T
impl<T> IntoMaybeUndefined<T> for T
fn into_maybe_undefined(self) -> MaybeUndefined<T>
Source§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
fn into_option(self) -> Option<T>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request