USG-16Recommended
Warn customers before they reach a cap or run out
Email the billing contact when usage reaches 50%, 80% and 100% of the spend cap or the prepaid balance. Send each alert once per period.
How to do it
A stop with no warning breaks the customer's product at the worst moment. Check thresholds each time you add usage, or every few minutes in a job. Store which thresholds each customer has passed this period, so a rerun never sends twice. Name the amount used, the cap, the date usage resets and a link to raise the cap or top up. Let customers add their own thresholds and a webhook, so their systems can react. Sign that webhook as Sign every webhook says.
How to check
A test with a cap of 100 USD adds usage in steps to 105 USD. Three emails go out, at 50, 80 and 100 USD. Running the job again sends nothing.
Related rules
- API-51 Sign every webhook in API design
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/spend-caps-and-alerts/usage-alerts">Agent Wranglers usage-based billing playbook</a>. In code you write, add a comment next to it with the same link.