pub struct Usage {
pub prompt_tokens: Option<u32>,
pub completion_tokens: Option<u32>,
pub total_tokens: Option<u32>,
pub prompt_tokens_details: Option<PromptTokensDetails>,
}Expand description
Token usage statistics. Notes:
total_tokens≈prompt_tokens+completion_tokens.- Some providers omit
usagein streaming chunks; expect it mainly in the final response. prompt_tokens_details.cached_tokensoften indicates KV-cache hits or reused tokens.
Fields§
§prompt_tokens: Option<u32>Number of tokens in the prompt.
completion_tokens: Option<u32>Number of tokens in the completion.
total_tokens: Option<u32>Total tokens for this request (prompt + completion).
prompt_tokens_details: Option<PromptTokensDetails>Details for prompt tokens (e.g., cached tokens count)
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn prompt_tokens(&self) -> Option<u32>
pub fn prompt_tokens(&self) -> Option<u32>
Number of prompt tokens.
Sourcepub fn completion_tokens(&self) -> Option<u32>
pub fn completion_tokens(&self) -> Option<u32>
Number of completion tokens.
Sourcepub fn total_tokens(&self) -> Option<u32>
pub fn total_tokens(&self) -> Option<u32>
Total tokens for this request.
Sourcepub fn prompt_tokens_details(&self) -> Option<&PromptTokensDetails>
pub fn prompt_tokens_details(&self) -> Option<&PromptTokensDetails>
Breakdown of prompt-token accounting.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Usage
impl<'de> Deserialize<'de> for Usage
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'v_a> ValidateArgs<'v_a> for Usage
impl<'v_a> ValidateArgs<'v_a> 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
Mutably borrows from an owned value. Read more