pub struct TokenUsage {
pub provider: Option<String>,
pub model: Option<String>,
pub input_tokens: Option<u64>,
pub output_tokens: Option<u64>,
pub total_tokens: Option<u64>,
pub reasoning_tokens: Option<u64>,
pub cached_input_tokens: Option<u64>,
pub cache_write_input_tokens: Option<u64>,
}Expand description
A numeric-only token usage summary for one (provider, model) pair.
Deliberately carries nothing identifying or content-bearing — no prompts, completions, message text, or thread/run/user ids. Only provider and model labels plus counts, so usage can be logged and aggregated in places where conversation content must not go.
Every count is optional and every count is a non-negative integer: None
means the provider did not report it, which is distinct from zero.
Fields§
§provider: Option<String>The inference provider, for example "anthropic".
model: Option<String>The model id, for example "claude-opus-5".
input_tokens: Option<u64>Tokens consumed by the prompt.
output_tokens: Option<u64>Tokens produced by the model.
total_tokens: Option<u64>Input plus output tokens under the protocol’s accounting. Cache and reasoning counts are already included in those totals.
reasoning_tokens: Option<u64>Output tokens spent on reasoning.
cached_input_tokens: Option<u64>Input tokens served from the provider’s prompt cache.
cache_write_input_tokens: Option<u64>Input tokens written to the provider’s prompt cache. Part of
input_tokens, disjoint from cached_input_tokens.
Implementations§
Source§impl TokenUsage
impl TokenUsage
Sourcepub const fn has_counts(&self) -> bool
pub const fn has_counts(&self) -> bool
Whether any count is present. A labels-only entry reports nothing and should be omitted rather than emitted.
Trait Implementations§
Source§impl Clone for TokenUsage
impl Clone for TokenUsage
Source§impl ComposeSchema for TokenUsage
Available on crate feature utoipa only.
impl ComposeSchema for TokenUsage
utoipa only.Source§impl Debug for TokenUsage
impl Debug for TokenUsage
Source§impl Default for TokenUsage
impl Default for TokenUsage
Source§impl<'de> Deserialize<'de> for TokenUsage
impl<'de> Deserialize<'de> for TokenUsage
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>,
impl Eq for TokenUsage
Source§impl JsonSchema for TokenUsage
Available on crate feature schemars only.
impl JsonSchema for TokenUsage
schemars only.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 TokenUsage
impl PartialEq for TokenUsage
Source§impl Serialize for TokenUsage
impl Serialize for TokenUsage
impl StructuralPartialEq for TokenUsage
Auto Trait Implementations§
impl Forget for TokenUsage
impl Freeze for TokenUsage
impl Move for TokenUsage
impl RefUnwindSafe for TokenUsage
impl Send for TokenUsage
impl Sync for TokenUsage
impl Unpin for TokenUsage
impl UnsafeUnpin for TokenUsage
impl UnwindSafe for TokenUsage
Blanket Implementations§
impl<T> AgentState for T
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
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.