Overconsumption alerting example (with n8n)
When a customer overconsumes during a period, you might need to warn them. This happens with cloud or API products. Automatic billing should not leave your customers with a bad surprise when they open their invoices.
n8n alerting workflow
- Uses a Cron node to call the Lago API every X minutes, hours or days.
- Calls
GET /api/v2/contracts/{external_id}/current_usageto fetch the contract’s current usage. - Uses an IF node to fire only above a spend threshold.
- Sends a message when the threshold is reached. This example uses Slack. An emailing tool or a CRM works too.
1st node: Cron expression to repeat tasks at a defined interval
The first node triggers the automation at a defined interval.- Add a new Node.
- Select CRON as a new application node.
- Set the Mode to
Every X. - Set the Value to
10and the Unit toMinutes.

Cron expression
2nd node: fetch the contract’s current usage with an HTTP request
This node fetches current usage from the Lago API.- Add a new Node.
- Select HTTP Request as a new application node.
- Set the method to
GETand the URL to the contract current usage endpoint, with the contract’sexternal_idin the path. - Set the
Authorizationheader toBearer __YOUR_API_KEY__and theContent-Typeheader toapplication/json. - Execute the node to fetch the payload from the Lago API.
current_usage object. It holds external_contract_id, external_customer_id, currency, amount_cents, taxes_amount_cents, total_amount_cents and a rate_cards array with the usage of each applied rate card (rate_card_code, product_code, units, events_count, amount_cents, from_datetime, to_datetime). The next node reads its fields with the current_usage prefix.
Current usage covers the contract’s open billing windows. Totals may span more than one upcoming invoice. Pending contracts have no usage. Pass
apply_taxes=false to skip tax calculation, or filter with rate_card_code, product_code, product_filter_code or product_type. The API key needs customer_usage read permission.3rd node: IF conditional statement to trigger messages under conditions
This node triggers the alert only when your customer exceeds a threshold. Those limits depend on your product and your paid features. In this example, the alert fires when the contract’s current usage goes over $200, before tax. You could also use theunits of one entry in rate_cards.
- Add a new Node.
- Select IF as a new application node.
- Create a condition for the TRUE branch (when conditions are met).
- Value 1 is the parameter of your condition, here
current_usage.amount_cents. - Operation is the comparison. Select
Larger or Equaland set Value 2 to20000. Amounts are in cents, so a $200 threshold is20000.
FALSE branch.
4th node: send an alert message to Slack
This last node sends the message. This example uses a Slack channel, but you could also email your customers when they pass their usage limits.- Add a new Node.
- Select Slack as a new application node.
- Select the targeted Slack Account and Slack Channel.
- Choose the option to POST a Message.
- Define a message and use the variables of the payload (for example
current_usage.rate_cards[0].product_nameandcurrent_usage.rate_cards[0].units) to give context about current usage.
Contract current usage
What current usage returns for a contract.
Retrieve contract current usage
GET /api/v2/contracts/{external_id}/current_usage reference.