Expand description
Cost tracking and usage metering for LLM requests.
This module provides usage tracking, cost calculation, and metering infrastructure for monitoring LLM API usage across providers and tenants.
§Example
ⓘ
use llmkit::{MeteringProvider, InMemoryMeteringSink};
let sink = Arc::new(InMemoryMeteringSink::new());
let provider = MeteringProvider::new(anthropic_provider, sink.clone())
.with_tenant("acme-corp");
// Make requests...
// Query usage
let usage = sink.query(UsageFilter {
tenant_id: Some("acme-corp".into()),
since: Some(Utc::now() - Duration::days(7)),
..Default::default()
}).await?;Structs§
- Cost
Tracker - Simple cost tracker that just accumulates totals.
- InMemory
Metering Sink - In-memory metering sink for development and testing.
- Metering
Provider - Provider wrapper that records usage metrics.
- Model
Stats - Statistics for a specific model.
- Tenant
Stats - Statistics for a specific tenant.
- Usage
Filter - Filter for querying usage records.
- Usage
Record - Usage record for a single request.
- Usage
Stats - Aggregated usage statistics.
Traits§
- Metering
Sink - Trait for metering sinks that persist usage data.