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 withwritescope, 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.
- Dashboard
- Admin API
-
Open Budgets, then select New budget.
-
Enter
Production spendin Name. Set Scope to Environment (one isolated env) and selectbudget-prodin Environment. -
Enter
500in Limit (USD) and select Month in Period. A CNY organization shows Limit (CNY) instead; amounts use the organization's currency. -
Enter
80, 100in 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. -
Keep Hard stop at limit selected to block matching traffic once spend reaches the limit. Clear it for a warn-only budget.

-
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.
Export the Admin API connection and target environment:
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash.
export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"
export AISIX_TOKEN="YOUR_ADMIN_TOKEN"
export ENV_ID="YOUR_ENVIRONMENT_ID"
Create a blocking monthly environment budget. The API accepts monetary values in minor units, so a limit of 500.00 becomes 50000:
BUDGET_RESPONSE=$(curl -sS -X POST "$AISIX_CP/budgets" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"scope": "environment",
"scope_ref": "'"$ENV_ID"'",
"display_name": "Production spend",
"limit_cents": 50000,
"period": "month",
"hard_stop": true,
"alert_thresholds": [80, 100]
}')
BUDGET_ID=$(printf '%s' "$BUDGET_RESPONSE" | jq -er '.budget.id')
export BUDGET_ID
printf '%s' "$BUDGET_RESPONSE" | jq -e --arg env "$ENV_ID" \
'.budget | .scope == "environment" and .scope_ref == $env and
.limit_cents == 50000 and .period == "month" and .hard_stop == true'
The command prints true and retains the new budget ID for later checks. See Budget Targets for the scope and scope_ref values for other 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.
- Dashboard
- Admin API
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.

For a priced request, confirm that the amount increases. The update time shows when the latest measurement completed.
Set the Admin API connection values and reuse the budget ID captured during creation:
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash.
export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"
export AISIX_TOKEN="YOUR_ADMIN_TOKEN"
export BUDGET_ID="${BUDGET_ID:-YOUR_BUDGET_ID}"
BUDGET_STATE=$(curl -sS "$AISIX_CP/budgets/$BUDGET_ID" \
-H "Authorization: Bearer $AISIX_TOKEN")
printf '%s' "$BUDGET_STATE" | jq '.state | {spent_cents, aggregated_at}'
printf '%s' "$BUDGET_STATE" | jq -e '.state.aggregated_at != null'
The final command prints true after spend has been measured. For budgets other than team_member, aggregated_at is null before the first measurement. For a team_member budget, the top-level state stays at its zero seed; the Admin API does not return the individual member counters.
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
- Dashboard
- Admin API
To adjust an existing cap, open Budgets and select Edit on its row:
-
Change the name, limit, period, alert thresholds, or enforcement mode as needed.
-
For this example, set the limit to
750and clear Hard stop at limit to allow traffic beyond the limit.
-
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.

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.
Set the Admin API connection values before looking up the budget:
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash.
export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"
export AISIX_TOKEN="YOUR_ADMIN_TOKEN"
If you do not have the budget ID from the create response, list the organization's budgets and find the target you want to change:
curl -sS "$AISIX_CP/budgets" \
-H "Authorization: Bearer $AISIX_TOKEN" | jq
Export its ID, then read the budget and its current-period state:
export BUDGET_ID="YOUR_BUDGET_ID"
curl -sS "$AISIX_CP/budgets/$BUDGET_ID" \
-H "Authorization: Bearer $AISIX_TOKEN" | jq
Update only the fields that should change. This example raises the limit to 750.00 and makes the budget warn-only:
curl -sS -X PATCH "$AISIX_CP/budgets/$BUDGET_ID" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"limit_cents": 75000,
"hard_stop": false
}' | jq -e '.budget.limit_cents == 75000 and .budget.hard_stop == false'
The command prints true when both changes are saved.
Delete the budget when the target no longer needs a cap:
curl -sS -X DELETE "$AISIX_CP/budgets/$BUDGET_ID" \
-H "Authorization: Bearer $AISIX_TOKEN" | \
jq -e --arg id "$BUDGET_ID" '.deleted == true and .id == $id'
The command prints true when the budget is deleted.
Budget Targets
Choose the narrowest target that represents the spend you want to control:
| Target | Spend counted toward the budget |
|---|---|
| Organization | All managed gateway traffic in the organization |
| Environment | Traffic in one deployment environment |
| Caller API key | Traffic authenticated with one downstream application or tenant key |
| Provider key | The platform cost of models that use one upstream credential or provider account |
| Team | Traffic from every caller API key bound to one team |
| Member | Traffic from every caller API key bound to one member, across the organization |
| Each member in a team | A separate allowance for each member's traffic through keys bound to one team |
| Tag | Traffic attributed to one tag value, such as department=rnd, across every environment in the organization |
- Dashboard
- Admin API
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.

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.

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.

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.

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.

