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 lean_ctx::core::proxy_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 holdout cohort totals. Keyed by arm name:
"control"|"treatment"for output savings (#895 Track B),"compression:control"|"compression:treatment"for input compression (#1905). The average tokens per turn are*_tokens / requests. Only populated while a holdout is active. - Model
Spend - One model’s measured, priced spend for
/statusand the dashboard. - 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.
- compression_
cohort_ key - Cohort-store key for an input-compression holdout arm (#1905). Prefixed so
it never collides with the output-savings arms stored as
control/treatment, which keeps existing files and readers unchanged. - 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_
projects - Priced spend per project key (the device view’s split).
- persisted_
session - Priced spend of one app session, read from disk;
Nonewhen the proxy saw no turn of it (or keeps it no longer). - persisted_
snapshot - Cross-process priced spend rows, read from disk.
- persisted_
snapshot_ where - Priced spend rows of the projects whose key
keepaccepts, summed per model. - 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.