pub struct Usage {
pub input_tokens: u64,
pub output_tokens: u64,
pub cached_input_tokens: u64,
}Expand description
Three-field token usage as returned by Gemini’s usageMetadata.
Gemini reports promptTokenCount as including cached content
tokens, so the Usage::from_gemini constructor subtracts
cachedContentTokenCount from promptTokenCount to get the fresh
input count this struct expects.
Fields§
§input_tokens: u64Fresh input/prompt tokens (not served from the context cache).
output_tokens: u64Output / candidate tokens.
cached_input_tokens: u64Input tokens that were served from a context cache (cache hit).
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn total_tokens(&self) -> u64
pub fn total_tokens(&self) -> u64
Total tokens billed (input + output + cached_input).
Sourcepub fn from_gemini(
prompt_token_count: u64,
candidates_token_count: u64,
cached_content_token_count: u64,
) -> Self
pub fn from_gemini( prompt_token_count: u64, candidates_token_count: u64, cached_content_token_count: u64, ) -> Self
Build a Usage from a Gemini usageMetadata payload.
prompt_token_count includes cached tokens on the wire; this
constructor subtracts them so the struct’s fields are disjoint.
Trait Implementations§
impl Copy for Usage
impl Eq for Usage
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
Mutably borrows from an owned value. Read more