Create Budget
POST /budgets
POST /budgetsInteractive request editor loads with JavaScript.
Authorization
BearerAdminToken Organization-scoped admin token. Read operations require a valid token, and write operations require a token with write permission.
In: header
Request Body
application/json
Create-budget body. One budget per scope + scope_ref
target.
Response Body
application/json
application/json
application/json
application/json
curl -X POST "$AISIX_CP/budgets" \ -H "Authorization: Bearer $AISIX_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "scope": "org", "display_name": "string", "limit_cents": 0, "period": "day" }'Created
{
"budget": {
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"org_id": "a40f5d1f-d889-42e9-94ea-b9b33585fc6b",
"scope": "org",
"scope_ref": "string",
"display_name": "string",
"limit_cents": 0,
"period": "day",
"hard_stop": true,
"alert_thresholds": [
1
],
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
}Request body or parameters failed validation.
{
"error": {
"code": "string",
"message": "string"
}
}Missing or invalid bearer.
{
"error": {
"code": "UNAUTHENTICATED",
"message": "no org context"
}
}The target already has a budget.
{
"error": {
"code": "DUPLICATE",
"message": "budget for this team already exists"
}
}Complete operation details and schema variants
POST /budgets
Create Budget
Create a spending cap. Each target — identified by the
scope + scope_ref pair — can hold at most one budget;
creating a second one for the same target is rejected with
409. A hard_stop budget makes the gateway reject matching
traffic with 429 budget_exceeded once the period's spend
reaches limit_cents; without hard_stop the budget only
reports the over-limit state. limit_cents: 0 with
hard_stop: true blocks all matching traffic immediately,
which freezes a target's spend without deleting anything.
Parameters
Request body
Content type: application/json
-
scope(string, required): What a budget's spend counts.orgcaps the whole organization.environmentcaps one environment.api_keycaps one caller API key andprovider_keyone upstream credential.teamis a pool shared by every caller API key bound to the team.memberis organization-wide for one member: all caller API keys bound to that member, in any team.team_membergives every member of one team an individual allowance of the same size, counting only their spend through keys bound to both that team and that member. -
scope_ref(string, optional): ID of the target the budget applies to, matchingscope. Required for every scope exceptorg, where the caller's own organization is used and this field is ignored. -
display_name(string, required): Human-readable budget name. -
limit_cents(integer, required): Spending limit in USD cents.0together withhard_stop: trueblocks all matching traffic immediately. -
period(string, required): Calendar window the limit applies to, in UTC:dayresets at 00:00,weekon Monday 00:00,monthon the 1st at 00:00. -
hard_stop(boolean, optional): Reject matching traffic once the limit is reached. Defaults tofalse: report the over-limit state, keep traffic flowing. -
alert_thresholds(array, optional): Percent-of-limit alert points. Omitted ornullmeans the default ([80]).
Responses
-
201: Created -
budget(object, required): A spending cap on one target. Amounts are integer USD cents. -
budget.id(string, required): Budget ID. -
budget.org_id(string, required): Organization that owns this budget. -
budget.scope(string, required): What a budget's spend counts.orgcaps the whole organization.environmentcaps one environment.api_keycaps one caller API key andprovider_keyone upstream credential.teamis a pool shared by every caller API key bound to the team.memberis organization-wide for one member: all caller API keys bound to that member, in any team.team_membergives every member of one team an individual allowance of the same size, counting only their spend through keys bound to both that team and that member. -
budget.scope_ref(string, required): ID of the target the budget applies to, matchingscope: an environment ID, caller API key ID, provider key ID, team ID, or member ID.team_memberbudgets reference a team ID. Fororgbudgets this holds the organization's internal ID, which differs from the organization identifier used elsewhere in this API. Fixed at creation. -
budget.display_name(string, required): Human-readable budget name. -
budget.limit_cents(integer, required): Spending limit in USD cents. -
budget.period(string, required): Calendar window the limit applies to, in UTC:dayresets at 00:00,weekon Monday 00:00,monthon the 1st at 00:00. -
budget.hard_stop(boolean, required): Whether the gateway rejects matching traffic with429 budget_exceededonce the period's spend reaches the limit. Whenfalsethe budget only reports the over-limit state. -
budget.alert_thresholds(array, optional): Percent-of-limit points at which abudget_thresholdnotification fires once per period, delivered to the organization's enabled notification channels.nullmeans the default ([80]). Values above100fire under either enforcement mode and flag overspend:hard_stoprejects new requests once the control plane observes spend at the limit, but it does not cap the cost of requests already admitted, so a hard-stopped budget can settle above100. -
budget.created_at(string, required): Time when the budget was created. -
budget.updated_at(string, required): Time when the budget was last updated. -
400: Request body or parameters failed validation. -
error(object, required): Error details. -
error.code(string, required): Machine-readable identifier. Examples:UNAUTHENTICATED,INVALID_REQUEST,MASTER_KEY_UNSET,INTERNAL. -
error.message(string, required): Human-readable explanation; safe to surface to operators. -
401: Missing or invalid bearer. Response fields (application/json): identical toPOST /budgets, response 400 above. -
409: The target already has a budget. Response fields (application/json): identical toPOST /budgets, response 400 above.
cURL
curl -X POST '$AISIX_CP/budgets' -H 'Authorization: Bearer $AISIX_TOKEN'