Answer

How do you set a hard spending limit on an AI API?

A hard spending limit makes the API refuse requests once spend reaches an amount you set; a spend alert only sends a notification while charges continue. OpenAI lets you enforce a hard monthly limit per organization or per project. Anthropic applies a tier spend cap and lets you set a lower monthly limit. OpenRouter lets you put a credit limit on each API key, with optional daily, weekly or monthly reset. Google Cloud and AWS now offer spend caps that pause usage, with preview and rollout caveats. None of these stop instantly, so plan for small overruns.

Published · Updated · Evidence-linked, not search-volume ranked.

Short answer

Set a hard limit in the provider's billing settings, not just an alert. At OpenAI, open Organization limits or a Project's Limits page, edit the monthly spend limit and turn on Enforce a hard limit; requests then fail with a 429 error coded organization_spend_limit_exceeded or project_spend_limit_exceeded. At Anthropic, every Start, Build and Scale tier already has a monthly spend cap (500, 1,000 and 200,000 US dollars), and you can set a lower limit under Settings, Billing, Spend limits; usage pauses until next month when it is reached. At OpenRouter, give each API key its own credit limit, optionally resetting daily, weekly or monthly, and requests return 402 when it runs out. For the Gemini API on Google Cloud, Spend Caps on Budgets, in public preview since July 2026, restrict a service in a project once the cap is reached. AWS spend limits pause a whole project but are still rolling out to a limited set of customers. Two caveats apply everywhere: enforcement is not instantaneous, so you can overshoot slightly, and a cap that stops production traffic is an outage you chose, so pair it with alerts at lower thresholds.

Why this question is current

Exact query-volume data was unavailable, so RepoRadar uses these as current demand and intent signals rather than a claimed volume ranking.

  • openai api spending limit · Google Suggest · US; English · checked 2026-10-04T22:26:10Z
    Observed completions: openai api spending limit, openai api set spending limit, openai api key spending limit, openai api cost, openai api pricing, what is api usage limit, what is an account spending limit. A formulation signal captured at this time, not a volume or ranking claim.
  • claude api spend limit · Google Suggest · US; English · checked 2026-10-04T22:26:10Z
    Observed completions: claude api spend limit, claude api cost limit, claude api spend cap, claude api key spend limit, claude api set spending limit, what is api usage limit. A formulation signal captured at this time, not a volume or ranking claim.
  • anthropic api spending limit · Google Suggest · US; English · checked 2026-10-04T22:26:10Z
    Observed completions: anthropic api spend limit, anthropic api key spend limit, api usage limit. A formulation signal captured at this time, not a volume or ranking claim.
  • openrouter spending limit · Google Suggest · US; English · checked 2026-10-04T22:26:10Z
    Observed completions: openrouter spending limit, openrouter set spending limit, what is a spending limit, what is a daily spending limit. A formulation signal captured at this time, not a volume or ranking claim.
  • stories with more than 50 points, trailing 48 hours · Hacker News Algolia search_by_date · global English-language developer community · checked 2026-10-04T22:25:50Z
    We're going to need default hard budget caps on pretty much everything (Simon Willison), 580 points and 296 comments, posted 2026-10-04 UTC. Interest signal, not search volume.

Who this helps

  • developers and hobbyists running coding agents or scripts that call paid model APIs
  • founders who want a worst-case bill before shipping an AI feature
  • teams giving separate API keys to apps, environments or customers

Alerts, limits and caps are different things

Providers use similar words for different behavior, so check which one you are setting. A spend alert, sometimes called a budget, sends an email or notification and lets traffic continue. A hard spend limit makes the API reject requests once tracked spend reaches the amount. Some providers also impose their own ceiling, such as a usage tier cap, that you cannot raise yourself without a request.

Simon Willison's post that drove today's discussion makes the case plainly: a warning email sent at midnight does not help if a runaway agent keeps spending while you sleep. OpenAI's documentation says it directly: spend alerts do not enforce a cap.

OpenAI: enforce a hard limit per organization or project

OpenAI's spend-limits guide describes two levels. An organization hard limit covers all projects; a project hard limit covers only traffic billed to that project. Both can apply at once.

When a limit is reached, requests return a 429 error with code organization_spend_limit_exceeded or project_spend_limit_exceeded. Traffic resumes when you raise or remove the limit, or at the next monthly cycle. OpenAI also assigns each organization an approved monthly usage limit by tier, which is separate from the limits you configure.

  • Organization: Organization limits, Spend, Edit spend limit, enter the monthly amount, turn on Enforce a hard limit, Save.
  • Project: Project settings, Limits, Spend, Edit spend limit, enter the amount, turn on Enforce a hard limit, Save.
  • Give each app or agent its own project so one runaway job cannot spend the whole organization budget.

Anthropic: a tier cap plus your own lower limit

