LLM budget caps compared: which ones stop the next request

Which LLM spend limits stop the next request and which only send an email: provider consoles, cloud budgets, AI gateways and agent SDK settings, compared, with a per-run budget in code.

· 9 min read

An alert is not a cap. Of the limits on LLM spend, the ones that refuse the next request are: the output token limit on each request, the turn and budget limits in agent SDKs, OpenAI’s hard spend limits, Anthropic’s Console spend limits, Gemini API spend caps, and the budgets in AI gateways such as Vercel, Cloudflare, LiteLLM, OpenRouter and Portkey. AWS Budgets, Azure budgets and Google Cloud’s alerts-only budgets send a message, usually hours after the money is spent, unless you wire an action to them yourself.

Even the caps that stop work rarely stop it exactly at the line. Most let the request that crosses it finish, and several learn about spend seconds or minutes late. This page compares them level by level from each vendor’s own documentation, then shows a per-run budget in code that refuses a call before it can go over. It is one part of spending controls for AI agents, which also covers what the agent buys.

Four levels of limit

Each level answers a different question, and none of them answers all four:

Per request
How much can one model call generate? A maximum on output tokens, thinking included. It caps the worst single call, not how many calls there are.
Per run
How much can one task cost? Turn limits and dollar budgets in the agent SDK or your own loop. Only code that sees every turn can enforce this.
Per key, project or month
How much can this team or product spend in total? Provider consoles and cloud billing. The last line of defence, with the longest delay.
Gateway
The same question, answered in a proxy that every request passes through, often per key or per user, with daily or weekly periods the providers do not offer.

Which limits stop the next request

Checked 23 November 2026 against each vendor’s documentation, listed under sources. “Stops” means the next request is refused or cut off; “alerts” means someone is told and traffic carries on. Features marked beta or experimental can change.

In the request and the run

Per-request and per-run LLM limits: what each stops, when it resets, and its caveats
OptionLevelStops or alertsResetsNotes
OpenAI max_output_tokens (Responses API)LevelOne requestStops or alertsStops. Generation ends and the response comes back with status incomplete, reason max_output_tokens.ResetsEvery requestNotesCounts reasoning tokens too. The limit can be hit before any visible output, and you still pay for the input and reasoning tokens.
Anthropic max_tokens (Messages API)LevelOne requestStops or alertsStops. The response ends with stop_reason: "max_tokens".ResetsEvery requestNotesA required field. A manual thinking budget, budget_tokens, must be at least 1,024 and less than max_tokens, so thinking comes out of the same ceiling.
Anthropic task budgets (beta)LevelOne agentic loop, in tokensStops or alertsNeither. The model sees a countdown and paces itself; Anthropic calls it “a soft hint, not a hard cap”.ResetsEach new user messageNotesBeta, set in output_config.task_budget, minimum 20,000 tokens. Pair it with max_tokens, which is the enforced limit.
Claude Agent SDK maxBudgetUsd / max_budget_usdLevelOne query() callStops or alertsStops, after the response that reaches it. Result subtype error_max_budget_usd.ResetsPer call; a /clear starts it overNotesChecked after each response arrives, so spend can pass it by one response plus what running subagents spend. Priced from a table bundled with the SDK: an estimate, not your bill.
Claude Code --max-budget-usd and --max-turnsLevelOne runStops or alertsStops the run once the turn count or estimated spend reaches the cap.ResetsPer runNotesPrint mode (-p) only. The budget uses the same client-side estimate as the Agent SDK and can be passed, so leave headroom. --max-turns has no limit by default, nor has maxTurns in the Agent SDK.
OpenAI Agents SDK maxTurns / max_turnsLevelOne runStops or alertsStops. Throws MaxTurnsExceededError (TypeScript) or MaxTurnsExceeded (Python).ResetsPer runNotesCounts turns, not money. The TypeScript default is 10; null or None removes the limit. An error handler can turn the error into a final answer. The run guides we read describe no cost budget.
Claude Managed Agents session budget (beta)LevelOne sessionStops or alertsStops new model requests. The session goes idle with budget_reached; the request in flight still completes.ResetsNever; set per session (a deployment copies it to each session)NotesBeta. max_list_cost in US cents at list prices, including web searches and running time. Overshoot is at most one model request per thread.

In the account, the cloud and the gateway

