How to Set Hard Spend Limits on LLM APIs (2026 Guide)
The short answer
Put a hard cap at the provider, a smaller cap on each key or project, and an alert well before either. Most bill shocks come from one leaked key or one runaway agent loop, so the per-key cap matters more than the account cap. Where to set them, as of November 4, 2026:
| Platform | Hard cap at | What happens at the cap |
|---|---|---|
| OpenAI | Organization and each project | 429 organization_spend_limit_exceeded / project_spend_limit_exceeded |
| Anthropic | Organization and each workspace (not the default workspace) | 400 invalid_request_error, “You have reached your specified … API usage limits” |
| OpenRouter | Each API key (credit limit, daily/weekly/monthly reset) | Key stops working until reset or raise |
| Vercel AI Gateway | Team, project, API key or team member budgets | Requests blocked by the budget |
| Baseten | Workspace budget with Enforce budget | Only Model API requests rejected; GPU deployments keep running |
Taken from each vendor’s documentation on November 4, 2026. For pricing strategy around these costs, see how to price an AI product around token costs.
Step 1: Split spend by project, key or workspace
One key per app, environment and customer-facing agent. A cap on the shared org key alone means one bad loop takes production down with it.
- OpenAI: create a project per environment; each project gets its own rate and spend limits and a service-account key.
- Anthropic: create a workspace per app; you can set custom spend and rate limits per workspace, but not on the default workspace.
- OpenRouter: create keys through the Management API with a
limitandlimit_reset(daily,weeklyormonthly); workspace-scoped management keys can only manage keys in their own workspace.
Step 2: Set the hard caps
OpenAI. Go to Organization limits (or a project’s Settings → Limits) → Spend → Edit spend limit, enter the monthly amount, turn on Enforce a hard limit, save. An org limit applies across every project; a project limit only to that project. Traffic resumes after you raise the limit or at the next monthly cycle.
Anthropic. In the Claude Console, Billing → Spend limits → Set limit. Your own limit cannot exceed your tier’s cap: Start $500, Build $1,000, Scale $200,000 a month (Custom has no cap). Hitting your own limit returns 400 invalid_request_error; hitting the tier cap returns 429 with enforced_spend_limit_reached and no retry-after header, and pauses usage until 00:00 UTC on the 1st. Claude Code workspace limits are checked separately and can return a 429 with retry-after.
OpenRouter. Give every key a credit limit; use limit_reset: "daily" for agents so a runaway loop burns one day’s budget, not a month’s. include_byok_in_limit controls whether your own-key usage counts.
Vercel AI Gateway. Set budgets per team, project, API key or member. Note that exhausting a provider grant does not necessarily stop requests if another balance or automatic recharge can fund them — the budget is the control.
Baseten. Set a monthly budget (emails at 75%, 90%, 100%) and tick Enforce budget — but it only rejects Model API requests. For dedicated GPU deployments the real ceiling is max_replica; see Baseten billing and cost control.
Step 3: Add alerts below the cap
OpenAI spend alerts and Baseten budget emails keep firing alongside hard limits. Put the first alert at 50% and a second at 80% so someone can react before traffic stops.
Step 4: Handle the cap in code
A capped request is not a rate limit. Retrying it — including your SDK’s automatic retries — fails until the limit changes.
except APIStatusError as e:
code = getattr(e, "code", None) or (e.body or {}).get("error", {}).get("code")
if code in ("project_spend_limit_exceeded", "organization_spend_limit_exceeded",
"enforced_spend_limit_reached"):
disable_feature_and_page_oncall() # do not retry
elif e.status_code == 429:
backoff_and_retry()
Match on the error code, not only the status: OpenAI’s spend cap and its rate limit both return 429, and Anthropic’s own-limit response is a 400.
Step 5: Plan for overshoot
Caps lag. OpenAI states enforcement is not instantaneous and spend can slightly exceed the limit; Anthropic warns batches may go slightly over a workspace limit. Set the hard cap at the amount you would be annoyed to pay, not the amount that would hurt.
Common mistakes
- One key everywhere. A leak or loop has no blast radius limit.
- Alert-only limits. Alerts do not stop traffic; only “enforce” settings do.
- Forgetting GPU spend. Token caps do not cover rented GPUs — cap replicas.
- Retrying a spend-cap error. It wastes calls and hides the outage from your on-call.
Last verified: November 4, 2026.