Skip to main content
Version: Dev

Budgets

Budgets set spending limits for an organization, environment, caller API key, provider key, team, member, or cost attribution tag. A blocking budget stops matching traffic after spend reaches the limit. A warn-only budget lets traffic continue while operators monitor spend and receive alerts.

Budgets are available with either AISIX Enterprise or AISIX Cloud. They are not part of the AISIX OSS resource model.

Prerequisites​

Before starting, prepare the following:

  • Access to the AISIX Enterprise or AISIX Cloud organization, with permission to create, update, and delete budgets.
  • To verify spend tracking, an attached gateway, a working model alias, and a caller API key that can use it. See Model Aliases and Caller API Keys.
  • For AISIX Cloud Admin API automation, curl, jq, an admin token with write scope, and the target identifier required by the selected scope. See Budget Targets for the identifier used by each scope.
  • For models that the catalog does not cover, configure Model Pricing so their traffic contributes spend to the budget.
  • For a team budget, create the team and bind the caller API keys whose traffic should count toward it.
  • For a tag budget, declare the tag key and set its values as described in Cost Attribution Tags.

Create a Budget​

This example sets a monthly limit of 500 in the organization's currency for an environment named budget-prod. Substitute your environment and spending limit.

  1. Open Budgets, then select New budget.

  2. Enter Production spend in Name. Set Scope to Environment (one isolated env) and select budget-prod in Environment.

  3. Enter 500 in Limit (USD) and select Month in Period. A CNY organization shows Limit (CNY) instead; amounts use the organization's currency.

  4. Enter 80, 100 in Alert thresholds (%) to notify operators at those percentages of the limit. Leaving the field empty uses 80%. Configure a destination through Budget Alerts and Notifications.

  5. Keep Hard stop at limit selected to block matching traffic once spend reaches the limit. Clear it for a warn-only budget.

    Environment budget for budget-prod with a monthly USD 500 limit, 80 and 100 percent alerts, and Hard stop at limit selected
  6. Select Create budget. In the saved row, confirm the environment, monthly limit, and hard-stop mode. Alert thresholds are available when you edit the budget.

Each scope-and-target combination can have one budget. If the combination already has one, edit that budget rather than creating another. To budget another kind of target, see Budget Targets.

Verify Spend Tracking​

Use a caller API key and model that match the budget target. For the environment example, both must belong to budget-prod.

Export the request values. The local quickstart guides use http://127.0.0.1:3000 for the gateway URL:

# AISIX_PROXY has no trailing slash or endpoint path.
export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"
export AISIX_MODEL="YOUR_MODEL_ALIAS"
export AISIX_API_KEY="YOUR_CALLER_API_KEY"

Send a request through the gateway:

curl -sS "$AISIX_PROXY/v1/chat/completions" \
-H "Authorization: Bearer $AISIX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "'"$AISIX_MODEL"'",
"messages": [
{
"role": "user",
"content": "Reply with a short greeting."
}
]
}'

Allow a few seconds for usage to be counted, then confirm that spend increases for the expected target.

Open Budgets and find the target. A new budget shows no spend data yet until the first measurement completes, then displays the amount spent. The same status appears in the budget controls on caller API key, provider key, member, and team pages. An each-member-in-a-team budget shows the per-member allowance instead of aggregate spend.

Measured Production spend budget showing the current spend, limit, percentage, and update time

For a priced request, confirm that the amount increases. The update time shows when the latest measurement completed.

Use Usage Reporting to confirm that the model requests produce spend. If token usage appears without spend, check that Model Pricing contains an exact provider and model-name match.

A warn-only budget continues to allow matching traffic after the limit is reached and shows the over-budget state in the control plane. A blocking budget rejects a later matching request with 429. The request that crosses the limit can still complete because the control plane records its usage after the provider responds. Requests sent in the few seconds before the gateway receives the exhausted budget can also complete.

Update or Delete a Budget​

