Budget tiers
A budget tier policy lets a team or organization keep working for the whole budget period instead of hitting its spending limit early. You map three tiers, frontier, balanced and economy, to routing presets, pick the tier requests start on, and set the budget percentages at which they move to a cheaper tier, for example 75 and 90. Applications send "model": "@tier" and the gateway serves each request from the preset of the tier the budget allows right now. When the budget resets, requests move back up on their own. Tier policies apply to /v1/chat/completions, /v1/responses and /v1/messages, are part of the free gateway and need a connected database.
A real-world scenario
The support team has a monthly budget of 2,000 USD. Early in the month the admin wants answers from the strongest models, but a busy week must not leave the team with no AI help for the last days of the month. The admin creates three global presets, frontier-models, balanced-models and economy-models, and gives the support team a tier policy that starts on frontier, moves to balanced at 75 percent of the budget used and to economy at 90 percent. The support tools send @tier. On the 22nd the team passes 1,500 USD, the gateway moves new requests to the balanced preset, writes an audit row, sends the Budget Tier Shift alert to Slack and the operators see budget_tier=balanced in the response headers. On the 1st the budget resets and the next request moves the team back to frontier.
Step by step
In the Admin UI
- Create the presets first. Open
/ui/routing-presetsas a proxy admin, keep the scopeglobal, click New preset and savefrontier-models,balanced-modelsandeconomy-models, each with the models of that tier in Configuration (JSON), for example{"models": ["claude-opus-5-5", "gpt-5.6"]}. - Scroll to Budget tiers on the same page and click New tier policy.
- Leave Applies to at
teamand type the team id in Team or organization id. Pickorganizationinstead to cover every team of the organization. A team with its own policy is then served the cheaper of its own tier and the organization's tier. - Type the preset names in frontier preset, balanced preset and economy preset, without
@preset/. Leave a tier empty if this policy never uses it. - Leave Starting tier at
frontier, First shift at (% of budget used) at75with First shift moves tobalanced, and Second shift at (% of budget used) at90with Second shift moves toeconomy. Clear a percentage to turn that shift off. - Click Save. A toast reads Saved the budget tier policy of team ..., and the table shows the policy with Tier now, Budget, Presets and Shifts.
- Send a request with
"model": "@tier"from a key of that team.
With curl
Assign the policy.
curl -X PUT http://localhost:4000/routing/tier_policies/team/team-support \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{
"config": {
"presets": {"frontier": "frontier-models", "balanced": "balanced-models", "economy": "economy-models"},
"default_tier": "frontier",
"shifts": [{"at_percent": 75, "tier": "balanced"}, {"at_percent": 90, "tier": "economy"}]
}
}'
| Field | What it does |
|---|---|
path scope_type | team or organization. |
path scope_id | The team id or organization id whose budget decides the tier. |
config.presets | The routing preset name for frontier, balanced and economy. A tier left out is never used. |
config.default_tier | The tier requests start on while the budget is healthy. Default frontier. It needs a preset. |
config.shifts | Up to two shifts. Each moves requests to a cheaper tier once at_percent of the budget is used, above 0 and at most 100. Percentages rise and each shift is cheaper than the one before it. Default none, so the policy stays on its starting tier. |
Use it, and read the policy back.
curl -i -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "@tier", "messages": [{"role": "user", "content": "Summarise this ticket"}]}'
curl http://localhost:4000/routing/tier_policies/team/team-support -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
Expected result
The PUT answers with the policy, the share of the budget used and the tier that share selects.
{
"policy": {
"scope_type": "team",
"scope_id": "team-support",
"config": {
"presets": {"frontier": "frontier-models", "balanced": "balanced-models", "economy": "economy-models"},
"default_tier": "frontier",
"shifts": [{"at_percent": 75.0, "tier": "balanced"}, {"at_percent": 90.0, "tier": "economy"}]
},
"active_tier": "balanced",
"active_since": "2026-11-24T08:15:02.411Z",
"updated_by": "admin@example.com",
"updated_at": "2026-11-24T08:15:02.411Z"
},
"budget_used_percent": 78.4,
"budget_tier": "balanced"
}
With 78.4 percent of the budget used, the chat request is served by the first model of balanced-models, with its other models as fallbacks, and the x-spanway-routing-reason response header carries preset=balanced-models@1 and budget_tier=balanced. The request metadata and the spend log record routing_preset and routing_budget_tier, so the logs page shows which tier served each request. A client cannot set routing_budget_tier itself.
How the tier is chosen
The budget used is the spend of the policy's team or organization divided by its maximum budget, in percent. The gateway picks the cheapest tier whose shift percentage has been reached, or the starting tier when none has. A team or organization with no maximum budget always stays on its starting tier.
"model": "@tier"uses that tier."model": "@tier/frontier",@tier/balancedor@tier/economyasks for a tier. The gateway serves the cheaper of the requested tier and the budget tier, so a request can always ask for less but never for more than the budget allows. Asking for a tier the policy leaves empty answers 400.- The chosen tier's preset is then applied exactly like
@preset/<name>, so its models, provider preferences and parameter defaults apply, and the request's own values still win.
The policy only changes what @tier means. A request that names a model or a preset directly is not moved. To make sure a team cannot bypass the tiers, limit the team's models to the models in the three presets.
Team and organization policies
A request looks for a policy of its key's team and for a policy of the key's organization, or of the team's organization when the key has none. When only one exists, that policy decides. When both exist, the gateway works out the tier each one allows and serves the cheaper of the two, and the organization policy wins a tie. This way a team admin cannot lift the team above the tier the organization's budget allows, for example by saving a team policy that never shifts, while a team can still choose to run cheaper than its organization. Each policy still records its own shifts, with its own audit row and alert, whichever one served the request. Each team or organization has at most one policy, and saving again replaces it. A team policy can use the team's own presets and global presets. An organization policy can only use global presets, because its members belong to different teams, and when the organization policy decides, its preset names are always looked up among global presets, never among the team's own. The policy and the budget it reads are cached on each replica for 30 seconds, so a new policy, a removal or a budget change reaches every replica within that time.
Proxy admins can assign, change and remove every policy. Admins of a team can do the same for that team's policy, but not for an organization. Read-only roles are refused every write. Proxy admins and admin viewers can list all policies, team members can read their team's policy and members of an organization can read its policy.
| Method | Path | Summary |
|---|---|---|
| GET | /routing/tier_policies | List the budget tier policies |
| GET | /routing/tier_policies/{scope_type}/{scope_id} | Read a budget tier policy |
| PUT | /routing/tier_policies/{scope_type}/{scope_id} | Assign a budget tier policy |
| DELETE | /routing/tier_policies/{scope_type}/{scope_id} | Remove a budget tier policy |
Shifts, alerts and audit
When a request finds that the budget now selects a different tier than the one recorded for the policy, the gateway records the new tier once, even when many replicas see it at the same moment. That writes:
- an audit row on
Spanway_TierPolicyTablewithchanged_bysystem:tier_policies,active_tierbefore and after,reasonbudget_thresholdandbudget_used_percent, see audit logs, - one
WARNINGlog line, see Logs below, - one count on the
spanway_budget_tier_shifts_totalPrometheus counter, byscope_typeandto_tier, see Prometheus, - the Budget Tier Shift alert, described next.
Every save and removal from the Admin UI or the API writes an audit row with the policy before and after.
Alerts
The budget_tier_shift alert type is on by default. It goes to every alerting destination you set up, Slack, webhooks, email or PagerDuty, as Medium when the team moves to a cheaper tier and as Low when it moves back up after a budget reset. The message names the team or organization, both tiers and the share of the budget used, for example "The team team-support moved down from the frontier tier to the balanced tier because 76% of its budget is used." To stop these alerts, leave budget_tier_shift out of alert_types, or turn off Budget Tier Shift on the Alerting Types tab of Settings, then Logging & Alerts.
Limits
- A shift is noticed by the next
@tierrequest, not by a timer. A team that sends no@tierrequest records no shift and gets no alert. - Spend counts the same way the budget does, including its reset period. A budget reset moves the team back to its starting tier on the next request.
- Removing a team or organization does not remove its policy. Remove the policy first, or later with
DELETE /routing/tier_policies/{scope_type}/{scope_id}. - The request inspector does not resolve
@tieryet. Dry run the tier's preset with@preset/<name>instead. - Tier policies need a connected database. Without one, a request that sends
@tierfails with a 500, and every other request is unaffected.
Errors
Errors from the management routes under /routing/tier_policies:
| What you see | Why | Fix |
|---|---|---|
400 Routing preset 'economy-models' does not exist for team 'team-support' or globally | A tier names a preset the team cannot use. | Create the preset first, or fix the name. |
400 Routing preset 'economy-models' does not exist globally | An organization policy names a preset that is not global. | Use a global preset. |
403 Only proxy admins can change organization budget tier policies | A team admin or internal user wrote an organization policy. | Use a proxy admin key. |
403 Only proxy admins or admins of team 'team-support' can change its budget tier policy | The caller is not an admin of that team. | Ask a team admin or a proxy admin. |
403 Read-only roles cannot change budget tier policies | A viewer role tried to write. An admin viewer can be refused earlier by the route check with a plain text detail. | Use a key with a writing role. |
403 You cannot read the budget tier policy of team 'team-support' | The caller is not a member of that team or organization. | Read your own team's policy. |
403 Only proxy admins and admin viewers can list every budget tier policy | Another role called GET /routing/tier_policies. | Read your team's policy by its path instead. |
404 No team 'team-support' exists or No organization 'org-1' exists | The id is wrong or was deleted. | Copy the id from the Teams or Organizations page. |
404 No budget tier policy is assigned to team 'team-support' | A read or removal named a scope with no policy. | Check the scope type and id. |
422 Value error, the default tier 'frontier' has no routing preset | The starting tier has no preset. | Fill its preset, or pick another starting tier. |
422 Value error, the shift at 90% must move to a tier cheaper than 'economy' | A shift does not move to a cheaper tier than the one before it. | Order the shifts from expensive to cheap. |
422 Value error, shifts must be listed with rising at_percent values | The second shift's percentage is not above the first. | Raise the second percentage. |
422 Value error, the shift at 75% moves to 'balanced', which has no routing preset | A shift moves to an empty tier. | Fill that tier's preset. |
500 No database connected | Tier policies live in the database. | Connect a database. |
Errors on inference requests that send @tier:
| What you see | Why | Fix |
|---|---|---|
400 '@tier/premium' names no tier. Use @tier, @tier/economy, @tier/balanced or @tier/frontier | The tier name is misspelled. | Use one of the four forms. |
400 The budget tier policy maps no routing preset to the 'economy' tier | The request asked for a tier the policy leaves empty. | Send @tier, or fill that tier. |
400 @tier needs a key that belongs to a team or an organization | The key has no team and no organization, so no policy can apply. | Use a team key. |
400 Send either model @tier or a preset field, not both | The request also sent a preset field. | Drop the preset field. |
404 No budget tier policy is assigned to this key's team or organization | Neither the team nor the organization has a policy. | Assign one, or send a model name. |
404 No routing preset '@preset/economy-models' | The tier's preset was deleted after the policy was saved. | Create the preset again, or change the policy. |
500 Budget tier policies need a connected database | The gateway has no database. | Connect a database. |
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| WARNING | budget tier shift: team team-support moved from frontier to balanced at 76.2% budget used | The policy moved the team or organization to another tier. It is written once per shift. | None. Check the budget if it happens sooner than planned. |
| ERROR | budget tier shift alert failed for <id>: <error> | The shift is saved and audited, but the alert could not be sent. | Check the alerting destination. |
| ERROR | budget tier shift could not be recorded: <error> | The database refused the shift write. Requests are still served on the new tier. | Check the database. The next request after it recovers records the shift. |
| WARNING | Could not register the budget tier shift metric: <error> | The Prometheus counter is missing on this replica. Shifts still work. | Check that metrics are turned on for this replica, or ignore it if you do not scrape metrics. |
The log reference and the error reference list the same lines and messages.
Traces and analytics
With OpenTelemetry turned on, every request that sends @tier gets a spanway.budget_tier event on its request span. The event carries spanway.budget_tier.scope_type and spanway.budget_tier.scope_id (the team or organization whose policy decided), spanway.budget_tier.served (the tier that served the request) and spanway.budget_tier.budget_tier (the tier the budget used selects). It never carries the prompt.
On the Query page the spend_logs table has a budget_tier and a routing_preset column, so you can count requests and spend per tier, for example:
SELECT budget_tier, count(*) AS requests, sum(spend) AS spend
FROM spend_logs
WHERE budget_tier IS NOT NULL
GROUP BY budget_tier
The daily tables that Explore charts do not split by tier, so per tier charts are built from that query.
Related
- Routing presets explains the presets each tier points at.
- Routing Presets page documents every control of the Budget tiers section.
- Routing headers explains
x-spanway-routing-reason. - Budgets and rate limits explain how team and organization budgets are set and reset.
- Alerting lists every alert type and where alerts go.