Budgets page
A budget on this page is a reusable set of limits, a max spend, a reset period, tokens and requests per minute, and a daily batch token cap, saved under a budget ID. You assign a budget ID to a customer (an end user of your app, sent as the user field of a request) so that customer is held to those limits. The page also lists the provider budgets saved in the gateway config, and a proxy admin can add, edit and delete them there. It lives at /ui/budgets and sits under ACCESS CONTROL in the left nav as Budgets. The nav item shows only for the session roles Admin (proxy_admin) and Admin Viewer (proxy_admin_viewer). The page has no license gate.
A real-world scenario
A company sells a free tier where each end customer may spend 5 dollars a month. The admin creates one free-tier budget and assigns its id to every free customer, so changing the free tier later means editing one budget.
Steps
-
Open Budgets under Access Control, or go to
/ui/budgets, and click Create Budget. -
Type the budget id, the max budget and the reset period, and save. The same with the API:
curl -X POST http://localhost:4000/budget/new \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"budget_id": "free-tier", "max_budget": 5, "budget_duration": "30d", "rpm_limit": 20}' -
Assign the budget to a customer on the Customers page, or with
/customer/newand"budget_id": "free-tier".
Expected result
The budget is listed, and requests from a customer on it are refused with budget_exceeded once they spend 5 dollars in the period.
Page header and tabs
The header reads Budgets with the description "Spend, TPM and RPM limits you can assign to customers."
| Control | Type | Shown to | What it does |
|---|---|---|---|
| Create Budget | Button | Session role Admin | Opens the Create Budget dialog. |
| Budgets | Tab | Everyone who opens the page | The budget table. Selected by default. |
| Provider budgets | Tab | Session roles Admin and Admin Viewer | Spend against the per-provider budgets, with Add provider budget and a row menu for the session role Admin. |
| Examples | Tab | Everyone who opens the page | Code that shows how to use a budget ID. |
Budgets tab
The table is paginated, sorted and filtered on the server, with 25, 50 or 100 rows per page. It also lists the budget rows the gateway creates by itself for an organization's limits and for a team member's limits, which have generated ids. Editing or deleting one of those changes that organization's or member's limits, so change them from the organization or team instead.
| Control | Type | What it does |
|---|---|---|
| Search | Text box | Placeholder "Search by budget ID…". |
| Refresh | Button | Reloads the list. |
| Columns | Menu | Shows or hides columns. Reset and Created are hidden by default. |
| Filters | Button | Opens the Filters drawer ("Narrow down your budgets"), with a count of active filters. Active filters show as chips with Clear all. |
| Filter | Type | What it does |
|---|---|---|
| Reset | Checkboxes | hourly, daily, weekly, monthly, or "Not set" for budgets with no reset. Picking "Not set" clears the other choices and the reverse. |
| Max Budget (USD) | Two numbers and a checkbox | Min and Max bound the budget. Unlimited only shows only budgets with no max spend and disables the two boxes. |
| Created | Two dates | The first and last creation date to include. |
Apply Filters applies the drawer, and Reset clears it.
| Column | Meaning |
|---|---|
| Budget ID | The budget's name, with a copy button. Sortable. |
| Max Budget | The max spend with two decimals, or "Unlimited". Sortable. |
| TPM | Tokens per minute, or "n/a". Sortable. |
| RPM | Requests per minute, or "n/a". Sortable. |
| TPD (batch) | Tokens per day for batch submissions, or "n/a". Sortable. |
| Reset | How often the spend resets, or "Not set". Hidden by default. |
| Created | When the budget was created. Sortable, hidden by default. |
| Actions | A row menu with Edit budget and Delete budget, shown to the session role Admin. |
Delete budget opens Delete Budget? with the budget ID, max budget, TPM, RPM and TPD values and the warning "Are you sure you want to delete this budget? This action cannot be undone." Confirming deletes the budget and shows "Budget deleted." A deleted budget cannot be restored. The gateway lets only a proxy admin delete a budget.
Create Budget dialog
| Field | Type | What it does |
|---|---|---|
| Budget ID | Text box | Required ("Please input a human-friendly name for the budget"). A human friendly name, and the ID you assign to customers. |
| Max Tokens per minute | Number | Leave it blank for no gateway limit. Provider rate limits still apply. |
| Max Requests per minute | Number | Same as above. |
| Max Tokens per day (batch) | Number | A daily token budget for batch submissions. When set, batches are charged against this instead of TPM and RPM. |
| Optional Settings | Collapsible section | Closed by default. Holds the two fields below. |
| Max Budget (USD) | Number | Inside Optional Settings. Requests are refused once this much has been spent in the current period. Empty means no spending cap. The help text under the field says so, and that the value is saved only while Optional Settings is open. |
| Reset Budget | Dropdown | Inside Optional Settings. How often spend goes back to zero, daily, weekly or monthly. The placeholder "n/a" means spend never resets. Resets land within about 10 minutes of the reset time. |
The two optional fields are sent only while Optional Settings is open. The TPM, RPM and max budget values are rounded to two decimals before they are sent, and the gateway refuses a negative or non-finite max budget. Create Budget shows "Making API Call", then "Budget Created" and closes the dialog. On failure an "Error creating the budget" toast shows the reason.
Edit Budget dialog
Edit budget opens Edit Budget with the same fields filled in. Budget ID is read-only, with the note "Budget ID cannot be changed after creation". As in the create dialog, Max Budget (USD) and Reset Budget are sent only if you open Optional Settings, so leave it closed to keep them as they are. Save shows "Budget Updated" and closes the dialog, or "Error updating the budget" with the reason.
Provider budgets tab
A provider budget caps what the gateway may spend with one provider, such as OpenAI or Amazon Bedrock, over a time window. Once the cap is reached the router sends requests to deployments of other providers until the window resets. The tab reads the live spend from the running gateway and, for the session role Admin, the budgets saved in the gateway config, so you can see both what is enforced now and what you have changed. A short description at the top links to Provider budget routing.
When no budget is saved or enforced it says "No provider budgets are configured." Otherwise a table lists one row per provider, sorted by how much of the budget is used.
| Column | Meaning |
|---|---|
| Provider | The provider name as used in model prefixes. |
| Spend | Spend in the current period. |
| Limit | The saved budget, or the enforced one when the budget was removed, or "-". |
| Used | Spend as a percent of the limit, or "-". |
| Period | The budget period, or "-". |
| Resets | When the period resets, or "-". |
| Status | Session role Admin only. Active when the running gateway enforces the saved limit and period, Pending restart when a budget was added or changed and the gateway has not restarted since, Removal pending restart when the budget was deleted but is still enforced. |
| Actions | Session role Admin only. A row menu with Edit provider budget and Delete provider budget. Rows that are only pending removal have no menu. |
Saving a provider budget writes router_settings.provider_budget_config to the gateway config in the database. The running gateway keeps enforcing the budgets it started with, and applies the saved ones at its next restart, which is why the Status column exists. If the budgets are set in the config file instead, the gateway refuses the change with "router_settings provider_budget_config set in the config file and cannot be changed here." Move them out of the file to manage them here.
Scenario: cap a pay-as-you-go provider
Your frontier model group has an Azure deployment covered by committed spend and an OpenAI deployment paid as you go. You want at most 50 US dollars a week to reach OpenAI.
- Open
/ui/budgetsand click the Provider budgets tab. - Click Add provider budget.
- Type
openaiin Provider (the field suggests the known provider names),50in Budget limit (USD) and7din Time period. - Click Save. The toast "Provider budget saved." appears and the
openairow shows Pending restart. - Restart the gateway. The row shows Active, and Spend and Used grow as requests reach OpenAI.
The same change with curl, which is what the dialog sends.
curl -X POST http://localhost:4000/config/update \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"router_settings": {"provider_budget_config": {"openai": {"budget_limit": 50, "time_period": "7d"}}}}'
/config/update is the route the Admin UI saves settings with. It is deliberately left out of the published API reference and the Postman collection, and it stays supported, so see router settings for the body it takes.
Check what the running gateway enforces.
curl http://localhost:4000/provider/budgets \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY"
Expected result after the restart.
{"providers": {"openai": {"budget_limit": 50.0, "time_period": "7d", "spend": 0.0, "budget_reset_at": null}}}
Add and Edit provider budget dialogs
| Field | Type | What it does |
|---|---|---|
| Provider | Text box with suggestions | Required. Lowercase letters, digits and underscores, as in model prefixes such as openai or bedrock. A provider that already has a budget is refused with "This provider already has a budget. Edit that one instead." Read-only in the edit dialog. |
| Budget limit (USD) | Number | Required and above zero. The spend allowed in each period. |
| Time period | Text box | Required. A duration such as 1h, 1d, 7d, 30d or 1mo. Anything else is refused with "Use a duration such as 1h, 1d, 7d, 30d or 1mo". |
The dialog always sends the whole provider budget map, so other providers and any extra keys on the edited entry such as tpm_limit are kept. Save shows "Provider budget saved." and closes the dialog. On failure the gateway's reason shows as a toast and the dialog stays open.
Delete provider budget opens Delete provider budget? with the provider, limit and period and the warning "The provider will no longer be capped once the gateway restarts. This action cannot be undone." Confirming shows "Provider budget deleted." and the row switches to Removal pending restart until the gateway restarts.
Examples tab
Under "How to use budget id", three tabs show code you can copy.
| Tab | What it shows |
|---|---|
| Assign Budget to Customer | A curl call to /customer/new that creates a customer with a budget_id. |
| Test it (Curl) | A chat completions call that sends the customer ID in the user field. |
| Test it (OpenAI SDK) | The same call from the OpenAI Python SDK. |
Replace <your_proxy_base_url>, <your-master-key> and <BUDGET_ID> before you run them. The bodies are valid JSON as shown.
Empty, error and disabled states
| Situation | What you see | What to do |
|---|---|---|
| No budgets | "No budgets yet" and "Create a budget to set spend, TPM and RPM limits for customers." | Create one. |
| Search or filters find nothing | "No matching budgets" | Change the search or filters. |
| No permission to list | "You do not have access to budgets" and "Ask a proxy admin to grant you the admin viewer role." | Ask a proxy admin for an admin role. |
| List fails for another reason | "Could not load budgets" and the error | Reload the page. |
| Provider budgets fail | "Could not load provider budgets" and the error | Check the gateway config and reload. The same message appears when the saved config cannot be read. |
| Provider budget save refused | A toast with the gateway's reason, for example that the config file owns provider_budget_config | Move the setting out of the config file, or fix the value, and save again. |
| Loading | "Loading budgets…", or a spinner on the provider tab | Wait. |
When spend cannot be checked
Budgets fail closed by default. When the gateway cannot verify a key, team, user, org or model budget because Redis or the database cannot report spend, the request gets a 503 instead of being let through. Only an explicit fail_closed_budget_enforcement: false in general_settings admits those requests on the per instance spend. See the settings reference and Redis requirements.
Differences by role and license
| Role or setting | Effect on this page |
|---|---|
| Proxy admin (session role Admin) | Sees every tab, Create Budget, Add provider budget, the provider Status column and both row menus. |
View-only admin (proxy_admin_viewer) | Gets session role Admin Viewer. Sees the Budgets, Provider budgets and Examples tabs, but Create Budget, Add provider budget, the Status column and the row menus are hidden, and the provider tab shows only what the running gateway enforces. The gateway lets this role list budgets and refuses changes. |
| Every other role | Does not see the page in the nav. A user who opens the URL sees the forbidden message, because the gateway lists budgets only for admins. |
| License | No license is needed for this page. |
Errors
| What you see | What it means | Fix |
|---|---|---|
| The gateway refuses the budget | A negative value or an unknown reset period. | Use positive numbers and a period such as 30d. |
| No Create Budget button | Only the Admin session role creates budgets. | Sign in as a proxy admin. |
A 503 on requests | Spend could not be checked because Redis or the database is down. | Restore it, see When spend cannot be checked. |
| "Failed to delete budget" | The budget is an organization's budget, which cannot be deleted while the organization uses it, or it was already deleted. | Give the organization another budget first, see budget management errors. |
Logs
The page writes no log lines of its own. The budget lines the gateway writes are in the log reference.