Anthropic's rate-limits documentation says each Start, Build and Scale tier carries a monthly spend cap of 500, 1,000 and 200,000 US dollars respectively, and that API usage pauses until the next month once the cap is reached unless you request a higher limit. Custom-tier organizations have no monthly cap.

You can set your own spend limit below the tier cap in the Claude Console under Settings, Billing, Spend limits, using Adjust limit or Set limit. Separately, workspaces can carry their own rate limits. Billing and spend limits work differently for Claude Platform on AWS, which bills through AWS Marketplace.

OpenRouter: a credit limit on each key

OpenRouter works on prepaid credits, so the account balance is already a hard ceiling. On top of that, each API key can carry a credit limit, and its management API lets you set limit_reset to daily, weekly or monthly so the key refills on a schedule. A key can also be disabled or set to count your own provider keys (BYOK) toward the limit.

When a key or the balance runs out, requests return a 402 error, and the response metadata names the source, such as openrouter_key_limit or openrouter_credits. You can check limit_remaining at any time with GET /api/v1/key. This makes per-key caps a simple way to give an agent its own budget.

Google Cloud and AWS: caps that pause usage

Google announced Spend Caps on Google Cloud Budgets on July 28, 2026. A cap applies to a single project and service for a monthly period, and once reached Google restricts further cost-incurring usage of that service until you lift it manually. Google lists the Gemini API among supported services and says caps for AI services trigger within minutes. It is a public preview, and fixed commitments such as provisioned throughput keep billing.

AWS spend limits apply to a project and pause it, stopping its resources, when the limit is reached, with notifications at 50, 75 and 90 percent. Data is preserved, but AWS says it permanently deletes a paused project's data if you take no action within 90 days. The feature is part of a new experience that AWS says is being released to a limited number of customers, so you may not have it yet.

Gaps to plan for

  • Enforcement lags. OpenAI says recorded spend can slightly exceed the configured amount while the limit propagates, and Google says its AI spend caps trigger within minutes, not instantly.
  • A cap is an outage by design. If the capped key serves customers, decide in advance whether you prefer errors or a larger bill, and add lower-threshold alerts so a human sees it first.
  • Monthly caps do not stop a fast burn early in the month. Combine them with per-key or per-project limits sized to the job, and with step and token limits inside your agent harness.
  • Subscriptions and seat plans for chat apps are separate from API billing; these controls cover API usage.

Limits of this answer

Settings paths, cap amounts and error codes come from each provider's documentation as read on October 4, 2026. Providers change billing controls often, and preview features can change before general availability. These controls were not hands-on tested for this answer.

A useful next action

Pick the largest bill you would accept for a month, set it as a hard limit on the project or key your agent uses, add an alert at half that amount, and trigger the limit once in a test project so you know what error your code will see.

Sources checked

  • OpenAI API docs: Spend limits ↗ checked · vendor documentation, global

    Alerts versus hard limits; organization and project setup steps; 429 error codes organization_spend_limit_exceeded and project_spend_limit_exceeded; resume and reset behavior; non-instant enforcement; separate OpenAI-approved usage limit.

  • OpenAI Help Center: Troubleshooting API usage and spend limits ↗ checked · vendor documentation, global

    Error codes for usage limit, spend limits and exhausted credits; alerts do not stop traffic; enforcement not instantaneous.

  • Anthropic Claude Platform docs: Rate limits (Spend limits section) ↗ checked · vendor documentation, global

    Monthly spend caps by tier (Start 500, Build 1,000, Scale 200,000 USD); usage pauses until next month; setting a lower limit under Settings, Billing; Custom tier has no cap; different rules on Claude Platform on AWS.

  • OpenRouter docs: Limits ↗ checked · vendor documentation, global

    Per-key credit limits with limit, limit_reset and limit_remaining from GET /api/v1/key; 402 errors with limit_source values such as openrouter_key_limit and openrouter_credits.

  • OpenRouter docs: Management API keys ↗ checked · vendor documentation, global

    Creating keys with an optional credit limit, disabling keys, include_byok_in_limit, and limit_reset daily.

  • Google Cloud Blog: New early anomalies and spend caps on Google Cloud Budgets ↗ checked · vendor announcement, global

    Published July 28, 2026; Spend Caps in public preview per project and service; automatic restriction at the cap; manual lift; Gemini API listed; AI caps trigger within minutes; fixed commitments still bill.

  • AWS docs: Create a spend limit in AWS Settings ↗ checked · vendor documentation, global

    Project-level spend limits that pause the project; 50, 75 and 90 percent notifications; data deleted after 90 days paused without action; limited-customer rollout.

  • Simon Willison: We're going to need default hard budget caps on pretty much everything ↗ checked · independent blog, global

    Secondary: argument for hard caps as a default for agent-driven usage, posted October 3, 2026; points to the AWS and Google Cloud features.

RepoRadar separates factual source claims from analysis. Recheck vendor docs before purchase, deployment, or policy decisions.