Model usage was recorded per call and never read, so an org could not see
what it spent. Add the read side:
- model_usage carries identity_id. Task calls take it from the task row,
chat and curator calls from the calling principal carried in the usage
record, so an outbox replay keeps its attribution. Existing task rows are
backfilled from tasks.
- StatsService.UsageTotals sums the caller org's rows by UTC day, source,
provider, model and identity. The org comes from the principal, with no
org parameter, so cross-org reads do not exist.
- GET /api/usage prices tokens at the catalog's list rate, netting cache
hits, and reports calls to unpriced models as tokens only. The published
catalog view now carries each model's cost.
- A new org Usage page behind a read_usage grant: admin and owner only,
with a 7, 30 or 90 day range, totals, the daily series, and model, source
and identity breakdowns. The org shell keeps it on the caller's own org.
Task agent runs and MCP sampling record against their task (billed to the
task's org); gateway chat turns, titles, sampling and curators record
against the system org. Rows carry source, workflow, step, alias,
provider/model and tokens for later chargeback.