pub struct TokenUsage {
pub input: u64,
pub cache_write_5m: u64,
pub cache_write_1h: u64,
pub cache_read: u64,
pub output: u64,
}Expand description
Token counts, split the way the Anthropic and OpenAI usage objects split them.
Fields§
§input: u64§cache_write_5m: u64§cache_write_1h: u64§cache_read: u64§output: u64Implementations§
Source§impl TokenUsage
impl TokenUsage
pub fn cache_write(&self) -> u64
Sourcepub fn total(&self) -> u64
pub fn total(&self) -> u64
Everything the model consumed or produced. This is the “TOKENS” column.
Sourcepub fn prompt(&self) -> u64
pub fn prompt(&self) -> u64
The input side: everything sent to the model as the prompt, fresh input plus cache writes plus cache reads, but not the output it produced.
Sourcepub fn cache_hit_rate(&self) -> Option<f64>
pub fn cache_hit_rate(&self) -> Option<f64>
The share of the prompt served from cache (the cheap reads), in 0..=1.
A high number means most of the re-sent conversation was billed at the
cache-read rate rather than full input; a low one on a long session is
money left on the table. None when there was no prompt to judge, or
the model does not cache at all.
pub fn add(&mut self, other: &TokenUsage)
pub fn sub(&mut self, other: &TokenUsage)
Trait Implementations§
Source§impl Clone for TokenUsage
impl Clone for TokenUsage
Source§fn clone(&self) -> TokenUsage
fn clone(&self) -> TokenUsage
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for TokenUsage
Source§impl Debug for TokenUsage
impl Debug for TokenUsage
Source§impl Default for TokenUsage
impl Default for TokenUsage
Source§fn default() -> TokenUsage
fn default() -> TokenUsage
Returns the “default value” for a type. Read more
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§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 Freeze 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§
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