Consumption guardrails
@agentcosts/consumption-guardrails
Set and check consumption guardrails for an AI product: per-customer daily and monthly spend caps, month-end forecasts, spend spike rules, runaway agent runs, and failure rate spikes, plus a runbook for what to do when each alert fires. Runs on usage files; exit code 2 on critical alerts for cron or CI.
- Activity
- New: be the first to try it
- Installs
- 0 installs
- Likes
- 0 likes
- Clones
- 0 clones
- 1# Consumption guardrails runbook: <product name>
- 3Owner: <role>. Review these limits every quarter and after any pricing change.
- 5## Limits
- 7| Limit | Default | Exceptions | Why this number |
- 8| --- | --- | --- | --- |
- 9| Daily spend per customer | $<x> | <customer: $y> | about 3x a normal heavy day |
- 10| Monthly spend per customer | $<x> | <customer: $y> | keeps gross margin above <target>% at their price |
- 11| Cost per run | $<x> | | 3x the p95 cost of the most expensive task |
- 12| Calls per run | <n> | | stops agent loops |
- 13| Spend spike | <m>x the 7-day median, at least $<min> | | |
- 14| Failure rate | over <x>% with at least <n> runs in a day | | |
- 16## When an alert fires
- 18| Alert | First 15 minutes | Same day | Who decides |
- 19| --- | --- | --- | --- |
- 20| Runaway runs (critical) | Find the run IDs in the alert, check for a loop or retry storm, stop the job or feature flag the task for that customer | Fix the cause, add a test, refund if the customer was billed for failures | Engineering on call |
- 21| Spend spike (critical) | Check if it is real use (a launch, a batch import) or a bug; message the account owner | If real, check the customer's cap and plan; if a bug, treat as runaway | Engineering on call + account owner |
- 22| Daily cap (critical) | Apply the agreed action: <throttle / queue / pause non-urgent tasks / notify only> | Talk to the customer about plan or overage | Account owner |
- 23| Monthly forecast (warning) | Nothing urgent | Account owner contacts customer before the cap is hit; offer a plan change | Account owner |
- 24| Failure rate (warning) | Check provider status and recent deploys | Fix or roll back; failed runs still cost money | Engineering |
- 26## What we never do automatically
- 28- Cut off a paying customer without a human decision.
- 29- Raise a cap without the account owner and finance agreeing.
- 31## How it runs
- 33- `node scripts/guardrails.mjs data/usage.csv --config data/guardrails.json --fail-on-alert` on a schedule (<daily at 9:00 / hourly>), after usage is exported.
- 34- Exit code 2 means at least one critical alert. <Where alerts go: a channel, an email, an on-call tool>.