To adjust an existing cap, open Budgets and select Edit on its row:

  1. Change the name, limit, period, alert thresholds, or enforcement mode as needed.

  2. For this example, set the limit to 750 and clear Hard stop at limit to allow traffic beyond the limit.

    Edit Production spend with a monthly USD 750 limit and Hard stop at limit cleared; scope and target are immutable
  3. Select Save changes, then confirm the row shows the new limit and warn-only mode. Reopen Edit to verify settings that the row does not display, such as alert thresholds.

Scope and target cannot be edited. To move a cap to another target, delete the existing budget and create a replacement. To remove a cap, select Delete on its row and confirm. Deleting a budget leaves its target in place and removes this cap after the gateway receives the configuration update; other matching budgets still apply.

Resource views also provide inline budget controls as shortcuts. These controls appear in the API key list, provider key list, Members view, and team detail page. The team detail page includes both the shared team budget and its per-member budget. An inline control and the Budgets view edit the same budget, so changes made in either location appear in both.

For example, open API keys, expand the key, and select Add budget. Set its limit, period, and Hard stop mode.

Inline caller API key budget editor with a monthly USD 100 limit and Hard stop selected

Select Add budget. This creates a caller-key budget; any environment budget still applies as well.

Deleting a target also deletes the budgets attached to it:

  • Deleting a caller API key, provider key, team, or member deletes its budget. Deleting a team also deletes its each-member-in-a-team budget.
  • Deleting an environment deletes its budget and the budgets on every caller API key in that environment.
  • A tag key cannot be deleted while a budget uses it.

The Dashboard confirmation lists the budgets that will be deleted. If the organization already has an orphaned budget from a target deletion, remove it separately from Budgets.

Budget Targets​

Choose the narrowest target that represents the spend you want to control:

TargetSpend counted toward the budget
OrganizationAll managed gateway traffic in the organization
EnvironmentTraffic in one deployment environment
Caller API keyTraffic authenticated with one downstream application or tenant key
Provider keyThe platform cost of models that use one upstream credential or provider account
TeamTraffic from every caller API key bound to one team
MemberTraffic from every caller API key bound to one member, across the organization
Each member in a teamA separate allowance for each member's traffic through keys bound to one team
TagTraffic attributed to one tag value, such as department=rnd, across every environment in the organization

Target a Caller API Key​

In the new-budget form, choose Caller API key as the scope. Select the environment first, then choose the key in API key. Complete the limit, period, thresholds, and enforcement mode as in Create a Budget.

Caller API key budget with budget-prod selected before the production-chat key

Target a Provider Key​

Choose Provider key as the scope, then select the credential in Provider key. The form explains that this cap controls upstream spending for models using that credential.

Provider key budget targeting production-openai with the upstream-spending hint visible

Target a Cost Attribution Tag​

Choose Tag as the scope, select Tag key, and enter Tag value. For example, the following budget targets department=rnd across the organization. The key must already be declared; see Cost Attribution Tags.

Tag budget targeting the research department with its key and value configured

Set Team and Member Limits​

For a shared team budget, choose Team and select the team. For an organization-wide member budget, choose Member and select the member. To give each member a separate allowance in one team, choose Per member in a team and select that team.

Team per-member budget targeting frontend with the independent allowance explanation visible

After creating a per-member budget, the row shows the allowance for each member rather than an aggregate spend bar. The following example gives each member a monthly USD 100 limit.

Saved frontend per-member budget showing a separate monthly USD 100 allowance for each member

Provider Key Budgets​

Provider-key accounting follows the credential attached to the model when the request's cost is counted. Enforcement follows the upstream a request would use, not the caller API key:

  • A routing target whose model uses a provider key with an exhausted blocking budget is skipped before AISIX applies the routing strategy or fallback limit. A model group can continue through targets that use other provider keys.
  • AISIX returns 429 and budget_exceeded when a direct model uses an exhausted provider key or every eligible routing target does.
  • In an ensemble model, an exhausted provider key makes a panel member fail and makes a judge fail the request.

