Enable custom spend limits
Spend limits provide an important safety mechanism to reassure customers that their total costs won’t exceed a predefined threshold. These limits trigger notifications and prevent further service usage in the case of a hard limit. Implement spend limits with the following workflow:- An end user sets limits in your application (see example UI below)
- Using the Metronome API, your application creates a
spend_threshold_reached
alert for each limit with a threshold matching the values entered by the end user - Metronome continuously evaluates the spend for the billing period, setting the alerts to an
in_alarm
state once the threshold is reached - Metronome sends an alert notification to a webhook configured for your application that you can use to notify your customer and optionally block access to the service

INFOThe
credit_type_id
of 2714e483-4ff1-48e4-9e25-ac732e8f24f2
represents a credit unit of US cents. However, spend alerts are not limited to USD. You can set them in custom pricing units, which you can define on the Offering page in the Metronome app.Process alert notifications sent through a webhook
Taking action on alerts in real time requires the use of webhooks—dedicated endpoints in your application for receiving and processing alert notifications. Configure webhooks in Metronome in under Connections - API tokens & webhooks. When an alert triggers in Metronome, a POST request is sent to your webhook with basic information related to the alert, including the alert type, customer ID, and alert ID. Upon receiving a webhook notification, your application can process it and take the appropriate action. Learn more best practices around handling webhook notifications. For the spend limit example above, processing the webhook payload might look like this:- Check that the alert ID matches an alert you have configured and that the customer ID matches the one you associated with the alert ID.
- Using information included in the webhook like alert ID, alert name, and alert threshold, determine whether the customer exceeded their soft limit, or their hard limit.
- If the customer exceeded their soft limit, notify the customer inside the app, through email, or via your preferred delivery mechanism.
- If the customer exceeded their hard limit, disable the customer’s access to your services to prevent any additional spend. Inform the customer they have reached their hard spend limit and prompt them to update their limits in your application if they’d like to continue using the service.
- For any limits that have changed, archive the previous alerts before creating new alerts with the updated thresholds:
Enable custom spend limits for a specific dimension
Your customers may want the flexibility to set up custom spend limits for a subset of usage. For example, they may want to receive a notification or limit access once a specificuser_id
has spent more than $500 in a billing period, or when a specific organization_id
has spent more than $5000.
In Metronome, you have the option of adding group_values
filters to spend alerts to support this use case. Create an alert on spend for organization_id
= finance
using the following API call:
group_values
field, make sure that key is added as a group key on billable metrics associated with that customer’s contract. Spend on products where the key is not a group key on the underlying billable metrics will not contribute to the threshold.
When evaluating spend threshold alerts for a specific dimension, Metronome recomputes the invoice as if the group key is a presentation group key. In cases with tiered pricing, quantity rounding, or MAX billable metrics, the pricing and packaging will be applied to the subset of usage you define. For example, if you create an alert for organization_id
= finance
, the quantity will be rounded for the subset of usage by the finance org.
INFOFor a given customer, you can set spend alerts for three keys. For example, you can set spend alerts for a
user_id
, a project_id
, and an organization_id
, but will be prevented from adding an alert using a fourth key. For keys with more than 5000 values for a given customer, contact your Metronome representative to discuss your spend alert configuration.