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§
- Cohort
Usage - Cumulative output-savings cohort totals (#895 Track B). Keyed by arm name
(
"control"|"treatment"); the average output tokens per turn isoutput_tokens / requests. Only populated while a holdout is active. - Model
Spend - One model’s measured, priced spend for
/statusand the dashboard. - Model
Usage - Cumulative real token counts for one model. Cost is derived at read time so a pricing-table change re-values historical usage consistently.
- Persisted
Usage - On-disk shape of the measured spend totals.
- Verified
Savings - Cross-model verified-savings totals (#701) for
/statusand 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
ModelSpendrows. Pure: shared by the in-memory snapshot and the cross-processpersisted_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
Noneuntil at least one probe-covered request has been recorded. Unlike thetokens_savedestimate (bytes/4), both sides of this pair were counted by the provider on the same request — receipts, not estimates.