Provider-key budgets do not apply to MCP or A2A traffic.

Tag Budgets​

A tag budget counts every request whose resolved tags include its key=value pair. The value can come from a JWT claim, the caller API key, its team, or its member. See How a Request Resolves Its Tags and Budget by Tag.

Team and Member Budgets​

Team and member budgets follow the bindings stored on the caller API key used for the request. Team membership alone does not make a key's spend count toward that team.

The two member scopes count different traffic:

  • A member budget combines spend from every caller API key bound to that member, regardless of the key's team binding.
  • An each-member-in-a-team budget gives every member a separate limit within one team. It applies only when the caller API key has both that team binding and a member binding.

For example, suppose Alice uses three caller API keys:

KeyTeam bindingMember binding
K1frontendAlice
K2dataAlice
K3noneAlice

Alice's organization-wide member budget counts all three keys. A shared frontend budget counts K1, and an each-member-in-frontend budget also counts K1 toward Alice's individual allowance. Neither K2 nor K3 counts toward the frontend budgets.

AISIX checks K1 against every matching blocking budget, including organization, environment, caller-key, team, member, and each-member-in-team budgets. Provider-key budgets apply separately to the upstream selected for the request.

If spend appears under the wrong team or member, inspect the bindings on the caller API key. Binding changes affect later requests; spend already counted stays with the previous binding until the period resets. See How Spend Is Counted.

How Spend Is Counted​

The control plane counts spend incrementally. Within a few seconds after the gateway reports a request's usage, the applicable cost is added to every matching budget. These include organization, environment, caller API key, provider key, team, member, each-member-in-a-team, and tag budgets.

Cost by Budget Scope​

Budget scopeCost counted
Provider keyThe event's upstream cost, based on the serving model's platform price. If that price is missing, the event counts zero toward this budget.
All other scopesThe recorded request cost, including sale prices, price tiers, and off-peak discounts.

A response-cache hit adds nothing to any budget. Sale prices and off-peak discounts do not change platform cost, so a model sold at zero can still spend a provider key budget.

Existing usage events without upstream cost still use their recorded request cost.

The internal model calls that support a request, such as a semantic router's embedding or decision call, also spend budgets. Each call counts toward the budgets its request counts toward and toward the called model's provider key budget at platform cost. An exhausted provider key budget does not stop an internal call to a model on that key.

Provider-key spend already counted in the current period is not recalculated. The current accounting rule applies to newly recorded usage and to a full recount, such as when a budget is created or its period changes. Existing amounts remain until the period ends unless a recount occurs.

Attribute Spend to a Target​

AISIX attributes a request using the bindings in effect when its cost is counted. These include the caller key's team and member, the model's provider key, and the environment's organization.

Tag budgets instead use the tags recorded when the request ran. Changing a tag later never moves spend that was already recorded.

Spend already counted stays where it was counted. The following changes leave the current period's counted spend unchanged, and only later requests follow the new bindings:

  • Rebinding a caller API key to another team or member.
  • Moving a model to another provider key.
  • Deleting a caller API key, member, team, or environment. The budgets on the deleted target go with it, but the spend it already added to other budgets stays. Deleting a member is the one exception: it also drops that member's own counter under every each-member-in-a-team budget, while the other members' counters stay.
  • Removing usage records older than the organization's usage data retention window.

For example, after a key moves from the frontend team to the data team, the spend from its earlier requests remains in the frontend team budget. The key's later requests count toward the data team budget and are no longer checked against the frontend budget.

Initial Spend and Period Resets​

Creating a budget or changing its period counts the spend already recorded for its target in the current period, using the current bindings. After that, it counts new spend incrementally.

Each period starts from zero. Usage reported late for a request that occurred in the previous period is not counted.

