pub struct MeteringEngine { /* private fields */ }Expand description
Engine for tracking LLM costs and enforcing spend quotas.
Implementations§
Source§impl MeteringEngine
impl MeteringEngine
Sourcepub fn new(memory: Arc<MemorySubstrate>) -> Self
pub fn new(memory: Arc<MemorySubstrate>) -> Self
Create a new metering engine with embedded default pricing.
Sourcepub fn with_prices(
memory: Arc<MemorySubstrate>,
model_prices: HashMap<String, ModelPrice>,
) -> Self
pub fn with_prices( memory: Arc<MemorySubstrate>, model_prices: HashMap<String, ModelPrice>, ) -> Self
Create a new metering engine with custom pricing.
Sourcepub fn estimate_cost(
&self,
model: &str,
input_tokens: u64,
output_tokens: u64,
) -> f64
pub fn estimate_cost( &self, model: &str, input_tokens: u64, output_tokens: u64, ) -> f64
Calculate the cost for a given model and token counts.
Sourcepub async fn record_usage(
&self,
fighter_id: &FighterId,
model: &str,
input_tokens: u64,
output_tokens: u64,
) -> PunchResult<f64>
pub async fn record_usage( &self, fighter_id: &FighterId, model: &str, input_tokens: u64, output_tokens: u64, ) -> PunchResult<f64>
Record usage for a fighter, calculating cost automatically.
Sourcepub async fn get_spend(
&self,
fighter_id: &FighterId,
period: SpendPeriod,
) -> PunchResult<f64>
pub async fn get_spend( &self, fighter_id: &FighterId, period: SpendPeriod, ) -> PunchResult<f64>
Get total spend for a specific fighter over a time period.
Sourcepub async fn get_total_spend(&self, period: SpendPeriod) -> PunchResult<f64>
pub async fn get_total_spend(&self, period: SpendPeriod) -> PunchResult<f64>
Get total spend across all fighters over a time period.
Sourcepub async fn get_fighter_summary(
&self,
fighter_id: &FighterId,
period: SpendPeriod,
) -> PunchResult<UsageSummary>
pub async fn get_fighter_summary( &self, fighter_id: &FighterId, period: SpendPeriod, ) -> PunchResult<UsageSummary>
Get the usage summary for a fighter over a time period.
Sourcepub async fn get_total_summary(
&self,
period: SpendPeriod,
) -> PunchResult<UsageSummary>
pub async fn get_total_summary( &self, period: SpendPeriod, ) -> PunchResult<UsageSummary>
Get the total usage summary across all fighters over a time period.
Sourcepub async fn get_model_breakdown(
&self,
fighter_id: &FighterId,
period: SpendPeriod,
) -> PunchResult<Vec<ModelUsageBreakdown>>
pub async fn get_model_breakdown( &self, fighter_id: &FighterId, period: SpendPeriod, ) -> PunchResult<Vec<ModelUsageBreakdown>>
Get per-model usage breakdown for a fighter over a time period.
Sourcepub async fn get_total_model_breakdown(
&self,
period: SpendPeriod,
) -> PunchResult<Vec<ModelUsageBreakdown>>
pub async fn get_total_model_breakdown( &self, period: SpendPeriod, ) -> PunchResult<Vec<ModelUsageBreakdown>>
Get per-model usage breakdown across all fighters over a time period.
Sourcepub async fn get_fighter_breakdown(
&self,
period: SpendPeriod,
) -> PunchResult<Vec<FighterUsageBreakdown>>
pub async fn get_fighter_breakdown( &self, period: SpendPeriod, ) -> PunchResult<Vec<FighterUsageBreakdown>>
Get per-fighter usage breakdown over a time period.
Auto Trait Implementations§
impl Freeze for MeteringEngine
impl !RefUnwindSafe for MeteringEngine
impl Send for MeteringEngine
impl Sync for MeteringEngine
impl Unpin for MeteringEngine
impl UnsafeUnpin for MeteringEngine
impl !UnwindSafe for MeteringEngine
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 more