Skip to main content

Crate agent_metering

Crate agent_metering 

Source
Expand description

Provider-independent usage accounting primitives.

This crate defines normalized, durable-domain representations for resource consumption at the model-invocation level, including provenance, attribution, and provider-reported monetary amounts. It deliberately has no dependency on model providers, storage engines, HTTP APIs, or monitoring backends.

Pricing data is versioned and cost calculations use integer arithmetic. Storage and run orchestration are owned by the storage and service crates; this crate owns the accounting vocabulary and deterministic calculations.

Structs§

CostEstimate
A reproducible cost calculation in integer currency micro-units.
CurrencyCostSummary
Cost totals retain the source of every amount.
DimensionUsageSummary
Totals for one normalized resource dimension.
ModelPricing
Rates are currency micro-units per one million resource units. A missing rate means that the dimension is not priced, not that it is free.
ReportedCost
Provider-reported monetary cost, retained separately from calculated cost.
UsageDimensions
Named resource dimensions for one provider invocation.
UsageRecord
Immutable accounting input for one model invocation.
UsageSummary
Run-level totals across all model invocations, retries, and fallbacks.

Enums§

CostOrigin
Explains where a monetary amount came from.
CostStatus
InvocationOutcome
Whether the provider invocation completed from the platform’s perspective.
MeteredValue
A resource quantity together with the provenance of that quantity.
PricingError
UsageRecordError

Functions§

calculate_cost
Calculates cost using one immutable pricing version. Unknown or unpriced dimensions make the result partial; estimated quantities remain marked.
summarize_usage
Aggregates records additively. Each invocation ID is expected to be unique; retries and fallback attempts are separate records and therefore counted.