For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Budget and spend limits
Combine global USD or token spending limits with budgets for teams, users, and API keys by using the EnterpriseAgentgatewayBudget resource.
Solo Enterprise for agentgateway includes a declarative EnterpriseAgentgatewayBudget API for AI workloads. This way, you can state the limits for your budget directly, such as “each API key can spend up to 50 USD per month” or “The Engineering Team can consume up to 1 million tokens per week.”
The agentgateway controller compiles each budget into configuration for the built-in global rate limit service, which is deployed by default along with its Redis-backed cache. You do not need to deploy any extra infrastructure.
Budgets complement other rate limiting features:
- Budgets (this section): Limit spend in dollars (USD) or tokens over long windows (day to year), keyed by business dimensions such as team, user, or API key. Requires only an EnterpriseAgentgatewayBudget resource and a policy that enables enforcement.
- Global rate limiting: Limit request or token rates over short windows with custom RateLimitConfig descriptors that you write yourself.
- Local rate limiting: Per-replica request limits without shared state.
How budget enforcement works
Review the following diagram to understand how agentgateway resources work together to enforce budgets.
flowchart LR
A[EnterpriseAgentgatewayBudget] --> C[Controller discovers budgets<br>and generates rate limit]
B[EnterpriseAgentgatewayPolicy] --> C
D[Request arrives] --> E[Proxy resolves budget dimensions<br>such as virtual key, user, model]
C --> E
E --> F{Any matching budget<br>over its limit?}
F -->|No| G[Request proceeds;<br>actual token or USD usage<br>is debited after the response]
F -->|Yes, action Block| H[Reject with 429]
F -->|Yes, action Audit| I[Log the overage;<br>request proceeds]
- The Budget owner creates an EnterpriseAgentgatewayBudget with details about the budget, such as the limit, window, and exceeded action.
- The Platform admin creates an EnterpriseAgentgatewayPolicy that enables budget enforcement for the targeted Gateway or HTTPRoutes, and controls which namespaces are searched for budget resources.
- The controller discovers EnterpriseAgentgatewayBudget resources in scope and compiles each budget entry into rate limit server configuration. You can inspect the generated, controller-managed RateLimitConfig resources, which are named
agw-budget-<budget-name>-<hash>. - At request time, the proxy resolves the configured budget dimensions for the request, such as the virtual key ID or the model. On admission, the proxy checks each matching budget entry. If an entry is over its limit, the request is rejected with an HTTP 429 status code (
Block) or logged and allowed through (Audit). - After the response completes, the proxy debits the request’s actual token usage, or its USD cost as priced by your model cost catalog, against every matching budget entry.
- When you delete a budget resource, the controller removes the generated rate limit configuration, and enforcement for those entries stops.
Budget entries
Each EnterpriseAgentgatewayBudget resource holds a list of up to 64 independent budget entries. Entries in one resource must have unique names, and no two entries can repeat the same combination of subject, limit unit, and window.
apiVersion: enterpriseagentgateway.solo.io/v1alpha1
kind: EnterpriseAgentgatewayBudget
metadata:
name: team-budgets
namespace: agentgateway-system
spec:
budgets:
- name: alice-daily-tokens
subject:
virtualKey: alice
limit:
unit: Tokens
amount: 100000
window:
unit: Day
onBudgetExceeded: Block
- name: bob-daily-usd
subject:
virtualKey: bob
limit:
unit: USD
amount: 5
window:
unit: Day
onBudgetExceeded: AuditReview the following table to understand this configuration. For more information, see the API docs.
| Field | Description |
|---|---|
name | Unique name for the entry within the budget resource. |
subject | Optional map of budget dimensions that scope the entry, such as virtualKey: alice. Use "*" as a value to give each distinct value of that dimension its own separate allowance. Omit subject to create a single budget for all requests through the enforcing gateway or routes. |
limit.unit | USD or Tokens. USD budgets require a model cost catalog. |
limit.amount | Maximum spend in the window as a positive whole number. For USD, whole dollars only. |
window.unit | Accumulation period: Day, Week, Month, or Year, which are fixed windows of 24 hours, 7 days, 30 days, and 365 days. The windows are aligned to the Unix epoch in UTC, not to the first request or to calendar boundaries. For more information, see How budget windows work. |
onBudgetExceeded | Block rejects over-limit requests with a 429 status code. Audit logs the overage but lets requests through. |
Budget dimensions
Subjects match against budget dimensions, which are named values that the proxy resolves for each request. The following dimensions are available by default.
| Dimension | Resolved from | Description |
|---|---|---|
model | Built-in | The LLM model of the request. |
provider | Built-in | The LLM provider that serves the request, such as openai. |
virtualKey | apiKey.id | The metadata.id value of the API key that authenticated the request, from your virtual key Secret. |
user | apiKey.user, jwt.sub, jwt.email, and other identity fields, in coalescing order | The calling user’s identity. |
group | jwt.group or apiKey.group | The calling user’s group. |
The model and provider dimensions are built in to the proxy. The others are defined as CEL expressions in the agentgateway-enterprise-budget-dimensions ConfigMap in the control plane namespace, which is installed by default. Dimensions are organized into an ordered hierarchy list (such as group > user) and an unordered attributes list (such as virtualKey). To define your own dimensions, such as a cost center resolved from a JWT claim or request header, see Add a custom budget dimension.
When a request matches multiple entries at different levels, such as a per-user budget and a group-wide budget, all matching entries are debited cumulatively.
Wildcard and exact subjects: A wildcard value ("*") creates an independent allowance per distinct dimension value, which is an easy way to set a default, such as “every API key gets 100,000 tokens per day.” If an exact entry also matches the same dimensions, such as virtualKey: alice, the exact entry takes precedence and the wildcard default is suppressed for that value. A subject with multiple keys matches only when every key matches.
Budget notifications
A budget entry can send an alert when its usage crosses a percentage of its limit, such as 80%. A Webhook channel posts a JSON payload to an HTTP endpoint, and a Slack channel posts a message to a Slack incoming webhook. For how the proxy delivers the alerts and the steps to set them up, see Send budget notifications.
USD budgets and the model cost catalog
Budgets with limit.unit: USD count the realized cost of each request in dollars (USD), as computed from your model cost catalog. Requests to models that the catalog cannot price add nothing to USD spend, so an incomplete catalog undercounts expenditures. Token budgets do not require a catalog.
More enforcement details
Keep in mind the following details about how budgets are enforced.
- Budgets are approximate at the boundary. Usage is debited after the response completes, because the token count and cost are not known until then. The request that crosses the limit still completes. The next matching request is rejected.
- All matching entries are debited. If a request matches several budget entries, such as a per-user budget and a team-wide budget, each entry’s counter is decremented. A request is blocked when any matching entry with
onBudgetExceeded: Blockis over its limit, even if other entries have capacity left. - Enforcement fails open. If the rate limit service is unreachable, requests are allowed through rather than blocked.
- Budget spend is stored in Redis. By default, the in-cluster ext-cache Redis instance stores the counters without persistent storage. If its pod is rescheduled, all spend resets to zero. For production, use an external Redis.
How budget windows work
Budgets use fixed windows, not rolling windows. The rate limit service divides time into consecutive blocks of the window length, counted from the Unix epoch (January 1, 1970, 00:00 UTC).
Spend resets to zero at the start of each block. The window does not begin with the first request that the budget applies to, so every budget with the same window.unit resets at the same moment. A budget that you create in the middle of a block gets only the time that remains in that block. For example, a Week budget that you create on a Tuesday resets on Thursday at 00:00 UTC.
window.unit | Block length | Reset time |
|---|---|---|
Day | 24 hours | Every day at 00:00 UTC. |
Week | 7 days | Every Thursday at 00:00 UTC (because January 1, 1970 was a Thursday). |
Month | 30 days | Every 30 days at 00:00 UTC. The reset does not fall on the first day of a calendar month. |
Year | 365 days | Every 365 days at 00:00 UTC. The reset does not fall on January 1, because the blocks do not count leap days. |
Guides
Set up budgets
Enable budget enforcement on a route, then combine a global token budget with a separate allowance …
Customize budgets
Enforce dollar budgets, set a global spending limit, audit budgets before you enforce them, add your …
Send budget notifications
Send a Webhook or Slack alert when a user, group, or API key crosses part of a budget, and route …
Troubleshoot budgets
Find out why a budget is not enforced, does not block, or does not count usage.