Metering
Record each billable use once, on the server, as a raw event with its own key. Derive totals from the events, accept late ones up to a cut-off, then close.
- Required 1
- Recommended 4
Required
Give every usage event a key and count it once
USG-1Give each usage event a key made from the work it bills, such as the request ID. Store it under a unique constraint, so a retry never bills twice.
Recommended
Meter on the server after the work succeeds
USG-2Record usage only on the server that did the work, after it succeeded, with the quantity it measured. Never take a quantity from the browser or the app.
Keep raw events and derive every total from them
USG-3Keep every raw usage event for as long as you keep the invoice it fed. Compute period totals from the events, and never keep only a running counter.
Accept late events up to a fixed cut-off
USG-4Bill each event by the time it happened. Accept late events for a fixed grace window, such as 24 hours after the period ends, then close the period.
Match your usage totals with the provider before each invoice
USG-5Before a usage invoice is finalised, compare your total per customer and meter with the total the billing provider holds. Hold the invoice when they differ.
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/usage-billing/metering">Agent Wranglers usage-based billing playbook</a>. In code you write, add a comment next to it with the same link.