pub struct Usage {
pub input_tokens: Option<u64>,
pub output_tokens: Option<u64>,
pub total_tokens: Option<u64>,
pub cached_input_tokens: Option<u64>,
pub cache_creation_input_tokens: Option<u64>,
pub tool_use_prompt_tokens: Option<u64>,
pub reasoning_tokens: Option<u64>,
}Expand description
The token usage a provider reported for one completion.
Every provider mapping keeps one contract, so the counters read the same way on every provider:
cached_input_tokens + cache_creation_input_tokens <= input_tokens: input counts every prompt token, cache reads and writes included.reasoning_tokens <= output_tokens: output counts every generated token, reasoning included.total_tokens == input_tokens + output_tokens, absent unless both are reported.
A counter the provider did not send is None; a reported zero is
Some(0). Serialized as the same keys, absent when None.
Fields§
§input_tokens: Option<u64>Every input token of the request: uncached, read from a cache, written to a cache, and any prompt a provider’s hosted tools added.
output_tokens: Option<u64>Every output token, reasoning included.
total_tokens: Option<u64>input_tokens + output_tokens; absent unless both are reported.
cached_input_tokens: Option<u64>The part of input_tokens read from a provider-managed cache.
cache_creation_input_tokens: Option<u64>The part of input_tokens written to a provider-managed cache.
tool_use_prompt_tokens: Option<u64>The part of input_tokens a provider’s hosted tools added to the prompt.
reasoning_tokens: Option<u64>The part of output_tokens spent on internal reasoning (“thinking”,
“thoughts”).
Implementations§
Trait Implementations§
Source§impl AddAssign for Usage
impl AddAssign for Usage
Source§fn add_assign(&mut self, other: Usage)
fn add_assign(&mut self, other: Usage)
+= operation. Read moreimpl Copy for Usage
Source§impl<'de> Deserialize<'de> for Usage
impl<'de> Deserialize<'de> for Usage
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Usage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Usage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for Usage
Source§impl From<&Interaction> for Usage
impl From<&Interaction> for Usage
Source§fn from(value: &Interaction) -> Usage
fn from(value: &Interaction) -> Usage
Source§impl From<&InteractionUsage> for Usage
Rig’s input is total_input_tokens plus the tool-use tokens, its
output total_output_tokens plus the thought tokens, and its total
their sum; without a base count, that side and the total stay absent.
impl From<&InteractionUsage> for Usage
Rig’s input is total_input_tokens plus the tool-use tokens, its
output total_output_tokens plus the thought tokens, and its total
their sum; without a base count, that side and the total stay absent.
Source§fn from(value: &InteractionUsage) -> Usage
fn from(value: &InteractionUsage) -> Usage
Source§impl From<&PartialUsage> for Usage
impl From<&PartialUsage> for Usage
Source§fn from(value: &PartialUsage) -> Usage
fn from(value: &PartialUsage) -> Usage
Source§impl From<&ResponsesUsage> for Usage
impl From<&ResponsesUsage> for Usage
Source§fn from(usage: &ResponsesUsage) -> Usage
fn from(usage: &ResponsesUsage) -> Usage
Source§impl From<&StreamingCompletionResponse> for Usage
impl From<&StreamingCompletionResponse> for Usage
Source§fn from(value: &StreamingCompletionResponse) -> Usage
fn from(value: &StreamingCompletionResponse) -> Usage
Source§impl From<&StreamingCompletionResponse> for Usage
impl From<&StreamingCompletionResponse> for Usage
Source§fn from(value: &StreamingCompletionResponse) -> Usage
fn from(value: &StreamingCompletionResponse) -> Usage
Source§impl From<&StreamingCompletionResponse> for Usage
impl From<&StreamingCompletionResponse> for Usage
Source§fn from(response: &StreamingCompletionResponse) -> Usage
fn from(response: &StreamingCompletionResponse) -> Usage
Source§impl From<&StreamingCompletionResponse> for Usage
impl From<&StreamingCompletionResponse> for Usage
Source§fn from(response: &StreamingCompletionResponse) -> Usage
fn from(response: &StreamingCompletionResponse) -> Usage
Source§impl From<&Usage> for Usage
Normalize total token counters, not billed units, which exclude cached input
and system overhead. A total requires both input and output counts.
impl From<&Usage> for Usage
Normalize total token counters, not billed units, which exclude cached input and system overhead. A total requires both input and output counts.
Source§impl From<&UsageMetadata> for Usage
Rig’s input is the prompt plus the tool-use prompt, its output the
candidates plus the thoughts, and its total their sum, which is
totalTokenCount. A count Gemini leaves out is zero, as its JSON omits
zeros (a reply that only thought carries no candidates count).
impl From<&UsageMetadata> for Usage
Rig’s input is the prompt plus the tool-use prompt, its output the
candidates plus the thoughts, and its total their sum, which is
totalTokenCount. A count Gemini leaves out is zero, as its JSON omits
zeros (a reply that only thought carries no candidates count).
Source§fn from(value: &UsageMetadata) -> Usage
fn from(value: &UsageMetadata) -> Usage
Source§impl From<Interaction> for Usage
impl From<Interaction> for Usage
Source§fn from(value: Interaction) -> Usage
fn from(value: Interaction) -> Usage
Source§impl From<InteractionUsage> for Usage
impl From<InteractionUsage> for Usage
Source§fn from(value: InteractionUsage) -> Usage
fn from(value: InteractionUsage) -> Usage
Source§impl From<PartialUsage> for Usage
impl From<PartialUsage> for Usage
Source§fn from(value: PartialUsage) -> Usage
fn from(value: PartialUsage) -> Usage
Source§impl From<ResponsesUsage> for Usage
impl From<ResponsesUsage> for Usage
Source§fn from(usage: ResponsesUsage) -> Usage
fn from(usage: ResponsesUsage) -> Usage
Source§impl From<StreamingCompletionResponse> for Usage
impl From<StreamingCompletionResponse> for Usage
Source§fn from(value: StreamingCompletionResponse) -> Usage
fn from(value: StreamingCompletionResponse) -> Usage
Source§impl From<StreamingCompletionResponse> for Usage
impl From<StreamingCompletionResponse> for Usage
Source§fn from(value: StreamingCompletionResponse) -> Usage
fn from(value: StreamingCompletionResponse) -> Usage
Source§impl Serialize for Usage
impl Serialize for Usage
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 Usage
Auto Trait Implementations§
impl Freeze for Usage
impl RefUnwindSafe for Usage
impl Send for Usage
impl Sync for Usage
impl Unpin for Usage
impl UnsafeUnpin for Usage
impl UnwindSafe for Usage
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
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.