Set scope and scope_ref for the target:
| Target | scope | scope_ref |
|---|---|---|
| Organization | org | Omit it; the control plane uses the caller's organization. |
| Environment | environment | Environment ID |
| Caller API key | api_key | Caller API key resource ID |
| Provider key | provider_key | Provider key resource ID |
| Team | team | Team ID |
| Member | member | Organization membership ID from the Members API, not the account user ID |
| Each member in a team | team_member | Team ID |
| Tag | tag | <key>=<value>, such as department=rnd |
Each scope and scope_ref pair can have one budget. To change either value, delete the budget and create a replacement.
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
429andbudget_exceededwhen 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:
| Key | Team binding | Member binding |
|---|---|---|
K1 | frontend | Alice |
K2 | data | Alice |
K3 | none | Alice |
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 scope | Cost counted |
|---|---|
| Provider key | The 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 scopes | The 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.
- Open Settings and select the Policies tab.
- 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.

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.
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.

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.
- 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.
- 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.
- 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.
| Mode | Behavior 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. |
| Strict | After 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:
- Open Settings, select Policies, and find Budget enforcement.
- Select Strict. The mode is saved immediately.
- Set Strict-mode grace period (seconds), then select Save. The default is 600 seconds; valid values are whole numbers from 60 to 86400.

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.
| Metric | Meaning |
|---|---|
aisix_budget_details_present | 1 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_limit | The rejecting budget's limit. |
aisix_budget_spent | The spend reported for that budget. |
aisix_budget_remaining | The remaining amount reported for that budget. |
aisix_budget_reset_seconds | The 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.
- Dashboard
- Admin API
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.

Use scope and scope_ref from the rejection to find the matching budget, then inspect its configuration and current-period state:
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash.
export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"
export AISIX_TOKEN="YOUR_ADMIN_TOKEN"
export BUDGET_SCOPE="SCOPE_FROM_THE_REJECTION"
export BUDGET_SCOPE_REF="SCOPE_REF_FROM_THE_REJECTION"
BUDGET_ID=$(curl -sS "$AISIX_CP/budgets" \
-H "Authorization: Bearer $AISIX_TOKEN" | \
jq -er --arg scope "$BUDGET_SCOPE" --arg ref "$BUDGET_SCOPE_REF" \
'.data[] | select(.budget.scope == $scope and .budget.scope_ref == $ref) | .budget.id')
export BUDGET_ID
curl -sS "$AISIX_CP/budgets/$BUDGET_ID" \
-H "Authorization: Bearer $AISIX_TOKEN" | \
jq '{budget: (.budget | {scope, scope_ref, limit_cents, period, hard_stop}), state}'
If the scope is unexpected, inspect the team and member bindings on the caller API key used for the rejected request.
Next Steps
- Configure Budget Alerts and Notifications to notify operators through webhooks or Slack when spend crosses a threshold.
- Use Cost Analysis to compare spending across the targets covered by your budgets.
- Follow Logging and Auditing to investigate policy rejections and the configuration changes behind them.