Ana içeriğe geç

Update Budget

Endpoint

PUT /apiops/projects/{projectName}/ai-budgets/

Authentication

Requires a Personal API Access Token.

Authorization: Bearer YOUR_TOKEN

Request

Headers

HeaderValueRequired
AuthorizationBearer {token}Yes
Content-Typeapplication/jsonYes

Path Parameters

ParameterTypeRequiredDescription
projectNamestringYesProject name

Query Parameters

None

Request Body

Full JSON Body Example

{
"targetType": "CREDENTIAL_ORGANIZATION",
"targetId": "665f1a2b3c4d5e6f7a8b9c1a",
"targetProjectId": "665f1a2b3c4d5e6f7a8b9c0d",
"budgetSource": "INHERIT",
"budget": {
"enabled": true,
"tokensPerHour": null,
"tokensPerMinute": null,
"tokensPerDay": 100000,
"tokensPerMonth": 2000000,
"monthlyBudgetUsd": 250.00,
"usdPerHour": null,
"usdPerDay": null,
"softCapPercents": [80, 95],
"hardCapPercent": 100,
"overflowAction": "CHEAPER_MODEL",
"cheaperModelId": "claude-haiku-4-5",
"modelBudgets": [
{
"modelId": "gpt-4o",
"tokensPerMonth": 500000,
"monthlyBudgetUsd": 100.00,
"overflowAction": "BLOCK"
}
],
"providerBudgets": []
}
}

Request Body Fields

FieldTypeRequiredDefaultDescription
targetTypestringYes-Owner entity type: CREDENTIAL_ORGANIZATION, API_PROXY, PROJECT or CREDENTIAL_ALLOWED_API_PROXY
targetIdstringYes-Entity ID of the owner (org / proxy / project / credential binding). Take it from a scope-rules or hierarchy read
targetProjectIdstringNopath projectIgnored / overwritten. The server forces it to the path project as a cross-tenant guard
budgetSourcestringNo-Budget source for CREDENTIAL_ALLOWED_API_PROXY targets: CREDENTIAL, ORGANIZATION or INHERIT. Ignored for other target types. null leaves it unchanged (new bindings default to INHERIT)
budgetobjectYes-The AI token budget value to apply (see below)

Budget Object Fields

FieldTypeRequiredDefaultDescription
enabledbooleanNofalseWhether the budget is enabled
tokensPerHourintegerNo-Hourly token cap. null = no limit; if set, must be >= 1
tokensPerMinuteintegerNo-Per-minute token cap. null = no limit; if set, must be >= 1
tokensPerDayintegerNo-Daily token cap. null = no limit; if set, must be >= 1
tokensPerMonthintegerNo-Monthly token cap. null = no limit; if set, must be >= 1
monthlyBudgetUsdnumberNo-Monthly USD cost cap. null = no cost limit; if set, must be > 0
usdPerHournumberNo-Hourly USD cost cap. null = no limit; if set, must be > 0
usdPerDaynumberNo-Daily USD cost cap. null = no limit; if set, must be > 0
softCapPercentsarray[integer]No[]Soft-cap warning thresholds. Each element in range [0, 100]
hardCapPercentintegerNo100Hard-cap percent, range [1, 100]
overflowActionstringNoBLOCKAction on overflow: BLOCK, FAILOVER, ALERT_ONLY or CHEAPER_MODEL
cheaperModelIdstringNo-Cheaper fallback model id (required behaviour when overflowAction=CHEAPER_MODEL)
modelBudgetsarrayNokeepPer-model budget overrides (max 50). See list-semantics note below
providerBudgetsarrayNokeepPer-provider budget overrides (max 50). See list-semantics note below

Model / Provider Budget Entry Fields

FieldTypeRequiredDescription
modelIdstringYes (model entry)Catalog model id the override applies to
providerRefstringYes (provider entry)LLM provider reference (ConnectionConfigLlm ID) the override applies to
tokensPerHour / tokensPerDay / tokensPerMonthintegerNoToken caps for this model/provider. If set, must be >= 1
monthlyBudgetUsd / usdPerHour / usdPerDaynumberNoUSD cost caps for this model/provider. If set, must be > 0
overflowActionstringNoPer-entry overflow action (defaults to BLOCK)

