Pro: email the customer at 80% of their monthly credits, and again when 100 are left. Team: tell the admin when a day’s messages pass 150 of 200.Usage alerts tell you the moment a customer crosses a threshold, so you can nudge them before they hit a wall: an “80% used” email, an in-app upgrade prompt, a sales call for an account growing fast, or an auto top-up of your own. Set them on a plan for everyone on it, and on one customer or entity for their own. Ledger decides each alert on the use that crosses it and sends
usage_alert.triggered.
The catalog
Alerts go in a plan’scontrols.usageAlerts:
When alerts fire
usagealerts fire once per window, on the use that crosses the threshold upward. Landing exactly on it counts. The window is the billing period, or the usage limit’s window withusageLimit.remainingalerts fire on every downward crossing. A renewal, a credit pack or a top-up that lifts the balance back above the threshold re-arms them, so the customer hears again next time they run low.- Every level at once. A plan’s alerts, a customer’s own and an entity’s own all apply. A customer’s alert replaces the plan’s with the same target and name, and an entity’s replaces the customer’s.
- Changes apply at once. Alerts change in place for everyone on the plan, with no new version.
GET /v1/customers/controls lists every alert in force with its source and firedAt, when it last fired in its current window.
The webhook
Webhooks deliversusage_alert.triggered with the alert, the value that crossed it, and the use that did:
value is what’s used, or what’s left, after the use, in units or credits. windowStart is the start of the window the alert fired in, and source the level that set it: plan, customer or entity. balance.low keeps working beside alerts, for one environment-wide threshold.
One customer’s alerts
Give a customer or entity their own alerts withsetCustomerControls:
eighty alert now fires at 90%, in place of the plan’s. Send "usageAlerts": null to follow the plan’s again. See Overrides for the rest of the call.
Rules
- Targets. An alert watches the pool, a metered or held feature, or a credits feature through its
usageLimit. Boolean features have no usage to watch. - Percentages need an allowance. A
_percentagealert on the pool needsmonthlyCredits, and on an item needs one that includes more than 0; or alert on a usage limit. - What’s left is the customer’s. A
remainingalert on the pool watches the customer’s shared balance, so it’s set on the plan or the customer. - Decided with the use. An alert is decided on the track that crosses it, in the same transaction, and a retried track never sends it twice.
- Up to 50 alerts on each plan, customer or entity, and
POST /v1/customers/controlsanswers400 invalid_alertwith each problem inissues.
Related
- Usage limits: cap use over a day, week or month.
- Webhooks: verify and receive events.
- Credit packs and top-ups: what to offer a customer running low.