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
- 3Sets spend caps, forecasts, spike rules, and runaway-run limits for each customer of your AI product, checks your usage against them, and writes a runbook for what to do when each alert fires. Exit code 2 on critical alerts, so it drops into a cron job or CI step.
- 5**Who it is for:** founders and engineers running agent products who have been surprised by a bill, or want to make sure they never are.
- 7## Example
- 9Input: `examples/usage.csv` (October usage, including a day when one customer's research agent looped), `examples/guardrails.json`.
- 11```
- 12node scripts/guardrails.mjs examples/usage.csv --config examples/guardrails.json --prices examples/prices.csv --as-of 2026-10-27
- 13```
- 15Output (`out/guardrails.md`):
- 17| Severity | Customer | Rule | Detail |
- 18| --- | --- | --- | --- |
- 19| CRITICAL | cobalt-labs | daily cap | Spent $23.39 on 2026-10-27, cap $4.00. |
- 20| CRITICAL | cobalt-labs | spend spike | 13.6x the 7-day median of $1.71. |
- 21| CRITICAL | cobalt-labs | runaway runs | 6 research_agent runs over $3.00 per run or 25 calls per run (up to 52 calls). |
- 22| WARNING | cobalt-labs | monthly forecast | On pace for $66.24 this month, over the $60.00 cap. |
- 23| WARNING | cobalt-labs | failure rate | 6 of 6 research_agent runs failed. |
- 25Plus `out/guardrails-runbook.md`, written with you from `templates/runbook.md`.
- 27## What it can access
- 29- Runs `node scripts/guardrails.mjs` (Node built-ins only).
- 30- Reads `data/`. Writes `data/guardrails.json` (your limits) and `out/guardrails*`.
- 31- No network. It reports; it never blocks or throttles anything.
- 33## Setup
- 35None to try it. To run it daily, schedule the command after your usage export. Check the example LLM prices against each provider's current pricing first.
