docs(0047): usage & cost stats — metering what a ticket costs #121

Merged
chad merged 1 commit from glen/0047-usage-cost-stats into main 2026-10-17 14:03:42 -04:00
Collaborator

Design doc only — no code. This is the spec for usage/cost/time metering across a conversation group, for Chad's review before implementation (which will be handed to Cursor per the working session).

What's in it:

  • Gloo pricing solved from the public API: GET /platform/v2/models (no auth, verified live 2026-10-17) gives exact per-1M input/output/cache_read/cache_write rates + long-context tiers per model. Cost computed at capture time so price drift never rewrites history. One calibration item: the 6.5% guarded platform fee vs list price on the bare /ai/v2/chat/completions path — resolved once against Gloo's Usage dashboard.
  • Capture: chat turns (sum per-slice usage in the turn loop, one usage_events row per turn) + harness calls (a new onUsage hook in the harness event sink, which currently drops usage chunks). Titles excluded by decision.
  • Cost model: fresh×input + cached×cache_read + output×output, platform-fee multiplier, long-context tier selection, null cost (plan chip) for subscriptions — GLM/claude/cursor get tokens but no invented dollars.
  • Storage: migration 0054_usage_stats.sql — usage_events + model_prices (refreshed by the existing catalog sweep; Gloo fetch needs no key).
  • Stats drawer: overlay drawer off the chat header (agent-panel pattern), hand-rolled SVG donut for cost-by-model (no chart dependency), plan rows, time strip (work · waiting · idle), touches, cache-hit rate. Semantic tokens per DESIGN.md.
  • Optional amendment, recommended: enabling prompt caching (X-Cache-TTL / prompt_cache_key in the provider transforms) — the chat path currently pays quadratic full-price input on long threads; the cost model already prices cache segments so the drawer will show the win.
  • Open questions listed for the implementation spike (usage chunk shapes, cached-token reporting, fee calibration).

Decisions locked with Chad in chat, 2026-10-17: scope = conversation tree + harness calls; Gloo is the accuracy target; titles unmetered; subscriptions token-only; forward-only metering; stats drawer surface; Cursor implements.

Design doc only — no code. This is the spec for usage/cost/time metering across a conversation group, for Chad's review before implementation (which will be handed to Cursor per the working session). **What's in it:** - **Gloo pricing solved from the public API**: `GET /platform/v2/models` (no auth, verified live 2026-10-17) gives exact per-1M input/output/cache_read/cache_write rates + long-context tiers per model. Cost computed at capture time so price drift never rewrites history. One calibration item: the 6.5% guarded platform fee vs list price on the bare `/ai/v2/chat/completions` path — resolved once against Gloo's Usage dashboard. - **Capture**: chat turns (sum per-slice usage in the turn loop, one `usage_events` row per turn) + harness calls (a new `onUsage` hook in the harness event sink, which currently drops usage chunks). Titles excluded by decision. - **Cost model**: `fresh×input + cached×cache_read + output×output`, platform-fee multiplier, long-context tier selection, null cost (plan chip) for subscriptions — GLM/claude/cursor get tokens but no invented dollars. - **Storage**: migration `0054_usage_stats.sql` — `usage_events` + `model_prices` (refreshed by the existing catalog sweep; Gloo fetch needs no key). - **Stats drawer**: overlay drawer off the chat header (agent-panel pattern), hand-rolled SVG donut for cost-by-model (no chart dependency), plan rows, time strip (work · waiting · idle), touches, cache-hit rate. Semantic tokens per DESIGN.md. - **Optional amendment, recommended**: enabling prompt caching (`X-Cache-TTL` / `prompt_cache_key` in the provider transforms) — the chat path currently pays quadratic full-price input on long threads; the cost model already prices cache segments so the drawer will show the win. - **Open questions** listed for the implementation spike (usage chunk shapes, cached-token reporting, fee calibration). Decisions locked with Chad in chat, 2026-10-17: scope = conversation tree + harness calls; Gloo is the accuracy target; titles unmetered; subscriptions token-only; forward-only metering; stats drawer surface; Cursor implements.
docs(0047): usage & cost stats — metering what a ticket costs
All checks were successful
deploy / checks (pull_request) Successful in 41s
deploy / deploy (pull_request) Has been skipped
40d5ea4237
Design for per-ticket token/cost/time accounting: Gloo pricing from the
public /platform/v2/models endpoint (verified live), capture at the chat
turn and harness call sources, usage_events + model_prices tables, and a
stats drawer in the chat header.
chad merged commit 93f9c77cf0 into main 2026-10-17 14:03:42 -04:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
chad/sweatshop-legacy!121
No description provided.