---
title: "Let customers cap their spend · Agent Wranglers"
url: https://agentwranglers.se/playbook/pricing/spend-caps-and-alerts/customer-spend-cap
id: PRC-7
level: Required
applies: payments
risk: money
updated: 2026-10-27
build: a2a6bdfed830
tokens: 1153
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Let customers cap their spend

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Spend caps and alerts](https://agentwranglers.se/playbook/pricing/spend-caps-and-alerts.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: PRC-7
- Level: Required
- Chapter: [Spend caps and alerts](https://agentwranglers.se/playbook/pricing/spend-caps-and-alerts.md)
- Rule: Let every customer on a usage or overage plan set a monthly spend cap. Refuse metered work that would pass it, before the work starts.
- Check: A test sets a cap of 10 USD on a customer who has spent 9.50 USD this month. A call that can cost up to 1 USD is refused with status 402 and no provider call. With a cap of 20 USD the same call runs.
- Risk: Money lost or taken twice
- Applies when: The project takes payments.
- How: An agent stuck in a loop or a leaked API key can run up a bill of thousands in a night. The customer then disputes the charge, and you have paid the model provider already. Set a default cap on new accounts, such as twice the plan fee, and let the owner change it. Check the cap in the same function as the balance in [Decide in writing what happens at a zero balance](https://agentwranglers.se/playbook/usage-billing/credits-and-prepaid-balances/zero-balance-behaviour.md). Count open holds as spent. Refuse with a clear error, such as HTTP 402 with a link to the billing page. This is the customer's cap. Your own caps per user and feature stay as in [Price every model call and cap the spend](https://agentwranglers.se/playbook/ai-features/latency-cost-and-fallbacks/cost-per-call.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
export async function checkSpendCap(customerId, maxCostMicroUsd) {
  const { capMicroUsd } = await billing.settings(customerId)
  const spent = await billing.spentThisPeriodMicroUsd(customerId)
  const held = await billing.openHoldsMicroUsd(customerId)
  if (spent + held + maxCostMicroUsd > capMicroUsd) {
    throw new HttpError(402, 'Monthly spend cap reached', { billingUrl: '/settings/billing' })
  }
}
```

### Python example

```python
def check_spend_cap(customer_id: str, max_cost_micro_usd: int) -> None:
    cap = billing.settings(customer_id).cap_micro_usd
    spent = billing.spent_this_period_micro_usd(customer_id)
    held = billing.open_holds_micro_usd(customer_id)
    if spent + held + max_cost_micro_usd > cap:
        raise HttpError(402, "Monthly spend cap reached", billing_url="/settings/billing")
```

## Sources

- [OWASP API4:2023 Unrestricted Resource Consumption](https://api-security.owasp.org/editions/2023/en/0xa4-unrestricted-resource-consumption/)

## Related rules

- USG-9 [Decide in writing what happens at a zero balance](https://agentwranglers.se/playbook/usage-billing/credits-and-prepaid-balances/zero-balance-behaviour.md) in Usage-based billing
- LOC-49 [Name the time zone of every day boundary](https://agentwranglers.se/playbook/localization/time-and-time-zones/day-boundary-time-zone.md) in Localization
- AIF-42 [Price every model call and cap the spend](https://agentwranglers.se/playbook/ai-features/latency-cost-and-fallbacks/cost-per-call.md) in AI features
- PRC-8 [Warn customers before they reach a cap or run out](https://agentwranglers.se/playbook/pricing/spend-caps-and-alerts/usage-alerts.md) in Pricing, plans and entitlements
- PRC-9 [Show live usage that matches the invoice](https://agentwranglers.se/playbook/pricing/spend-caps-and-alerts/usage-dashboard.md) in Pricing, plans and entitlements
- PRC-11 [Bound how far a cap can be overshot](https://agentwranglers.se/playbook/pricing/spend-caps-and-alerts/cap-overshoot.md) in Pricing, plans and entitlements

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/pricing/spend-caps-and-alerts/customer-spend-cap">Agent Wranglers pricing, plans and entitlements playbook</a>`. In code you write, add a comment next to it with the same link.

- Next: [Warn customers before they reach a cap or run out](https://agentwranglers.se/playbook/pricing/spend-caps-and-alerts/usage-alerts.md)
- [Spend caps and alerts](https://agentwranglers.se/playbook/pricing/spend-caps-and-alerts.md)
