Skip to main content

Module usage_meter

Module usage_meter 

Source
Expand description

Measured per-model spend meter.

record aggregates the real provider usage extracted by super::usage into per-model token sums, prices them with the shared ModelPricing table, and persists the totals to proxy_usage.json so the dashboard, CLI and the savings ledger (which run in other processes) can read the user’s real provider bill.

Unlike super::metrics (which resets per proxy lifetime), this meter is a lifetime-cumulative spend counter: resume_from_disk seeds the in-memory totals on proxy startup so a restart never zeroes the user’s measured spend.

Structs§

CohortUsage
Cumulative output-savings cohort totals (#895 Track B). Keyed by arm name ("control" | "treatment"); the average output tokens per turn is output_tokens / requests. Only populated while a holdout is active.
MeasuredSlice
Token/cost sums of the turns that reported a measured provider charge.
ModelSpend
One model’s measured, priced spend for /status and the dashboard.
ModelUsage
Cumulative real token counts for one model. Cost is derived at read time so a pricing-table change re-values historical usage consistently.
PersistedUsage
On-disk shape of the measured spend totals.
VerifiedSavings
Cross-model verified-savings totals (#701) for /status and the dashboard.

Functions§

cohort_snapshot
Live output-savings cohort totals (#895). Empty until a holdout runs.
load_persisted
Cross-process read of the persisted measured spend (dashboard / CLI / ledger).
persisted_cohorts
Cross-process read of the persisted output-savings cohort totals.
persisted_dominant_model
The model carrying the most measured tokens (excludes the “unknown” bucket). Used to value savings against the real dominant model when no explicit model is configured.
persisted_snapshot
Cross-process priced spend rows, read from disk.
price_models
Prices a model usage map into sorted ModelSpend rows. Pure: shared by the in-memory snapshot and the cross-process persisted_snapshot.
record
Records one turn’s measured usage against its model bucket (and its output-savings cohort, when tagged) and persists.
resume_from_disk
Seeds the in-memory totals from proxy_usage.json. Call once on proxy startup so measured spend is cumulative across restarts. Idempotent-ish: it merges the persisted totals into whatever is in memory (normally empty).
snapshot
Live per-model measured spend, priced and sorted by USD descending.
total_cost_usd
Total measured spend across all models (live in-memory totals).
verified_savings
Aggregated provider-verified savings across all models (#701), or None until at least one probe-covered request has been recorded. Unlike the tokens_saved estimate (bytes/4), both sides of this pair were counted by the provider on the same request — receipts, not estimates.