> ## Documentation Index
> Fetch the complete documentation index at: https://docs.integrateledger.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage alerts

> Get a webhook the moment a customer crosses 80% of their allowance, nears a usage limit or runs low, and turn it into an email, an upsell or a top-up.

> **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](https://docs.integrateledger.com/pricing/top-ups.md) 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-webhook).

## The catalog

Alerts go in a plan's `controls.usageAlerts`:

```ts ledger.config.ts theme={"system"}
plan({
	id: "pro",
	name: "Pro",
	monthlyCredits: 5000,
	priceCents: 2900,
	items: [{ featureId: "messages", included: 1000 }],
	controls: {
		usageLimits: [{ featureId: "messages", limit: 200, interval: "day" }],
		usageAlerts: [
			{ creditPool: true, name: "eighty", type: "usage_percentage", threshold: 80 },
			{ creditPool: true, name: "last_hundred", type: "remaining", threshold: 100 },
			{
				featureId: "messages",
				name: "daily",
				type: "usage",
				threshold: 150,
				usageLimit: { interval: "day" },
			},
		],
	},
}),
```

```json ledger.catalog.json theme={"system"}
{ "id": "pro", "name": "Pro", "monthlyCredits": 5000, "priceCents": 2900,
  "items": [{ "featureId": "messages", "included": 1000 }],
  "controls": {
    "usageLimits": [{ "featureId": "messages", "limit": 200, "interval": "day" }],
    "usageAlerts": [
      { "creditPool": true, "name": "eighty", "type": "usage_percentage", "threshold": 80 },
      { "creditPool": true, "name": "last_hundred", "type": "remaining", "threshold": 100 },
      { "featureId": "messages", "name": "daily", "type": "usage", "threshold": 150,
        "usageLimit": { "interval": "day" } }
    ]
  } }
```

| Field | |
| - | - |
| `featureId` or `creditPool: true` | What the alert watches: the shared credit pool, a metered or held feature, or a credits feature's usage limit. |
| `name` | Yours, unique for each target on a plan, customer or entity. It comes back on the webhook. |
| `type` | `usage` or `usage_percentage`: what's used this period, crossing upward. `remaining` or `remaining_percentage`: what's left, crossing downward. |
| `threshold` | The value to cross: units or credits, or a percentage of the allowance for the `_percentage` types. |
| `usageLimit` | Watch a [usage limit's](https://docs.integrateledger.com/pricing/usage-limits.md) window instead of the period, with the limit's `interval` and `filter`. Percentages are of the limit. |

## When alerts fire

* **`usage` alerts 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 with `usageLimit`.
* **`remaining` alerts 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`](https://docs.integrateledger.com/api-reference/customers/get-controls) lists every alert in force with its `source` and `firedAt`, when it last fired in its current window.

## The webhook

[Webhooks](https://docs.integrateledger.com/webhooks.md) delivers `usage_alert.triggered` with the alert, the value that crossed it, and the use that did:

```json theme={"system"}
{
  "type": "usage_alert.triggered",
  "data": {
    "object": {
      "object": "usage_alert",
      "customerId": "user_123",
      "entityId": null,
      "creditPool": true,
      "featureType": "credits",
      "alert": { "name": "eighty", "type": "usage_percentage", "threshold": 80, "usageLimit": null },
      "value": 4012,
      "windowStart": "2026-11-07T07:40:58.000Z",
      "requestId": "chat_0193",
      "source": "plan"
    }
  }
}
```

`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`](https://docs.integrateledger.com/webhooks#low-and-depleted-balances) keeps working beside alerts, for one environment-wide threshold.

## One customer's alerts

Give a customer or entity their own alerts with `setCustomerControls`:

```typescript TypeScript theme={"system"}
await billing.setCustomerControls({
	customerId: "acme",
	body: {
		usageAlerts: [{ creditPool: true, name: "eighty", type: "usage_percentage", threshold: 90 }],
	},
});
```

```python Python theme={"system"}
billing.set_customer_controls(
    customer_id="acme",
    controls={
        "usageAlerts": [
            {"creditPool": True, "name": "eighty", "type": "usage_percentage", "threshold": 90}
        ]
    },
)
```

```bash cURL theme={"system"}
curl "https://api.integrateledger.com/v1/customers/controls?customerId=acme" \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"usageAlerts": [{"creditPool": true, "name": "eighty", "type": "usage_percentage", "threshold": 90}]}'
```

Acme's `eighty` alert now fires at 90%, in place of the plan's. Send `"usageAlerts": null` to follow the plan's again. See [Overrides](https://docs.integrateledger.com/customers/overrides.md#overage-controls) 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 `_percentage` alert on the pool needs `monthlyCredits`, 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 `remaining` alert 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/controls` answers `400 invalid_alert` with each problem in `issues`.

## Related

* [Usage limits](https://docs.integrateledger.com/pricing/usage-limits.md): cap use over a day, week or month.
* [Webhooks](https://docs.integrateledger.com/webhooks.md): verify and receive events.
* [Credit packs](https://docs.integrateledger.com/pricing/credit-packs.md) and [top-ups](https://docs.integrateledger.com/pricing/top-ups.md): what to offer a customer running low.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.