Notes

  • targetType and targetId are required; a blank value returns 400 Bad Request with targetType and targetId are required!.
  • An empty body returns 400 Bad Request with AI budget update body can not be empty!.
  • modelBudgets / providerBudgets list semantics: an empty array [] clears all model-/provider-level overrides; null or an absent field keeps the currently stored overrides.
  • hardCapPercent defaults to 100 and overflowAction defaults to BLOCK when omitted.

Response

Success Response (200 OK)

The response returns the resulting budget as a single-element resultList.

{
"status": "SUCCESS",
"resultList": [
{
"enabled": true,
"tokensPerHour": null,
"tokensPerMinute": null,
"tokensPerDay": 100000,
"tokensPerMonth": 2000000,
"monthlyBudgetUsd": 250.00,
"usdPerHour": null,
"usdPerDay": null,
"softCapPercents": [80, 95],
"hardCapPercent": 100,
"overflowAction": "CHEAPER_MODEL",
"cheaperModelId": "claude-haiku-4-5",
"modelBudgets": [
{
"modelId": "gpt-4o",
"tokensPerHour": null,
"tokensPerDay": null,
"tokensPerMonth": 500000,
"monthlyBudgetUsd": 100.00,
"usdPerHour": null,
"usdPerDay": null,
"overflowAction": "BLOCK"
}
],
"providerBudgets": []
}
],
"resultCount": 1
}

Response Fields

FieldTypeDescription
statusstringResponse status: SUCCESS or FAILURE
resultListarraySingle-element list holding the resulting budget object (same shape as the budget request field)
resultCountintegerAlways 1 on success

EnumStatus

  • SUCCESS - Operation successful
  • FAILURE - Operation failed

Error Response (400 Bad Request)

{
"status": "FAILURE",
"resultMessage": "targetType and targetId are required!"
}

or

{
"status": "FAILURE",
"resultMessage": "AI budget update body can not be empty!"
}

Error Response (401 Unauthorized)

{
"status": "FAILURE",
"resultMessage": "Token is not valid!"
}

cURL Example

curl -X PUT \
"https://demo.apinizer.com/apiops/projects/MyProject/ai-budgets/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"targetType": "CREDENTIAL_ORGANIZATION",
"targetId": "665f1a2b3c4d5e6f7a8b9c1a",
"budgetSource": "INHERIT",
"budget": {
"enabled": true,
"tokensPerDay": 100000,
"tokensPerMonth": 2000000,
"monthlyBudgetUsd": 250.00,
"softCapPercents": [80, 95],
"hardCapPercent": 100,
"overflowAction": "CHEAPER_MODEL",
"cheaperModelId": "claude-haiku-4-5",
"modelBudgets": [],
"providerBudgets": []
}
}'

Notes and Warnings

  • Cross-tenant guard: The body targetProjectId is always overwritten with the authenticated path project. You cannot redirect the write to another tenant by supplying a different targetProjectId; omitting it is fine.
  • ID-based target: targetId is an entity ID, not a name - this is an exception to the APIops name-based convention. Resolve it from a scope-rules (id / scopeRef) or hierarchy (nodeId) read.
  • targetType vs hierarchy nodeType: The update uses CREDENTIAL_ALLOWED_API_PROXY for a per-credential proxy binding (the effective-limit endpoint calls the equivalent leaf CREDENTIAL). The other three types (CREDENTIAL_ORGANIZATION, API_PROXY, PROJECT) match.
  • List clear vs keep: Send modelBudgets: [] / providerBudgets: [] to wipe all model-/provider-level limits. Omit the field (or send null) to preserve the stored overrides - a common source of accidental silent wipes.
  • Defaults on omission: hardCapPercent falls back to 100 and overflowAction to BLOCK when not supplied.
  • PROJECT target side-effect: Updating a PROJECT (tenant) budget also pushes a project redeploy to the workers so the new tenant cap takes effect at the gateway.
  • No secret fields: AI budgets carry no @SecretData fields; nothing is masked in the response.
  • Permission: Requires AI_BUDGETS + MANAGE permission in the project.