Budget management API
This page documents the 7 gateway endpoints tagged budget management in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| Method | Path | Summary |
|---|---|---|
| GET | /management/v1/budgets | List the budgets, paged, sorted and filtered |
| POST | /budget/new | Create a shared budget |
| POST | /budget/update | Change a shared budget |
| POST | /budget/info | Look up budgets by id |
| GET | /budget/settings | Show the editable fields of a budget |
| GET | /budget/list | List every budget |
| POST | /budget/delete | Delete a budget |
Endpoints
GET /management/v1/budgets
List the budgets, paged, sorted and filtered
List the shared budgets defined on the gateway, the named spend caps and rate limits that end users, tags,
organizations and projects point at by budget_id, a page at a time. This is what the Admin UI Budgets page
reads.
Only a proxy admin or an admin viewer may call it, anyone else gets 403. Nothing is changed.
sort takes a comma-separated list of budget_id, max_budget, tpm_limit, rpm_limit, tpd_limit or
created_at, each optionally prefixed with - for descending, and defaults to -created_at. budget_id is
appended to every sort as the tiebreaker. q is a case-insensitive substring match on budget_id.
page_size defaults to 50 and is capped at 100. Filters are filter[budget_duration][in|is_null],
filter[max_budget][gte|lte|is_null] and filter[created_at][gte|lte], and any other query parameter is
refused with 400 so a mistyped filter never returns more than you asked for.
Docs (https://docs.spanway.ai/docs/proxy/budgets)
Example request:
curl -X GET "http://localhost:4000/management/v1/budgets" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json ListResponse_BudgetListItem_ |
| 400 | A sort, filter or other query parameter is unknown or has a bad value | application/problem+json object |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller is not a proxy admin or an admin viewer | application/problem+json object |
| 500 | Reading the budgets failed | application/problem+json object |
| 503 | The gateway has no database connected | application/problem+json object |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
data | array of BudgetListItem | Yes | Data |
meta | ListMeta | Yes | Page-mode counterpart to PageMeta: an entity list pays for the COUNT(*) so the table can show a page count. |
links | ListLinks | Yes | Page-mode counterpart to PageLinks. first/last are knowable here because the total count is. |
POST /budget/new
Create a shared budget
Create a budget that end users, tags, organizations and projects can share by pointing at its budget_id.
max_budget is the hard cap in US dollars, soft_budget only raises an alert, budget_duration says how often
spend resets (1h, 1d, 30d), and tpm_limit, rpm_limit, tpd_limit and max_parallel_requests cap the
rate. model_max_budget holds separate limits per model. Leave budget_id out to have one generated, and
leave budget_reset_at out to reset at the end of the first duration from now. A budget_id that already
exists, a negative or infinite amount, or a duration that never advances is a 400. Proxy admins only. The
change is written to the audit log.
Docs (https://docs.spanway.ai/docs/proxy/budget_management)
Request body (application/json, schema BudgetNewRequest):
| Field | Type | Required | Description |
|---|---|---|---|
budget_id | string or null | No | The unique budget id. |
max_budget | number or null | No | Requests will fail if this budget (in USD) is exceeded. |
soft_budget | number or null | No | Requests will NOT fail if this is exceeded. Will fire alerting though. |
max_parallel_requests | integer or null | No | Max concurrent requests allowed for this budget id. |
tpm_limit | integer or null | No | Max tokens per minute, allowed for this budget id. |
rpm_limit | integer or null | No | Max requests per minute, allowed for this budget id. |
tpd_limit | integer or null | No | Max tokens per day, charged by batch submissions, allowed for this budget id. |
budget_duration | string or null | No | How often spend resets to zero, for example '1h', '1d', '7d', '30d' or '1mo' |
model_max_budget | object or null | No | Max budget for each model (e.g. {'gpt-4o': {'max_budget': '0.0000001', 'budget_duration': '1d', 'tpm_limit': 1000, 'rpm_limit': 1000}}) |
budget_reset_at | string or null | No | Datetime when the budget is reset |
Example request:
curl -X POST "http://localhost:4000/budget/new" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"budget_id": "free-tier",
"max_budget": 5,
"soft_budget": 4,
"budget_duration": "30d",
"rpm_limit": 20
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The budget as stored | application/json Spanway_BudgetTableFull |
| 400 | The request breaks a rule named in the detail | application/json ErrorDetail |
| 401 | No valid key was sent, or the key belongs to someone who is not a proxy admin | application/json ProxyError |
| 403 | An admin viewer tried to change a budget, and admin viewers can only read | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
budget_id | string or null | No | Budget Id |
soft_budget | number or null | No | Soft Budget |
max_budget | number or null | No | Max Budget |
max_parallel_requests | integer or null | No | Max Parallel Requests |
tpm_limit | integer or null | No | Tpm Limit |
rpm_limit | integer or null | No | Rpm Limit |
tpd_limit | integer or null | No | Tpd Limit |
model_max_budget | object or null | No | Model Max Budget |
budget_duration | string or null | No | Budget Duration |
allowed_models | array of string or null | No | Allowed Models |
temp_budget_increase | number or null | No | Temp Budget Increase |
temp_budget_expiry | string or null | No | Temp Budget Expiry |
budget_reset_at | string or null | No | Budget Reset At |
created_at | string | Yes | Created At |
created_by | string or null | No | Created By |
updated_at | string or null | No | Updated At |
updated_by | string or null | No | Updated By |
POST /budget/update
Change a shared budget
Change the fields you send on the budget named by budget_id, and leave every other field as it is.
Every object attached to the budget sees the new limits on its next request. Sending a new budget_duration
moves budget_reset_at to the end of the first new duration unless you pass budget_reset_at yourself, and
sending budget_duration: null clears the reset time. A missing budget_id, a negative or infinite amount, or
a duration that never advances is a 400, and a budget_id that does not exist is a 404. Proxy admins only.
With audit logging on, the change is written to the audit log.
Docs (https://docs.spanway.ai/docs/proxy/budget_management)
Request body (application/json, schema BudgetNewRequest):
| Field | Type | Required | Description |
|---|---|---|---|
budget_id | string or null | No | The unique budget id. |
max_budget | number or null | No | Requests will fail if this budget (in USD) is exceeded. |
soft_budget | number or null | No | Requests will NOT fail if this is exceeded. Will fire alerting though. |
max_parallel_requests | integer or null | No | Max concurrent requests allowed for this budget id. |
tpm_limit | integer or null | No | Max tokens per minute, allowed for this budget id. |
rpm_limit | integer or null | No | Max requests per minute, allowed for this budget id. |
tpd_limit | integer or null | No | Max tokens per day, charged by batch submissions, allowed for this budget id. |
budget_duration | string or null | No | How often spend resets to zero, for example '1h', '1d', '7d', '30d' or '1mo' |
model_max_budget | object or null | No | Max budget for each model (e.g. {'gpt-4o': {'max_budget': '0.0000001', 'budget_duration': '1d', 'tpm_limit': 1000, 'rpm_limit': 1000}}) |
budget_reset_at | string or null | No | Datetime when the budget is reset |
Example request:
curl -X POST "http://localhost:4000/budget/update" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"budget_id": "free-tier",
"max_budget": 10
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The budget as stored | application/json Spanway_BudgetTableFull |
| 400 | The request breaks a rule named in the detail | application/json ErrorDetail |
| 401 | No valid key was sent, or the key belongs to someone who is not a proxy admin | application/json ProxyError |
| 403 | An admin viewer tried to change a budget, and admin viewers can only read | application/json ProxyError |
| 404 | No budget has that budget_id | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
budget_id | string or null | No | Budget Id |
soft_budget | number or null | No | Soft Budget |
max_budget | number or null | No | Max Budget |
max_parallel_requests | integer or null | No | Max Parallel Requests |
tpm_limit | integer or null | No | Tpm Limit |
rpm_limit | integer or null | No | Rpm Limit |
tpd_limit | integer or null | No | Tpd Limit |
model_max_budget | object or null | No | Model Max Budget |
budget_duration | string or null | No | Budget Duration |
allowed_models | array of string or null | No | Allowed Models |
temp_budget_increase | number or null | No | Temp Budget Increase |
temp_budget_expiry | string or null | No | Temp Budget Expiry |
budget_reset_at | string or null | No | Budget Reset At |
created_at | string | Yes | Created At |
created_by | string or null | No | Created By |
updated_at | string or null | No | Updated At |
updated_by | string or null | No | Updated By |
POST /budget/info
Look up budgets by id
Return the stored budgets for the budget_id values in budgets.
Ids that do not exist are left out of the answer rather than reported, so compare the result with what you sent. An empty list is a 400. Proxy admins and admin viewers only.
Docs (https://docs.spanway.ai/docs/proxy/budget_management)
Request body (application/json, schema BudgetRequest):
| Field | Type | Required | Description |
|---|---|---|---|
budgets | array of string | Yes | Budgets |
Example request:
curl -X POST "http://localhost:4000/budget/info" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"budgets": [
"free-tier",
"pro-tier"
]
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The budgets that exist among the ids sent | application/json array of Spanway_BudgetTableFull |
| 400 | The request breaks a rule named in the detail | application/json ErrorDetail |
| 401 | No valid key was sent, or the key belongs to someone who is not a proxy admin | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database connected | application/json ErrorDetail |
GET /budget/settings
Show the editable fields of a budget
List every field a budget can carry, with its type, description and the value stored for budget_id.
The Admin UI uses this to build the edit form. An unknown budget_id returns the fields with empty values.
Proxy admins and admin viewers only, a different role or a gateway without a database is a 400.
Docs (https://docs.spanway.ai/docs/proxy/budget_management)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
budget_id | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/budget/settings?budget_id=budget_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | One entry per editable field with its type, description and current value | application/json array of ConfigList |
| 400 | The caller is not a proxy admin or admin viewer, or no database is connected | application/json ErrorDetail |
| 401 | No valid key was sent, or the key belongs to someone who is not a proxy admin | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
GET /budget/list
List every budget
Return every budget as one array, which is what the Budgets page of the Admin UI shows.
Use GET /management/v1/budgets for a paged, sorted and filtered list. Proxy admins and admin viewers only,
a different role or a gateway without a database is a 400.
Docs (https://docs.spanway.ai/docs/proxy/budget_management)
Example request:
curl -X GET "http://localhost:4000/budget/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Every budget in the database | application/json array of Spanway_BudgetTableFull |
| 400 | The caller is not a proxy admin or admin viewer, or no database is connected | application/json ErrorDetail |
| 401 | No valid key was sent, or the key belongs to someone who is not a proxy admin | application/json ProxyError |
POST /budget/delete
Delete a budget
Delete the budget named by id and return the row that was removed.
Keys, end users, tags and projects that pointed at it keep their own spend but lose the shared limits, so move
them to another budget first. A budget that an organization uses cannot be deleted, which is a 400 naming the
organization, and an unknown id is a 404. Proxy admins only, any other role is a 400. With audit logging on,
the deletion is written to the audit log.
Docs (https://docs.spanway.ai/docs/proxy/budget_management)
Request body (application/json, schema BudgetDeleteRequest):
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Id |
Example request:
curl -X POST "http://localhost:4000/budget/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"id": "free-tier"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The budget as stored | application/json Spanway_BudgetTableFull |
| 400 | The request breaks a rule named in the detail | application/json ErrorDetail |
| 401 | No valid key was sent, or the key belongs to someone who is not a proxy admin | application/json ProxyError |
| 403 | An admin viewer tried to change a budget, and admin viewers can only read | application/json ProxyError |
| 404 | No budget has that id | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
budget_id | string or null | No | Budget Id |
soft_budget | number or null | No | Soft Budget |
max_budget | number or null | No | Max Budget |
max_parallel_requests | integer or null | No | Max Parallel Requests |
tpm_limit | integer or null | No | Tpm Limit |
rpm_limit | integer or null | No | Rpm Limit |
tpd_limit | integer or null | No | Tpd Limit |
model_max_budget | object or null | No | Model Max Budget |
budget_duration | string or null | No | Budget Duration |
allowed_models | array of string or null | No | Allowed Models |
temp_budget_increase | number or null | No | Temp Budget Increase |
temp_budget_expiry | string or null | No | Temp Budget Expiry |
budget_reset_at | string or null | No | Budget Reset At |
created_at | string | Yes | Created At |
created_by | string or null | No | Created By |
updated_at | string or null | No | Updated At |
updated_by | string or null | No | Updated By |