pub struct CostTracker { /* private fields */ }Expand description
Accumulates token usage and cost across calls. Thread-safe.
Cost is stored as micro-cents (1 cent = 10 000 micro-cents). The scaling factor is chosen so a single Haiku session (~1 000 tokens) costs on the order of a few hundred micro-cents — integer math without losing precision.
Implementations§
Source§impl CostTracker
impl CostTracker
Sourcepub fn record(&self, usage: TokenUsage, price: Price)
pub fn record(&self, usage: TokenUsage, price: Price)
Record one call’s usage under the given price table.
Sourcepub fn spent_micro_cents(&self) -> u64
pub fn spent_micro_cents(&self) -> u64
Total cost so far, in micro-cents (integer). Divide by 10 000 for cents.
Sourcepub fn input_tokens(&self) -> u64
pub fn input_tokens(&self) -> u64
Total input tokens accumulated.
Sourcepub fn output_tokens(&self) -> u64
pub fn output_tokens(&self) -> u64
Total output tokens accumulated.
Sourcepub fn log_session(&self)
pub fn log_session(&self)
Emit a tracing::info! line summarizing accumulated cost.
Trait Implementations§
Source§impl Debug for CostTracker
impl Debug for CostTracker
Source§impl Default for CostTracker
impl Default for CostTracker
Source§fn default() -> CostTracker
fn default() -> CostTracker
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for CostTracker
impl RefUnwindSafe for CostTracker
impl Send for CostTracker
impl Sync for CostTracker
impl Unpin for CostTracker
impl UnsafeUnpin for CostTracker
impl UnwindSafe for CostTracker
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