LLM Gateway
Features

Project budgets

Hard all-time and recurring spend limits for a whole project

A project budget caps the spend of every API key in a project. It works like an API key usage limit, but applies to the project as a whole, alongside the per-key limits and the member and team budgets from the Team page.

You can set two independent limits:

  • All-time limit: a lifetime spend cap for the project
  • Recurring limit: a spend cap over a rolling window of 1 hour to 12 months (units: hour, day, week, month)

Set a budget

In the dashboard, open Settings → Preferences for the project. The Budget card shows the project's all-time spend, the spend in the current window and any configured limits. Only organization owners and admins can change a budget; project admins can see it but not raise it.

With a master key, pass usageLimit, periodUsageLimit, periodUsageDurationValue and periodUsageDurationUnit to PATCH /v1/master/projects/{id}. Send null to remove a limit; a null periodUsageLimit also clears its period. A recurring limit needs both a duration value and unit. If another request changed the budget since yours read it, the update returns 409 and you can retry. Every change is recorded in the audit log as project.budget_update.

How spend is counted

  • All-time spend is the total usage of every API key in the project, including keys that were later disabled or deleted. It includes spend from LLM Gateway credits and from your own provider keys. Keys are removed for good only when the user who created them deletes their account, and their spend then no longer counts.
  • Recurring spend sums the project's hourly usage over the window. The window is aligned to whole hours: a 1-day limit covers the current hour plus the 23 before it, so older spend drops out as each hour passes.
  • On chat completions, and the image and Messages endpoints built on it, requests that cost nothing (free models, zero-priced custom providers) are never blocked by a budget. Other endpoints, including Responses and MCP tools, check the budget before the route's cost is known, like the API key usage limits do.
  • Embeddable payments end-user sessions are funded by end-user wallets and limited per session, so they neither count toward nor are blocked by the project budget.
  • Retrieving finished videos stays available when the budget is exhausted.

Spend is read from usage aggregates that refresh about once a minute, so requests already in flight, or sent within that minute, can overshoot a limit slightly. If spend cannot be read at all, for example during a database outage, the check fails open and lets requests through rather than blocking all traffic.

When the budget is reached

Every endpoint that runs inference (chat completions, Responses, Messages, embeddings, images, video, speech, transcription, realtime, batches and the rest) rejects the request with 401 Unauthorized, the same status as an API key that reached its own usage limit. OpenAI-format endpoints return error code project_usage_limit_exceeded:

{
	"error": {
		"message": "Unauthorized: LLMGateway project reached its usage limit.",
		"type": "invalid_request_error",
		"param": null,
		"code": "project_usage_limit_exceeded"
	}
}

The Anthropic-format Messages endpoint returns the same message in its own error body, which has no code field. Realtime sessions receive project_usage_limit_exceeded as the error code when connecting, and per turn once a session is open.

Requests succeed again once you raise or remove the limit, which takes effect immediately, or, for a recurring limit, once enough spend has left the window. Batch requests that hit the limit wait and retry instead of failing.

How is this guide?

Last updated on

On this page

Ready for production?

Ship to production with SSO, audit logs, spend controls, and guardrails your security team will approve.

Explore Enterprise