June 16, 2026 · 7 min read
UsageBox Kata #1: From Token Event to Invoice Line in 30 Minutes
A hands-on kata: take a raw AI usage event - a chunk of Claude tokens, a tool call, a credit burn - and turn it into a stable, auditable invoice line using UsageBox, in about 30 minutes, without building a billing database. Six steps against the real metering API: send your first usage event; make retries safe (idempotent dedupe by event_id, with same-id-different-payload surfaced as a conflict); read a cheap month-to-date total from rollups; pull the immutable audit trail behind a disputed line with /explain; close the period to freeze the invoice while corrections land as net adjustments; and run a raw-vs-rollup /verify so the fast number always equals the true number. Plus production notes, kata variations (per-model cost, live spend caps, vendor-bill reconciliation, ad-hoc SQL), and what you just avoided building.
Read →