Provider console, cloud billing and AI gateway budgets: whether each stops requests or only alerts
OptionLevelStops or alertsResetsNotes
OpenAI spend limitsLevelOrganization or project, per monthStops or alertsA hard limit stops: 429 with project_spend_limit_exceeded or organization_spend_limit_exceeded. A spend alert only notifies.ResetsNext monthly cycleNotesEnforcement is not instantaneous, so recorded spend can slightly exceed the limit. No per-key limit on that page.
Anthropic Console spend limitsLevelOrganization and each workspace, per monthStops or alertsStops: 400 invalid_request_error, “You have reached your specified API usage limits”.ResetsMonthly; the error says when access resumesNotesSet below your tier’s cap, which stops with a 429 of its own. A limit on the default workspace may not count Console, Managed Agents or Claude Code use there.
Gemini API project spend cap (AI Studio)LevelProject, per monthStops or alertsStops, but billing data can lag about ten minutes, and overages in that window are yours.Resets1st of the monthNotesGoogle calls it experimental. Batch jobs and agent sessions may run past the cap. Tier caps also pause every project on the billing account.
Google Cloud spend cap budgetsLevelOne service in one projectStops or alertsStops new usage of that service; requests in flight finish.ResetsNext budget periodNotesGemini API and Vertex AI are on the eligible list. Not instantaneous, and you pay the overage. Persistent resources keep running.
Google Cloud alerts-only budgetsLevelBilling account or projectStops or alertsAlerts only. A Pub/Sub message can trigger your own function that disables billing.ResetsBudget periodNotesDisabling billing shuts down every resource in the project and may delete some. Google says it does not guarantee you stay under budget.
AWS Budgets (Bedrock included)LevelAccount, filtered by service or tagStops or alertsAlerts. A budget action can apply a deny IAM policy or SCP, or stop EC2 and RDS instances, automatically or after approval.ResetsBudget periodNotesData is updated up to three times a day, so costs can pass the threshold before anyone hears. A budget can be filtered to one service, such as Bedrock.
Azure Cost Management budgetsLevelSubscription, resource group, billing scopesStops or alertsAlerts. “Resources aren’t affected, and your consumption isn’t stopped.” An action group can run automation.ResetsMonthly, quarterly or yearlyNotesCost data arrives within 8 to 24 hours and budgets are evaluated every 24 hours.
Vercel AI Gateway budgetsLevelTeam, project, API key or memberStops or alertsStops: 402 quota_for_entity_exceeded. Alerts at 50, 75 and 100% only notify.ResetsDaily, weekly, monthly (UTC) or neverNotesChecked at the start of each request, so the request that crosses the line completes. Spend on your own provider keys (BYOK) is not counted.
Cloudflare AI Gateway spend limitsLevelGateway rules by provider, model or metadataStops or alertsStops with 429, or falls back to a cheaper model if you set up a route.ResetsRolling or fixed windowNotesEventually consistent: cost is recorded after each request, so a burst of concurrent requests can briefly exceed the limit. Up to 20 rules per gateway.
LiteLLM proxy budgetsLevelKey, user, team, customer or the whole proxyStops or alertsStops: requests fail once max_budget is crossed.Resetsbudget_duration such as 30m or 30d; never if unsetNotesNeeds a database, or requests keep being served past the limit. Budget edits take up to a minute. Per-model budgets need an Enterprise licence.
OpenRouter per-key credit limitLevelAPI keyStops or alertsStops: 402 with limit_source openrouter_key_limit.ResetsDaily, weekly, monthly (midnight UTC) or neverNotesRaise the key’s limit or wait for the reset.
Portkey budget limitsLevelProvider integration or workspaceStops or alertsStops: the key expires at the limit, in dollars or tokens. A separate threshold sends an email.ResetsNever, weekly or monthly (UTC)NotesEnterprise and select Pro customers. A limit cannot be edited once set, and models without pricing do not count.

A cap only covers the traffic that goes through it. Gateway budgets do not see calls made straight to the provider with another key, and Vercel does not count spend on your own provider keys. Give each agent its own key so the cap and the logs line up.

Why a hard cap still overshoots

