pub struct UsageMetadata {
pub prompt_token_count: Option<i32>,
pub cached_content_token_count: Option<i32>,
pub candidates_token_count: Option<i32>,
pub thoughts_token_count: Option<i32>,
pub total_token_count: Option<i32>,
}Expand description
Token usage statistics from the backend.
Fields§
§prompt_token_count: Option<i32>Tokens in the prompt.
cached_content_token_count: Option<i32>Tokens served from cache.
candidates_token_count: Option<i32>Tokens in the model’s response.
thoughts_token_count: Option<i32>Tokens used for chain-of-thought reasoning.
total_token_count: Option<i32>Total tokens (prompt + response + thoughts).
Implementations§
Source§impl UsageMetadata
impl UsageMetadata
Sourcepub fn merge_round(&mut self, other: &UsageMetadata)
pub fn merge_round(&mut self, other: &UsageMetadata)
Fold a SUCCESSIVE ROUND of the SAME turn into self — the per-turn
accumulator the backend loops use. prompt_token_count /
cached_content_token_count describe the LIVE CONTEXT SIZE, which the
model reports afresh each round of a multi-round tool turn, so they
take the LATEST value (summing them quadruple-counted the context on a
4-round turn, made the context-fullness bar “fluctuate wildly”, and
fired auto-compaction early — on-chain feedback #73). Output-side
counts (candidates / thoughts / total) are genuinely cumulative
and sum. For cross-turn billing-style totals use Self::accumulate.
Sourcepub fn accumulate(&mut self, other: &UsageMetadata)
pub fn accumulate(&mut self, other: &UsageMetadata)
Fold other into self, summing EVERY field — the cross-turn
billing-style accumulator (Conversation::cumulative_usage). Missing
fields on either side are treated as zero so the accumulator only
advances when the backend reports usage.
Trait Implementations§
Source§impl Clone for UsageMetadata
impl Clone for UsageMetadata
Source§fn clone(&self) -> UsageMetadata
fn clone(&self) -> UsageMetadata
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 UsageMetadata
impl Debug for UsageMetadata
Source§impl Default for UsageMetadata
impl Default for UsageMetadata
Source§fn default() -> UsageMetadata
fn default() -> UsageMetadata
Source§impl<'de> Deserialize<'de> for UsageMetadata
impl<'de> Deserialize<'de> for UsageMetadata
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 UsageMetadata
Source§impl PartialEq for UsageMetadata
impl PartialEq for UsageMetadata
Source§fn eq(&self, other: &UsageMetadata) -> bool
fn eq(&self, other: &UsageMetadata) -> bool
self and other values to be equal, and is used by ==.