pub struct CostTracker { /* private fields */ }Implementations§
Source§impl CostTracker
impl CostTracker
pub fn new(enabled: bool, max_daily_cents: f64) -> Self
pub fn with_pricing(self, model: &str, pricing: ModelPricing) -> Self
Sourcepub fn record_usage(
&self,
provider_name: &str,
provider_kind: &str,
model: &str,
input_tokens: u64,
cache_read_tokens: u64,
cache_write_tokens: u64,
output_tokens: u64,
)
pub fn record_usage( &self, provider_name: &str, provider_kind: &str, model: &str, input_tokens: u64, cache_read_tokens: u64, cache_write_tokens: u64, output_tokens: u64, )
Record token usage for a single LLM call, attributed to provider_name.
provider_kind must be the value returned by AnyProvider::provider_kind_str():
"ollama" or "candle" for local providers, "cloud" for API providers.
Local providers always have zero cost by design; the missing-pricing WARN is
suppressed for them to avoid log floods on every Ollama call.
Cache token counts are optional (pass 0 when not available). Cost is computed using model-specific pricing including cache read/write rates.
Sourcepub fn check_budget(&self) -> Result<(), BudgetExhausted>
pub fn check_budget(&self) -> Result<(), BudgetExhausted>
§Errors
Returns BudgetExhausted when daily spend exceeds the configured limit.
Sourcepub fn max_daily_cents(&self) -> f64
pub fn max_daily_cents(&self) -> f64
Returns the configured daily budget in cents. Zero means unlimited.
pub fn current_spend(&self) -> f64
Sourcepub fn provider_breakdown(&self) -> Vec<(String, ProviderUsage)>
pub fn provider_breakdown(&self) -> Vec<(String, ProviderUsage)>
Returns per-provider breakdown sorted by cost descending.
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request