The documentation describes three ways of enforcing a limit:

  • Checked before each request. Vercel AI Gateway and Claude Managed Agents look at spend so far before letting a request start. The request that carries the total over the line was admitted while it was still under, so it completes. Overshoot is about one request per thread or concurrent caller.
  • Checked after each response. The Claude Agent SDK’s maxBudgetUsd compares spend with the cap when a response arrives, because the cost comes from the usage the API returns. Anthropic’s docs say to leave headroom for one response plus whatever running subagents spend before they stop.
  • Learned with a delay. OpenAI says enforcement “is not instantaneous”; the Gemini API names about ten minutes; Cloudflare’s limits are eventually consistent, so a burst of concurrent requests can briefly pass them. During that window an agent loop with many parallel calls keeps spending.

Cloud budgets sit further out still. AWS updates budget data up to three times a day, and Azure evaluates budgets every 24 hours on cost data that is 8 to 24 hours old. By the time either one emails, a runaway loop has had most of a day.

A per-run budget in code

A run budget is the limit you control most precisely, because your code sees every call. The version below does two things: before each call it prices the worst case (every input token at the dearest input rate, plus the full max_tokens of output) and refuses the call if that would pass the ceiling; after each call it adds what the provider reported. Cache writes have two prices by lifetime: Anthropic charges 1.25 times the input price for a 5-minute write and 2 times for a 1-hour one, OpenAI 1.25 times for 30 minutes and 2.5 times for 12 hours. Both report the split in their usage, and the code prices each part. The price table is yours to fill in from your provider’s price page.

// US dollars per million tokens, from your provider's price page, with any
// surcharge that applies to your calls already multiplied in.
export interface Price {
  input: number; // ordinary input
  cacheWriteShort: number; // Anthropic 5-minute or OpenAI 30-minute write
  cacheWriteLong: number; // Anthropic 1-hour or OpenAI 12-hour write
  cacheRead: number; // input read from the prompt cache
  output: number; // output, thinking and reasoning tokens included
}

export interface Tokens {
  input: number;
  cacheWriteShort: number;
  cacheWriteLong: number;
  cacheRead: number;
  output: number;
}

export class BudgetExceeded extends Error {
  constructor(spent: number, next: number, ceiling: number) {
    super(
      `run budget: $${spent.toFixed(4)} spent, next call up to $${next.toFixed(4)}, ceiling $${ceiling}`
    );
    this.name = "BudgetExceeded";
  }
}

const PER_TOKEN = 1 / 1_000_000;

function cost(price: Price, t: Tokens): number {
  const usd =
    t.input * price.input +
    t.cacheWriteShort * price.cacheWriteShort +
    t.cacheWriteLong * price.cacheWriteLong +
    t.cacheRead * price.cacheRead +
    t.output * price.output;
  return usd * PER_TOKEN;
}

export class RunBudget {
  private readonly ceilingUsd: number;
  private readonly price: Price;
  private spent = 0;

  constructor(ceilingUsd: number, price: Price) {
    this.ceilingUsd = ceilingUsd;
    this.price = price;
  }

  // Before every call: refuse it if its worst case would pass the ceiling.
  // Worst case: every input token at the dearest input rate, plus the full
  // max output.
  reserve(inputTokens: number, maxOutputTokens: number): void {
    const { input, cacheWriteShort, cacheWriteLong, output } = this.price;
    const inputRate = Math.max(input, cacheWriteShort, cacheWriteLong);
    const usd = inputTokens * inputRate + maxOutputTokens * output;
    const next = usd * PER_TOKEN;
    if (this.spent + next > this.ceilingUsd) {
      throw new BudgetExceeded(this.spent, next, this.ceilingUsd);
    }
  }

  // After every call: add what the provider says the call used.
  record(tokens: Tokens): number {
    this.spent += cost(this.price, tokens);
    return this.spent;
  }
}

// Anthropic Messages: input_tokens leaves out cached tokens, reported apart.
// Without a breakdown by lifetime, count every write at the dearer rate.
export function fromAnthropic(u: {
  input_tokens: number;
  output_tokens: number;
  cache_creation: {
    ephemeral_5m_input_tokens: number;
    ephemeral_1h_input_tokens: number;
  } | null;
  cache_creation_input_tokens: number | null;
  cache_read_input_tokens: number | null;
}): Tokens {
  const writes = u.cache_creation_input_tokens ?? 0;
  return {
    input: u.input_tokens,
    cacheWriteShort: u.cache_creation?.ephemeral_5m_input_tokens ?? 0,
    cacheWriteLong: u.cache_creation?.ephemeral_1h_input_tokens ?? writes,
    cacheRead: u.cache_read_input_tokens ?? 0,
    output: u.output_tokens,
  };
}

