pub struct TokenUsage {
pub input_tokens: u64,
pub output_tokens: u64,
pub cache_creation_input_tokens: u64,
pub cache_read_input_tokens: u64,
pub cache_creation: Option<CacheCreation>,
pub service_tier: Option<String>,
}Expand description
Token usage with granular cache tracking
Captures detailed token usage for cost analysis.
Fields§
§input_tokens: u64Input tokens (new prompt tokens)
output_tokens: u64Output tokens (response tokens)
cache_creation_input_tokens: u64Cache creation tokens (tokens added to cache, 25% more expensive)
cache_read_input_tokens: u64Cache read tokens (tokens read from cache, 90% discount)
cache_creation: Option<CacheCreation>Cache creation details
service_tier: Option<String>Service tier (for pricing)
Implementations§
Source§impl TokenUsage
impl TokenUsage
Sourcepub fn total_input(&self) -> u64
pub fn total_input(&self) -> u64
Total input including cache operations
Sourcepub fn effective_input(&self) -> f64
pub fn effective_input(&self) -> f64
Effective input tokens with cache discount (90% for reads)
Sourcepub fn calculate_cost(&self, model: &str) -> Option<f64>
pub fn calculate_cost(&self, model: &str) -> Option<f64>
Calculate cost in USD based on model pricing
Sourcepub fn format_cost(&self, model: &str) -> String
pub fn format_cost(&self, model: &str) -> String
Format cost as human-readable string
Sourcepub fn estimated_cost(&self) -> f64
👎Deprecated since 0.1.0: Use calculate_cost(model) instead
pub fn estimated_cost(&self) -> f64
Use calculate_cost(model) instead
Calculate approximate cost (deprecated)
Trait Implementations§
Source§impl Clone for TokenUsage
impl Clone for TokenUsage
Source§impl Debug for TokenUsage
impl Debug for TokenUsage
Source§impl Default for TokenUsage
impl Default for TokenUsage
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
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