Set or replace a budget
Creates or replaces the budget for a scope: account (omit scopeId), or key/agent (each requires a scopeId you own — an API key id (a UUID) for key, or an agent's id or portable agt_… id for agent).
Creates or replaces the budget for a scope: account (omit scopeId), or key/agent (each requires a scopeId you own — an API key id (a UUID) for key, or an agent's id or portable agt_… id for agent). The call is an idempotent upsert keyed on the (scope, scopeId) pair, so re-sending the same target updates the existing budget instead of creating a duplicate. limits must set at least one ceiling — maxSendsPerDay, maxNewRecipientsPerHour, maxSpendPerDayCents (each an integer in 0–1000000, where 0 is enforced as a cap), or hardStopOnComplaint: true — and unknown limit keys are rejected so a typo can't silently widen the ceiling. maxSpendPerDayCents is the account's daily spend cap on calls, letters, and AI generations; it is accepted on the account scope only (a 400 on a key or agent budget), and a request that would cross it is refused with spend_cap_reached. Once set, every send under the budget is checked before it is accepted and re-checked at scheduled fire time, and a send over the line is rejected with a budget_exceeded error and emits a budget.tripped event to your webhooks and the event stream. Requires the budgets:write scope.
Scope: budgets:write. Send the API key as a bearer token; Scopes lists what each one reaches.
Request
Body
Required, application/json: BudgetSetRequest.
| Field | Type | Required | Description |
|---|---|---|---|
scope | "account", "key", "agent" | yes | |
scopeId | string or null | no | Required for key/agent scopes (an api_key id you own); omit for the account scope. |
enabled | boolean | no | (default true) |
limits | BudgetLimits | yes |
Response
200 Success. Body: application/json, BudgetResponse.
| Field | Type | Required | Description |
|---|---|---|---|
budget | Budget | yes |
Errors
Every error has the same body, {"error": {"type", "code", "message", "param"}}; branch on code. Errors lists every code.
| Status | Meaning |
|---|---|
400 | The request is malformed or a value is invalid (invalid_request, invalid_domain, idempotency_key_mismatch). |
401 | The API key is missing or invalid. |
403 | The key lacks the scope this endpoint needs (scope_missing) or may not do this (not_permitted). |
404 | No such resource in this account (resource_not_found). |
422 | The request is well-formed but a field failed validation (validation_failed). |
429 | Rate limit, plan limit, budget or spend cap reached (rate_limited, plan_limit_reached, budget_exceeded, spend_cap_reached). |
500 | An unexpected error; retry with backoff, then contact support (internal_error). |
List spend and send budgets
Returns every budget configured for the active organization, each with its resolved limits and live windowed usage.
Get a single budget by scope
Returns one budget with its live usage, addressed by the {scope} path segment: use account for the account-wide budget, or a key/agent budget's scopeId (the API key or agent id it targets).