// OpenAI Responses: input_tokens includes cache reads and writes.
// Without a breakdown by lifetime, count every write at the dearer rate.
export function fromOpenAI(u: {
  input_tokens: number;
  output_tokens: number;
  input_tokens_details: {
    cached_tokens: number;
    cache_write_tokens?: number;
    cache_write_tokens_details?: {
      ttl_30m_tokens: number;
      ttl_12h_tokens: number;
    };
  };
}): Tokens {
  const details = u.input_tokens_details;
  const cacheRead = details.cached_tokens;
  const writes = details.cache_write_tokens ?? 0;
  return {
    input: u.input_tokens - cacheRead - writes,
    cacheWriteShort: details.cache_write_tokens_details?.ttl_30m_tokens ?? 0,
    cacheWriteLong: details.cache_write_tokens_details?.ttl_12h_tokens ?? writes,
    cacheRead,
    output: u.output_tokens,
  };
}

In an agent loop on the Claude Messages API, the input count comes from the token counting endpoint, which Anthropic documents as free and rate-limited separately from messages:

import Anthropic from "@anthropic-ai/sdk";
import { fromAnthropic, type Price, RunBudget } from "./run-budget";

// Your tool runner: runs each tool_use block and returns its results.
declare function runTools(
  content: Anthropic.ContentBlock[]
): Promise<Anthropic.ToolResultBlockParam[]>;

const client = new Anthropic();
const MODEL = "your-model-id";
const PRICE: Price = {
  input: 0, // fill in all five
  cacheWriteShort: 0,
  cacheWriteLong: 0,
  cacheRead: 0,
  output: 0,
};
const MAX_OUTPUT = 8000; // per call, thinking included

export async function runAgent(
  messages: Anthropic.MessageParam[],
  tools: Anthropic.Tool[]
) {
  const budget = new RunBudget(0.5, PRICE); // this run may spend $0.50
  for (let turn = 1; turn <= 40; turn++) {
    // The count is an estimate, so keep a margin in the ceiling.
    const { input_tokens } = await client.messages.countTokens({
      model: MODEL,
      messages,
      tools,
    });
    budget.reserve(input_tokens, MAX_OUTPUT); // throws BudgetExceeded

    const reply = await client.messages.create({
      model: MODEL,
      max_tokens: MAX_OUTPUT,
      messages,
      tools,
    });
    budget.record(fromAnthropic(reply.usage));
    if (reply.stop_reason !== "tool_use") return reply;

    messages.push({ role: "assistant", content: reply.content });
    messages.push({ role: "user", content: await runTools(reply.content) });
  }
  throw new Error("turn limit");
}
  • It refuses, it does not warn. BudgetExceeded is thrown before the call, so the run stops with the ceiling intact. As long as the price table holds the dearest rate that applies to the call, spend cannot pass the ceiling by more than the gap between the counted and the billed input, which Anthropic describes as small. The code models no surcharges, so multiply them into the table yourself: on the Claude API, for example, US-only inference costs 1.1 times, fast mode has its own higher prices, and Claude Haiku 5.5 charges more for prompts over 100,000 tokens.
  • The usage fields differ by provider. On the Claude Messages API, input_tokens leaves out cache reads and writes, which come in their own fields. On the OpenAI Responses API, input_tokens includes cached_tokens and cache_write_tokens, so fromOpenAI subtracts them. Reasoning and thinking tokens are billed as output on both.
  • Not everything is tokens. Server-side tools such as web search carry their own fees. Add them in record, or keep those tools out of budgeted runs.
  • We type-checked it. Both files compile with tsc --strict against @anthropic-ai/sdk 1.13.0 and openai 7.63.0, and we ran RunBudget on sample numbers to check that it throws. We did not run the loop against the live API.

A run budget is one of several limits in a loop. Step limits, time limits and spotting the same tool call repeated are in the circuit breaker in OWASP LLM06:2026 Unbounded Consumption; use both. If you use the Claude Agent SDK, its maxBudgetUsd does the same job with one response of headroom, and the OpenAI Agents SDK’s maxTurns bounds the number of calls but not their price.

What model budgets do not cover

