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

# Usage alerts

> Usage alerts monitor a Contract's usage and spend and fire a webhook when it crosses thresholds you define.

## Overview

Usage alerts notify you when a Contract's usage or spend crosses thresholds you define. Common use cases:

1. Let customers set and manage their own usage limits and budgets;
2. Warn customers whose usage is climbing fast, before it reaches their bill; or
3. Stop serving usage when a customer reaches the limit you defined for them.

> [!NOTE]
>
> Usage alerts on Contracts are a **premium** feature, in beta. Contact the Lago team to enable them on your organization.

## Create an alert

> [tab] Dashboard
>
> An alert is tied to a specific Contract. You can create one on a `pending` or `active` Contract:
>
> 1. Open the Contract and select **Alerts** in its overview;
> 2. Click **Create alert**;
> 3. Enter a name and a code for the alert;
> 4. Select the alert type, **Usage units** or **Usage amount**;
> 5. In **Include**, select a product, and optionally one of its product filters. A usage amount alert can also cover every product;
> 6. Set the thresholds and their codes;
> 7. Optionally, set **Notify when resolved** to **True** on a threshold to also receive `alert.resolved`;
> 8. Optionally, turn on **Recurring alert after last threshold**; and
> 9. Click **Create alert** to confirm.
>
> ![The Create an alert on contract form, with a usage units alert on the LLM tokens product and a 1,000,000 units threshold](https://mintcdn.com/lago-docs/z0U4TdkC3UIahDlF/v2/guide/alerts/images/create-contract-alert.webp?fit=max\&auto=format\&n=z0U4TdkC3UIahDlF\&q=85\&s=68b6b8b95e68e81c36dbaa8ecf435b2e)
>
> Create an alert on a Contract
>
> The **Alerts** tab lists every alert of the Contract with its name and code.
>
> ![The Alerts tab of the Hooli Enterprise Contract, listing eight alerts such as Monthly spend, Opus tokens and Video minutes](https://mintcdn.com/lago-docs/z0U4TdkC3UIahDlF/v2/guide/alerts/images/contract-alerts-list.webp?fit=max\&auto=format\&n=z0U4TdkC3UIahDlF\&q=85\&s=33a3d63a0fd1bf674c49ecf76af71cd4)
>
> Alerts of a Contract

> [tab] API
>
> An alert is tied to a Contract's `external_id`. You can create one on a `pending` or `active` Contract.
>
> ```bash Spend on the whole Contract theme={"dark"}
> LAGO_URL="https://api.getlago.com"
> API_KEY="__YOUR_API_KEY__"
>
> curl --location --request POST "$LAGO_URL/api/v2/contracts/:external_id/alerts" \
>   --header "Authorization: Bearer $API_KEY" \
>   --header 'Content-Type: application/json' \
>   --data-raw '{
>     "alert": {
>       "alert_type": "usage_amount",
>       "code": "monthly_spend",
>       "name": "Monthly spend",
>       "scope": [],
>       "thresholds": [
>         { "code": "soft", "value": "100000" },
>         { "code": "hard", "value": "500000", "notify_on": ["triggered", "resolved"] },
>         { "value": "250000", "recurring": true }
>       ]
>     }
>   }'
> ```
>
> ```bash Units of a product filter theme={"dark"}
> LAGO_URL="https://api.getlago.com"
> API_KEY="__YOUR_API_KEY__"
>
> curl --location --request POST "$LAGO_URL/api/v2/contracts/:external_id/alerts" \
>   --header "Authorization: Bearer $API_KEY" \
>   --header 'Content-Type: application/json' \
>   --data-raw '{
>     "alert": {
>       "alert_type": "usage_units",
>       "code": "opus_tokens",
>       "name": "Opus tokens",
>       "scope": [
>         { "type": "contract", "product_code": "llm_tokens", "product_filter_codes": ["opus"] }
>       ],
>       "thresholds": [
>         { "code": "warn", "value": "1000000", "notify_on": ["triggered", "resolved"] },
>         { "value": "500000", "recurring": true }
>       ]
>     }
>   }'
> ```
>
> Use `GET`, `PUT` and `DELETE` on `/api/v2/contracts/:external_id/alerts/:code` to read, update and delete an alert, and `GET /api/v2/contracts/:external_id/alerts` to list them. An update accepts `name` and `thresholds` only. The `code`, `alert_type` and `scope` cannot change.

## Alert types

* **Usage amount** (`usage_amount`): the amount of the usage in scope for the current billing period, before taxes. Values are in cents of the Contract currency, so `"100000"` is 1,000.00.
* **Usage units** (`usage_units`): the number of units in scope for the current billing period. A units alert needs a product in its `scope`.

## Scope

The `scope` sets which usage the alert measures. It takes one entry at most.

| `scope` | What the alert measures |
| - | - |
| `[]` | Every metered product on the Contract. Only for `usage_amount`. Fixed products are left out. |
| `[{ "type": "contract", "product_code": "llm_tokens" }]` | The product's own [Rate Card](https://getlago.com/docs/v2/guide/rate-cards/overview.md). Events that match one of its [product filters](https://getlago.com/docs/v2/guide/product-catalog/product-filters.md) are not counted. |
| `[{ "type": "contract", "product_code": "llm_tokens", "with_product_filters": true }]` | The product's own Rate Card and the Rate Cards of its filters. |
| `[{ "type": "contract", "product_code": "llm_tokens", "product_filter_codes": ["opus"] }]` | The Rate Card of that filter only. |

The product, and the filter if any, must be priced on the Contract. A fixed product cannot be used.

## Thresholds

* An alert takes up to 20 thresholds, the recurring one included.
* One threshold can be `recurring`. It repeats every `value` above the highest non-recurring threshold.
* Each threshold notifies on `triggered`. Add `resolved` to `notify_on` to also be notified when the value goes back below it. A threshold that opts in needs a `code`.

## Billing period

Each Rate Card is measured on its own current billing period, so the Rate Cards of one Contract can reset on different dates. When a Rate Card's period restarts, its usage leaves the alert's value and its thresholds can trigger again. This also happens when a new [rate](https://getlago.com/docs/v2/guide/rate-cards/rates.md) takes effect during the period. A restart never sends `alert.resolved`.

Usage on a [recurring billable metric](https://getlago.com/docs/v2/guide/billable-metrics/recurring-vs-metered.md) never resets.

## Alert notifications

Listen for the `alert.triggered` webhook. It names the alert, the Contract evaluated, the value that crossed the line, and every threshold crossed. `currency` is set on `usage_amount` alerts and `null` on `usage_units` alerts.

```json theme={"dark"}
{
  "webhook_type": "alert.triggered",
  "object_type": "triggered_alert",
  "organization_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
  "triggered_alert": {
    "lago_id": "46b91ede-d129-4b6e-a255-300e2dc4a57d",
    "lago_alert_id": "a42c76da-d766-43b5-bdda-1e5a84fe7e37",
    "alert_code": "monthly_spend",
    "alert_name": "Monthly spend",
    "alert_type": "usage_amount",
    "currency": "USD",
    "lago_contract_id": "889abf77-8947-4fc5-9501-03b4c5ff4add",
    "external_contract_id": "contract_8832",
    "external_customer_id": "hooli_1234",
    "current_value": "752000.0",
    "previous_value": "452000.0",
    "scope": [],
    "crossed_thresholds": [
      { "code": "hard", "value": "500000.0", "recurring": false },
      { "code": null, "value": "750000.0", "recurring": true }
    ],
    "triggered_at": "2026-12-02T16:13:42Z"
  }
}
```

## Alert resolution

Thresholds that opt in with `notify_on: ["triggered", "resolved"]` send `alert.resolved` when the value is back below them, or when an update raises or removes them. The `reason` is `recovered`, `threshold_updated` or `threshold_removed`.

```json theme={"dark"}
{
  "webhook_type": "alert.resolved",
  "object_type": "resolved_alert",
  "organization_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
  "resolved_alert": {
    "lago_id": "3f144e52-8dc6-4ad4-8e72-bd80d8202bbd",
    "lago_alert_id": "a42c76da-d766-43b5-bdda-1e5a84fe7e37",
    "alert_code": "monthly_spend",
    "alert_name": "Monthly spend",
    "alert_type": "usage_amount",
    "currency": "USD",
    "lago_contract_id": "889abf77-8947-4fc5-9501-03b4c5ff4add",
    "external_contract_id": "contract_8832",
    "external_customer_id": "hooli_1234",
    "current_value": "452000.0",
    "previous_value": "612000.0",
    "scope": [],
    "recovered_thresholds": [
      { "code": "hard", "value": "500000.0", "recurring": false }
    ],
    "in_alarm_thresholds": ["soft"],
    "fully_resolved": false,
    "reason": "recovered",
    "resolved_at": "2026-12-02T16:11:42Z"
  }
}
```

## Contract lifecycle

* Only the `active` Contract is evaluated. Alerts created on a `pending` Contract are evaluated once it is active.
* When the Contract is terminated, its alerts stop being evaluated and stay readable.
* Alerts follow the Contract's `external_id`. A new Contract created with the same `external_id` picks them up.
* If a product or filter leaves the Contract, its alerts are kept and skipped. If the product or filter is deleted, its alerts are deleted.

## Limitations

* An alert is evaluated after new events or after it is created or updated, close to real time. Its first evaluation sends `alert.triggered` for every threshold already passed;
* Each alert `code` must be unique per Contract, and only one alert per type and scope can exist on a Contract; and
* The API key needs the `alert` permission.


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