USG-2Recommended
Meter on the server after the work succeeds
Record 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.
How to do it
A count sent by the client can be changed, so a customer could bill themselves zero. Measure the quantity where the work happens, such as the token counts the model provider returns. Write the usage event in the same transaction as the result, or through an outbox, so a saved result always has its event. Decide in writing whether a failed or cancelled request is billed, and test that choice.
How to check
Search the API for request fields named quantity, tokens or units that reach the usage table. None do. A test makes a model call fail after the provider answers, and the result and the usage event are both saved or both missing.
Sources
Related rules
- DAT-18 Send side effects through an outbox in Data and databases
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/server-side-metering">Agent Wranglers usage-based billing playbook</a>. In code you write, add a comment next to it with the same link.