pub struct CostTrackingCallback { /* private fields */ }Expand description
Callback handler that tracks token usage and estimated cost across model calls.
Supports per-model pricing tables and optional budget limits. Query the
accumulated snapshot via snapshot().
Implementations§
Source§impl CostTrackingCallback
impl CostTrackingCallback
Sourcepub fn new(pricing: HashMap<String, ModelPricing>) -> Self
pub fn new(pricing: HashMap<String, ModelPricing>) -> Self
Create a new cost tracker with the given pricing table.
Sourcepub fn with_budget(self, limit_usd: f64) -> Self
pub fn with_budget(self, limit_usd: f64) -> Self
Set a budget limit in USD. Returns error via callback when exceeded.
Sourcepub async fn set_model(&self, model_name: &str)
pub async fn set_model(&self, model_name: &str)
Set the current model name for cost attribution.
Sourcepub async fn record_usage(&self, usage: &TokenUsage)
pub async fn record_usage(&self, usage: &TokenUsage)
Record token usage from a model response.
Sourcepub async fn snapshot(&self) -> UsageSnapshot
pub async fn snapshot(&self) -> UsageSnapshot
Get a snapshot of accumulated usage and costs.
Sourcepub async fn is_over_budget(&self) -> bool
pub async fn is_over_budget(&self) -> bool
Check if the budget has been exceeded.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CostTrackingCallback
impl !RefUnwindSafe for CostTrackingCallback
impl Send for CostTrackingCallback
impl Sync for CostTrackingCallback
impl Unpin for CostTrackingCallback
impl UnsafeUnpin for CostTrackingCallback
impl !UnwindSafe for CostTrackingCallback
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