Leave Estimated Usage Out of Budgets​

When an upstream response carries no usage, the gateway counts the tokens itself and marks the usage event as estimated, as Token Counting and Usage Estimation describes. By default, estimated usage counts toward budgets like reported usage. An organization can leave it out instead:

This organization policy is configured only in Dashboard; AISIX Cloud Admin API does not expose it.

  1. Open Settings and select the Policies tab.
  2. In the Estimated usage card, turn on Keep estimated requests out of budgets and token rate limits.

The setting requires control plane 1.11.0 or later and is off by default. Changing it requires permission to update organization settings. The toggle saves immediately.

Estimated usage policy with Keep estimated requests out of budgets and token rate limits enabled

While it is on, a usage event marked usage_estimated adds none of its cost to any budget, even when the gateway estimated only some of its token counts. This applies to every budget target, including provider key budgets, which count the event's upstream_cost. Excluding these requests from token rate limits requires gateway 1.11.0 or later; older gateways continue to count their tokens. See Estimated Usage and Token Limits.

The setting changes only what budgets and token limits count. The requests are still billed at their cost, and Usage Reporting and Cost Analysis, including their exports, still show them marked as including estimates.

caution

A stream closed before the upstream reports usage is estimated and therefore excluded. A caller could use early disconnections to keep traffic out of its budgets. Enable this policy only when every caller is trusted.

A change affects spend counted from then on. Spend counted before the change stays in the current period. When a budget's spend is counted again from scratch, for example after its period is changed, its whole period is recounted under the setting at that time.

Leaving estimated usage out of budgets works with every gateway, because the control plane counts spend. While the setting is on, Budgets shows a note that estimated requests are excluded.

Budgets view note confirming that estimated requests are excluded

Enforcement Path​

Applications continue to use the same proxy API and caller API key after a budget is configured. They do not call a separate budget API.

  1. The control plane sends blocking budgets to the gateways they apply to and marks each budget exhausted once spend reaches its limit. Warn-only budgets stay in the control plane.
  2. Before calling a provider, the gateway checks its local budget state. Traffic continues while all matching blocking budgets have spend remaining; the gateway does not contact the control plane for this check.
  3. After the provider responds, the control plane counts the reported spend. The updated state usually reaches gateways within a few seconds. An exhausted blocking budget then rejects subsequent matching traffic before the provider call.

To lift a block, raise the limit above current spend, clear Hard stop at limit, or delete the budget. The change reaches gateways through the same configuration path.

The gateway also lifts an exhausted budget on its own when the next period starts. Periods follow the UTC calendar: a day starts at 00:00 UTC, a week on Monday at 00:00 UTC, and a month on the 1st at 00:00 UTC. A budget with a limit of zero rejects matching traffic in every period.

Budget Rejection Response​

For OpenAI-compatible requests, a budget rejection returns 429 with an OpenAI-style error envelope:

{
"error": {
"message": "api key budget 'production-chat' exceeded ($1.00/month). Resets 2026-06-01 00:00 UTC.",
"type": "billing_error",
"code": "budget_exceeded",
"scope": "api_key",
"scope_ref": "api-key-uuid-1",
"limit": "1.00",
"spent": "2.00",
"period": "month",
"period_resets_at": "2026-06-01T00:00:00Z",
"retry_after_seconds": 259200
}
}

The amounts are in the organization's currency. message writes the limit with that currency's symbol, such as ¥1.00 in a CNY organization, while limit and spent carry plain numbers in that currency.

Anthropic-compatible Messages requests keep the Anthropic error format and do not include the additional budget fields.

Behavior During a Control-Plane Outage​

Budget checks run on the gateway. With the default Keep last known state mode, a control-plane outage does not by itself cause budget rejections. While the control plane is unreachable, the gateway keeps enforcing the budgets it last received:

  • A budget that was exhausted stays enforced. The gateway lifts it when the next period starts, without waiting for the control plane.
  • A budget that was not exhausted keeps admitting traffic. Spend is counted from the usage that gateways report, so while a gateway cannot report usage, the control plane cannot mark the budget exhausted, and traffic can exceed the limit.
  • A request that no blocking budget applies to is unaffected.

