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{
- 2 "name": "consumption-guardrails",
- 3 "owner": "agentcosts",
- 4 "version": "1.0.0",
- 5 "type": "skill",
- 6 "description": "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.",
- 7 "category": "devops",
- 8 "license": "MIT",
- 9 "compat": ["claude-code"],
- 10 "permissions": {
- 11 "shell": ["node scripts/guardrails.mjs"],
- 12 "files": { "read": ["./data/**"], "write": ["./data/guardrails.json", "./out/guardrails*"] }
- 13 },
- 14 "tests": {
- 15 "cases": [
- 16 {
- 17 "name": "catches the example spike, cap breach, and runaway runs",
- 18 "inputs": {},
- 19 "checks": [
- 20 { "type": "command_exits_zero", "command": "node scripts/guardrails.mjs examples/usage.csv --config examples/guardrails.json --prices examples/prices.csv --as-of 2026-10-27 --out out/guardrails" },
- 21 { "type": "file_contains", "path": "out/guardrails.md", "text": "| CRITICAL | cobalt-labs | runaway runs |" },
- 22 {
- 23 "type": "output_matches_schema",
- 24 "path": "out/guardrails.json",
- 25 "schema": {
- 26 "type": "object",
- 27 "required": ["as_of", "counts", "alerts", "customers"],
- 28 "properties": {
- 29 "as_of": { "const": "2026-10-27" },
- 30 "counts": { "const": { "critical": 3, "warning": 2, "info": 0 } },
- 31 "alerts": {
- 32 "type": "array",
- 33 "minItems": 5,
- 34 "maxItems": 5,
- 35 "items": { "type": "object", "properties": { "customer": { "const": "cobalt-labs" } } }
- 36 },
- 37 "runaway_runs": { "type": "array", "minItems": 6, "maxItems": 6 }
- 38 }
- 39 }
- 40 }
- 41 ]
- 42 },
- 43 {
- 44 "name": "forecasts the month and warns before the cap",
- 45 "inputs": {
- 46 "data/usage.csv": "timestamp,customer,task,model,cost_usd\n2026-11-01T10:00:00Z,a,t,m,10\n2026-11-02T10:00:00Z,a,t,m,10\n2026-11-03T10:00:00Z,a,t,m,10\n",
- 47 "data/guardrails.json": "{\"defaults\":{\"monthly_cap_usd\":200,\"daily_cap_usd\":50}}"
- 48 },
- 49 "checks": [
- 50 { "type": "command_exits_zero", "command": "node scripts/guardrails.mjs data/usage.csv --config data/guardrails.json --fail-on-alert --out out/guardrails" },
- 51 {
- 52 "type": "output_matches_schema",
- 53 "path": "out/guardrails.json",
- 54 "schema": {
- 55 "type": "object",
- 56 "properties": {
- 57 "counts": { "const": { "critical": 0, "warning": 1, "info": 0 } },
- 58 "customers": { "type": "array", "items": { "type": "object", "properties": { "month_to_date": { "const": 30 }, "forecast_month": { "const": 300 } } } }
- 59 }
- 60 }
- 61 }
- 62 ]
- 63 }
- 64 ]
- 65 }
- 66}
