Back to blog

How to Set LLM Budget Limits That Actually Stop Spend

LLM budget limits only work when they are enforced before the request runs. Here is how to layer hard limits per API key, per developer, per team and per project in LLM Gateway, what happens when a limit is hit, and how to automate it from your backend.

By LLM Gateway

LLM budget limits concept: a glowing gauge with a hard stop on a circuit board chip, surrounded by coins, folders and people icons

Most teams find out about an LLM cost problem from the invoice. An agent loops on a tool call overnight, a test suite runs against a frontier model instead of a small one, or a key leaks into a public repository. By the time someone looks at a dashboard, the money is gone.

LLM budget limits fix that only if they are enforced in the request path. A spreadsheet, a monthly review or an email alert reports the damage; a hard limit prevents it. This guide shows how to layer budgets in LLM Gateway so every request is checked against the key, the developer, the team and the project it belongs to before it reaches a provider.

Alerts are not LLM budget limits

Provider consoles give you usage charts and, at best, a monthly cap on the whole account. That leaves two gaps:

  • No granularity. One account cap cannot tell the customer-facing chatbot apart from an engineer's experiment. When it trips, everything stops.
  • No speed. Billing data at most providers lags by hours. A runaway loop can spend a week's budget before a daily alert fires.

A gateway sees every request as it happens, so it can refuse the next one the moment a limit is reached.

Four layers of hard limits

LLM Gateway checks four kinds of budget on every request. A request has to fit inside all of them.

Layer Who sets it What it caps
API key The key's creator or admins One key, all-time and over a recurring window
Developer Owners and admins Every key one member creates, plus how many they own
Team Owners and admins A per-developer ceiling for everyone in a team
Project Owners and admins Every key in a project combined

Each layer takes two independent limits: an all-time cap and a recurring cap over a window of one hour to twelve months. The windows behave differently by layer:

  • API key periods start with the key's first request and reset in full once the period ends. A one-day period that starts at 09:37 resets at 09:37 the next day.
  • Developer, team and project windows roll and are aligned to whole hours. A one-day limit covers the current hour and the 23 before it, and old spend drops out as each hour passes.

API key limits

The narrowest layer. Give the key behind a cron job or a customer integration its own limit, so a bug in that one path cannot spend more than you planned for it. See API key usage limits.

Developer and team budgets

Set a default developer budget for the organization, override it per member, and add a team ceiling on top. A new hire gets a sensible limit on day one without anyone remembering to configure it. These live on the Team page. The Developer role and organization teams are part of the Enterprise plan; API key limits and project budgets are not.

Project budgets

The newest layer, and the one that answers the finance question: what can this product spend? A project budget counts every API key in the project, including keys that were disabled or deleted later, and covers both LLM Gateway credits and your own provider keys. Creating a fresh key does not reset it. End-user sessions from embeddable payments are the exception: they are funded by end-user wallets, so they neither count toward the project budget nor stop when it is reached.

Set it under Settings → Preferences in the project. Only organization owners and admins can change it, so a project admin cannot raise their own ceiling.

What happens when a limit is reached

Every endpoint that runs inference, from chat completions and embeddings to images, video, speech, realtime and batches, rejects the request with 401. A project budget returns the code project_usage_limit_exceeded:

1{2  "error": {3    "message": "Unauthorized: LLMGateway project reached its usage limit.",4    "type": "invalid_request_error",5    "param": null,6    "code": "project_usage_limit_exceeded"7  }8}

A few details matter in production:

  • Batches wait. Batch requests that hit the limit retry later instead of failing.
  • Free requests pass. Chat completions that cost nothing, such as free models, are never blocked.
  • Finished work stays reachable. Retrieving a video that already rendered still works.
  • Recovery is immediate. Raising or removing the limit takes effect at once.

Treat the limits as approximate. They are checked against recorded spend, which refreshes about once a minute, and a request's cost is not reserved in advance, so traffic can keep passing until recent spend is recorded. How far it overshoots depends on your traffic and request costs, so set limits with some headroom. If spend cannot be read at all, the check fails open rather than blocking all traffic.

Automate budgets from your backend

Platform teams rarely want to click through a dashboard for every new project or hire. On the Enterprise plan, the master API sets the same limits:

1curl -X PATCH https://internal.llmgateway.io/v1/master/projects/$PROJECT_ID \2  -H "Authorization: Bearer $MASTER_KEY" \3  -H "Content-Type: application/json" \4  -d '{5    "usageLimit": "5000.00",6    "periodUsageLimit": "500.00",7    "periodUsageDurationValue": 1,8    "periodUsageDurationUnit": "month"9  }'

Member budgets work the same way, addressed by email:

1curl -X PATCH https://internal.llmgateway.io/v1/master/members/jane@example.com/budget \2  -H "Authorization: Bearer $MASTER_KEY" \3  -H "Content-Type: application/json" \4  -d '{ "periodUsageLimit": "50.00", "periodUsageDurationValue": 1, "periodUsageDurationUnit": "month" }'

GET /v1/master/members/{member}/budget returns the member's own budget, the effective budget after organization defaults, the team ceiling and current spend in each window, which is what you need for an internal chargeback report. Every change lands in the audit log. Changing team budgets requires the Enterprise access control feature.

A starting setup

If you are setting this up for the first time:

  1. Put a recurring project budget on each product at about 1.5 times its normal monthly spend.
  2. On Enterprise, give the organization a default developer budget small enough that an experiment cannot hurt.
  3. Add key limits to anything that runs unattended: cron jobs, agents, CI.
  4. Turn on spend tracking by key and project so you can tighten the numbers after a month of real data.

Start capping LLM spend

Frequently asked questions

What is an LLM budget limit?
An LLM budget limit is a spending cap enforced by the system that sends requests to the model provider. In LLM Gateway it is checked before each request: once an API key, developer, team or project reaches its limit, the request is rejected with a 401 and never reaches the provider.
What is the difference between a spend alert and a hard budget?
An alert tells you after the money is spent. A hard budget rejects the next request once the limit is reached. LLM Gateway has both, but only the hard limits stop a runaway loop or a leaked key at 3 a.m.
Do project budgets count requests made with my own provider keys?
Yes. A project budget counts spend from LLM Gateway credits and from your own provider keys, across every API key in the project, including keys that were disabled or deleted later. Wallet-funded end-user sessions from embeddable payments are the one exception.
Can I set LLM budgets programmatically?
Yes, on the Enterprise plan, which includes master keys. With a master key, PATCH /v1/master/projects/{id} sets a project budget, and PATCH /v1/master/members/{member}/budget and PATCH /v1/master/teams/{id}/budget set member and team budgets. Changing team budgets also needs the Enterprise access control feature.
LLM Gateway

One API key for every model.

Route to 200+ models with automatic failover, caching, and real-time cost analytics. Free to start — no credit card required.

Not ready to switch yet?

Follow new model releases instead.

A short roundup when new models land. Unsubscribe anytime.