The budgets travel with the gateway's configuration. A gateway that restarts during the outage and recovers from its configuration cache keeps enforcing them.

Choose the Budget Enforcement Mode​

The organization's budget enforcement mode decides what the gateway does with budgeted traffic while it cannot report usage. Changing it requires permission to update organization settings.

This organization policy is configured only in Dashboard; AISIX Cloud Admin API does not expose it.

ModeBehavior while a gateway cannot report usage
Keep last known state (recommended)The default. The gateway keeps enforcing the last budget state it received, as described above.
StrictAfter the gateway has been unable to report usage for the grace period, it rejects requests from caller API keys that a blocking budget applies to with 503 and the code budget_unverified, and it stops using upstreams whose provider key has a blocking budget. Requests and upstreams that no blocking budget applies to are unaffected.

Strict mode trades availability for a firmer spending cap. An organization or environment budget applies to every caller API key, so in strict mode it rejects all traffic in its environment once the grace period has passed.

To configure strict enforcement:

  1. Open Settings, select Policies, and find Budget enforcement.
  2. Select Strict. The mode is saved immediately.
  3. Set Strict-mode grace period (seconds), then select Save. The default is 600 seconds; valid values are whole numbers from 60 to 86400.
Budget enforcement policy with Strict selected and a 600-second grace period

The grace period starts when the gateway has usage waiting that it cannot deliver. A successful delivery, or a delivery rejected with 422 for its content, ends the timer and stops strict-mode rejections. A connection failure, timeout, server error, or authorization refusal does not end it. Each gateway measures its own delivery, and reports how long it has been failing in aisix_usage_delivery_unhealthy_seconds.

In strict mode, a budget that is already exhausted is still rejected with 429 and budget_exceeded. When a model group's targets are all excluded, the request receives 429 budget_exceeded if any of them is on an exhausted provider key, and 503 budget_unverified otherwise.

Budget Usage Metrics​

The gateway records budget gauges when the budget check for the caller API key finds an exhausted matching budget. The series identifies the caller key and, when available, its projected team and member IDs. These gauges do not report provider-key budget decisions.

MetricMeaning
aisix_budget_details_present1 when the budget check for the caller API key finds an exhausted matching budget. A later check that allows traffic or returns budget_unverified sets it to 0.
aisix_budget_limitThe rejecting budget's limit.
aisix_budget_spentThe spend reported for that budget.
aisix_budget_remainingThe remaining amount reported for that budget.
aisix_budget_reset_secondsThe number of seconds until the current budget period resets.

Read these budget gauges only while the presence flag is 1; their last values remain after it becomes 0. The amount gauges use the organization's currency. Switching currency changes the unit of subsequent values in the same series.

The gateway may log row loaded with unknown fields ignored when loading an exhausted budget. This warning is expected and needs no action.

Review Budget Rejections​

When AISIX Enterprise or AISIX Cloud returns budget_exceeded, inspect the error code and structured budget fields first. The gateway made the decision from the budget state the control plane last sent it; the denial did not come from the AISIX Cloud Admin API.

A 503 with the code budget_unverified is not a spending decision. It means the organization uses strict budget enforcement and the gateway has been unable to report usage for longer than the grace period. Check the gateway's connectivity to the control plane and its aisix_usage_delivery_unhealthy_seconds metric; see Behavior During a Control-Plane Outage.

Open Budgets and find the target named in the rejection. Check its current spend, limit, period, and enforcement mode. If the scope is unexpected, inspect the team and member bindings on the caller API key used for the request.

Budget row showing the target, current spend, limit, period, and hard-stop enforcement mode

Next Steps​