Every limit on this page counts tokens. None of them sees what the agent does with its tools: a purchase, a refund, an ad budget raised, a database cluster started, a paid API called five thousand times. One cheap model call can trigger any of these, and a model budget of fifty cents will let it.

Those need a cap on the action itself, checked outside the model on an amount your code calculates, and a person above a line. Spending limits for AI agents sets out per-payment, per-period and per-supplier limits, and virtual cards for AI agents makes the card itself unable to pay more than was approved.

VariantGate sits at that layer. An agent asks before an action with an amount and a currency; rules a workspace owner wrote allow it up to a limit, with a budget per day, week or month, and anything above waits for a person. A request with no amount, or in another currency, never passes an allow rule with a limit. VariantGate never sees a token, so it does not replace any limit on this page. The approval limit calculator helps pick where that line sits, and the rules documentation has every option.

Picking the numbers

Pick numbers from your own logs, not from a guess. A week of normal traffic is usually enough to start:

  1. Log the cost of every run, with the agent key and the task type. The provider usage fields above are enough; the Claude Agent SDK also reports total_cost_usd per call, as an estimate.
  2. For each task type, find the 99th percentile of run cost. Set the run ceiling at a small multiple of it, so a normal run never trips it and a loop trips it quickly. Anthropic’s task budget guide suggests starting from p99 for the same reason.
  3. Set max_tokens or max_output_tokens from the longest useful answer you saw, with room for thinking, not from the model’s maximum.
  4. Give each agent its own key with a daily cap in your gateway, sized to a normal day plus a margin. A daily period limits a bad night to one day of spend; a monthly one does not.
  5. Set the provider’s monthly hard limit above the sum of the daily caps, as a backstop, and turn on its alerts as well.
  6. Log every trip. A cap that fires every week is set too low, or the agent has a bug worth finding.

When the bill is climbing and nobody knows why yet, stopping all agents at once comes before tuning any number; see emergency stop.

Sources

  1. OpenAI: Reasoning models (max_output_tokens includes reasoning tokens; incomplete responses)
  2. OpenAI: Spend limits (spend alerts, organization and project hard limits, 429 codes)
  3. OpenAI: Prompt caching (cached_tokens and cache_write_tokens inside input_tokens)
  4. OpenAI Agents SDK for TypeScript: Running agents (maxTurns, MaxTurnsExceededError, errorHandlers)
  5. OpenAI Agents SDK for Python: Running agents (max_turns, MaxTurnsExceeded, error_handlers)
  6. Claude API reference: Create a Message (max_tokens, thinking.budget_tokens)
  7. Claude API: Task budgets (beta, advisory, not enforced)
  8. Claude API: Token counting (free, an estimate)
  9. Anthropic: Pricing (cache write multipliers, US-only inference, fast mode and long-context prices)
  10. Claude API: Rate limits (tier spend caps, your own spend limit, workspace limits)
  11. Claude Managed Agents: Session budgets (beta, max_list_cost)
  12. Claude Agent SDK: How the agent loop works (maxTurns, maxBudgetUsd, budget headroom)
  13. Claude Agent SDK: Track cost and usage (total_cost_usd is a client-side estimate)
  14. Claude Code: CLI reference (--max-budget-usd, --max-turns)
  15. Google AI Studio: Billing for the Gemini API (project and tier spend caps)
  16. Google Cloud Billing: Create, edit, or delete budgets and alerts
  17. Google Cloud Billing: Spend cap budgets (eligible services)
  18. Google Cloud Billing: Disable billing usage with notifications (Pub/Sub and a function)
  19. AWS Budgets: Managing your costs (updated up to three times a day; notification delay)
  20. AWS Budgets: Configuring budget actions (IAM policy, SCP, EC2, RDS)
  21. Microsoft Cost Management: Create and manage budgets
  22. Vercel AI Gateway: Budgets and spend limits
  23. Cloudflare AI Gateway: Spend limits
  24. LiteLLM proxy: Budgets and rate limits (max_budget, budget_duration)
  25. OpenRouter: Limits (per-key credit limits, 402 openrouter_key_limit)
  26. OpenRouter TypeScript SDK: key limit_reset values
  27. Portkey: Budget limits

Give your agents somewhere to ask.

Free for 100 requests a month. Sign in with your email and have a first request waiting a few minutes from now.

Start free