Skip to content

Alert

Source: src/Stripe/Alert.ts

A Stripe Billing Alert — notifies you when a usage threshold on a Billing Meter is crossed. title, alertType, and usageThreshold are immutable; changing them replaces the alert. status is changed with Stripe’s activate/deactivate endpoints.

Billing alerts have no metadata field and cannot be hard-deleted. Destroying this resource archives the alert (irreversible). Archived alerts leave the list API and cannot be reactivated.

Usage threshold on a meter

const apiCalls = yield* Stripe.BillingMeter("api-calls", {
displayName: "API Calls",
eventName: "api_call",
defaultAggregation: { formula: "sum" },
});
const highUsage = yield* Stripe.Alert("high-usage", {
title: "API Request usage alert",
usageThreshold: {
gte: 10000,
meter: apiCalls.id,
recurrence: "one_time",
},
});

Limit the alert to one customer

const highUsage = yield* Stripe.Alert("high-usage", {
title: "Customer API usage alert",
usageThreshold: {
gte: 1000,
meter: apiCalls.id,
recurrence: "one_time",
filters: [{ type: "customer", customer: customer.id }],
},
});
const highUsage = yield* Stripe.Alert("high-usage", {
title: "API Request usage alert",
usageThreshold: {
gte: 10000,
meter: apiCalls.id,
recurrence: "one_time",
},
status: "inactive",
});
// stack.destroy() / resource removal archives the alert
const highUsage = yield* Stripe.Alert("high-usage", {
title: "API Request usage alert",
usageThreshold: {
gte: 10000,
meter: apiCalls.id,
recurrence: "one_time",
},
});