pub struct UsageAccumulator {
pub total_prompt_tokens: u64,
pub total_completion_tokens: u64,
pub total_tokens: u64,
pub total_cost_usd: f64,
pub call_count: u64,
}Expand description
Accumulates token usage and cost across multiple LLM calls
Fields§
§total_prompt_tokens: u64Total prompt tokens across all calls
total_completion_tokens: u64Total completion tokens across all calls
total_tokens: u64Total tokens across all calls
total_cost_usd: f64Total cost across all calls (USD)
call_count: u64Number of LLM calls made
Implementations§
Source§impl UsageAccumulator
impl UsageAccumulator
Sourcepub fn add(&mut self, usage: &TokenUsage, cost: f64)
pub fn add(&mut self, usage: &TokenUsage, cost: f64)
Add usage from a single call
Sourcepub fn add_with_pricing(&mut self, usage: &TokenUsage, pricing: &ModelPricing)
pub fn add_with_pricing(&mut self, usage: &TokenUsage, pricing: &ModelPricing)
Add usage with automatic cost calculation
Sourcepub fn add_for_model(&mut self, usage: &TokenUsage, model: &str)
pub fn add_for_model(&mut self, usage: &TokenUsage, model: &str)
Add usage with model-based pricing
Sourcepub fn avg_tokens_per_call(&self) -> f64
pub fn avg_tokens_per_call(&self) -> f64
Get average tokens per call
Sourcepub fn avg_cost_per_call(&self) -> f64
pub fn avg_cost_per_call(&self) -> f64
Get average cost per call
Trait Implementations§
Source§impl Clone for UsageAccumulator
impl Clone for UsageAccumulator
Source§fn clone(&self) -> UsageAccumulator
fn clone(&self) -> UsageAccumulator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UsageAccumulator
impl Debug for UsageAccumulator
Source§impl Default for UsageAccumulator
impl Default for UsageAccumulator
Source§fn default() -> UsageAccumulator
fn default() -> UsageAccumulator
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for UsageAccumulator
impl RefUnwindSafe for UsageAccumulator
impl Send for UsageAccumulator
impl Sync for UsageAccumulator
impl Unpin for UsageAccumulator
impl UnsafeUnpin for UsageAccumulator
impl UnwindSafe for UsageAccumulator
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