Skip to main content

Team budgets

Teams are the usual unit of cost ownership on the gateway. A team groups people and keys, and its budget caps the combined spend of every key in it. Budgets reset on a schedule you choose, and the gateway rejects requests from a team's keys once the team has spent its budget, until the next reset. Members can get a budget of their own inside the team, and organizations above teams and tags across teams carry budgets of their own.

When you would use this​

The data science team gets 500 dollars a month. One member tends to run large batch jobs, so they get a 50 dollar cap inside the team. The team shares a reserved provisioned throughput deployment with another team, so each team gets a token ceiling on that model. When the team crosses 400 dollars the finance channel gets an alert, and at 500 every key in the team stops until the first of the month.

Before you start​

You need a proxy admin key or Admin role session to create teams, or an organization admin role to create teams in your organization. For alerts on soft_budget, configure alerting or email.

Step by step​

  1. Create the team with a budget. In the Admin UI open Teams, click Create Team, fill in Team Name, pick Models, set Max Budget (USD), Reset Budget, Tokens per minute Limit (TPM) and Requests per minute Limit (RPM), and click Create Team. Over the API call POST /team/new.

    curl -X POST http://localhost:4000/team/new \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{
    "team_alias": "data-science",
    "max_budget": 500,
    "budget_duration": "30d",
    "soft_budget": 400,
    "tpm_limit": 200000,
    "rpm_limit": 600,
    "models": ["claude-sonnet-5-5", "claude-haiku-5-5"],
    "members_with_roles": [{"role": "admin", "user_id": "user-123"}]
    }'
    {
    "team_id": "team-ds",
    "team_alias": "data-science",
    "organization_id": null,
    "admins": ["user-123"],
    "members": [],
    "members_with_roles": [{"role": "admin", "user_id": "user-123", "user_email": null}],
    "team_member_permissions": null,
    "max_budget": 500.0,
    "soft_budget": 400.0,
    "budget_duration": "30d",
    "budget_reset_at": "2026-12-21T00:00:00Z",
    "spend": 0.0,
    "tpm_limit": 200000,
    "rpm_limit": 600,
    "models": ["claude-sonnet-5-5", "claude-haiku-5-5"],
    "blocked": false,
    "metadata": {}
    }
  2. Give a member a budget inside the team. Open the team, open the Members tab, click Add Member, pick the user and the Member Role, then click the edit icon on the row and set Team Member Budget (USD). Over the API pass max_budget_in_team on POST /team/member_add or POST /team/member_update. team_member_budget on the team sets a default for every member.

    curl -X POST http://localhost:4000/team/member_add \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"team_id": "team-ds", "member": {"role": "user", "user_id": "user-123"}, "max_budget_in_team": 50}'
  3. Change the team's limits later. Open the Settings tab, click Edit Settings, change Max Budget (USD) or the rate limits and click Save Changes. Over the API call POST /team/update with the fields to change.

    curl -X POST http://localhost:4000/team/update \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"team_id": "team-ds", "max_budget": 800, "tpm_limit": 200000}'
  4. Share reserved capacity between teams. When several teams share one Azure provisioned throughput (PTU) deployment, give each team a token ceiling on that model with model_tpm_limit, so one team cannot use up the reservation the others rely on. In the Admin UI that is a row under Model-Specific Rate Limits on the team's Settings tab.

    curl -X POST http://localhost:4000/team/update \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"team_id": "team-ds", "model_tpm_limit": {"gpt-ptu": 60000}}'

    The key is the model name clients send. A team over its ceiling gets a 429 for that model only and keeps working on its other models, and every key in the team shares the ceiling. When the teams belong to an organization with its own tpm_limit or model_tpm_limit, the gateway refuses to hand out more tokens per minute across its teams than the organization has. Set tpm on the PTU deployment itself to the reservation's real throughput so the router sends overflow to a fallback deployment instead of the provider's 429. The reservation's flat cost is reported per team as described under cost attribution.

  5. Watch the spend. The Teams table shows Spend / Budget per team, the team's Overview tab shows Budget Status, and the Members tab shows each member's Current Cycle Spend (USD) against their budget. Over the API GET /team/info returns the team with spend, and GET /team/spend/by_user and GET /team/daily/activity report spend by member, key and model.

    curl "http://localhost:4000/team/info?team_id=team-ds" -H "Authorization: Bearer $SPANWAY_API_KEY"

What you should see​

The team appears on Teams with a Spend / Budget meter. Requests from the team's keys succeed for models on the team's list. When the team's spend reaches max_budget, requests from its keys fail with a budget exceeded error that says which budget was hit, and keys of the team keep their own budgets too, so a request can be stopped by the key budget, the member budget or the team budget, whichever is reached first. When the team crosses soft_budget, alerting and email notifications fire if configured. Team admins cannot raise their own team's budget unless a proxy admin allows it, see access control.

Fields​

FieldMeaning
max_budgetHard cap in US dollars across all of the team's keys.
budget_durationHow often spend resets, such as 1d, 7d or 30d.
soft_budgetSpend level that triggers an alert without blocking.
tpm_limit, rpm_limitRate limits shared by the team's keys.
model_tpm_limit, model_rpm_limitToken and request limits per model for the team, such as a share of reserved capacity.
model_max_budgetSeparate caps per model.
team_member_budgetDefault budget for each member inside the team.
max_budget_in_teamOne member's cap, on /team/member_add and /team/member_update. /team/{team_id}/member/{user_id}/reset_spend and /reset_budget reset one member.
MethodPathSummary
POST/team/newCreate a team
POST/team/updateUpdate a team
POST/team/member_addAdd members to a team
POST/team/member_deleteRemove a member from a team
POST/team/member_updateChange a member's role or budget in a team
POST/team/deleteDelete teams
GET/team/infoGet a team with its keys and members
POST/team/blockBlock a team
POST/team/unblockUnblock a team
GET/team/listList teams

Organization budgets​

An organization's max_budget caps the combined spend of every team and key in it, on top of each team's own budget. Set it with max_budget and budget_duration on /organization/new or PATCH /organization/update, or with Max Budget (USD) on the Organizations page. A team's max_budget can never be set above its organization's.

curl -X POST http://localhost:4000/organization/new \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"organization_alias": "research", "max_budget": 5000, "budget_duration": "30d", "models": ["claude-sonnet-5-5", "claude-haiku-5-5"]}'

Organizations, and so organization budgets, are part of Spanway Enterprise. Every /organization route answers 403 without a Spanway license. Any valid license turns them on, whatever features it lists, because Cloud tenants, billing accounts and organization SSO are all built on organizations.

Tag budgets​

A tag created with /tag/new or changed with /tag/update can carry its own budget. Requests name tags through metadata.tags or the x-spanway-tags header, and every request that carries the tag counts toward its spend.

FieldMeaning
max_budgetHard cap in US dollars across every request that carries the tag.
budget_durationHow often the tag's spend resets, such as 1d, 7d or 30d. The budget reset job zeroes it at each reset.
soft_budgetStored, but a tag's soft budget sends no alert. Use a team or key soft budget to be warned.
tpm_limit, rpm_limit, max_parallel_requestsRate limits shared by every request with the tag.
model_tpm_limit, model_rpm_limitToken and request limits per model for the tag.
model_max_budgetSeparate caps per model.
budget_idReuse an existing shared budget instead of creating one from the fields above.
curl -X POST http://localhost:4000/tag/new \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"name": "chat-app", "max_budget": 200, "budget_duration": "30d"}'

Once a tag has spent its max_budget, a request that carries it is refused at authentication with a budget exceeded error such as Budget has been exceeded! Tag=chat-app Current cost: 200.4, Max budget: 200, answered with status 422 by default. The request is not routed anywhere else. To move traffic away from deployments instead, see tag budgets in routing.

Budget windows and fallbacks​

A key or a team can carry several budgets at once, each with its own period, for example 20 dollars a day and 300 dollars a month. This stops one bad day from using a whole month's money while still capping the month. Each window resets on its own schedule, and the request is refused when any window is spent, with ExceededBudget: Key over 1d budget. Spend=$20.0100, Limit=$20.00 and status 422.

  1. In the Admin UI, open Virtual Keys, select the key, open Settings, select Edit Settings and add rows under the budget windows control, each with a period and an amount.

  2. Or set them with the API:

    curl -X POST http://localhost:4000/key/generate \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"team_id": "team-ds", "budget_limits": [{"budget_duration": "1d", "max_budget": 20}, {"budget_duration": "30d", "max_budget": 300}], "model_max_budget": {"claude-opus-5-5": {"max_budget": 50, "budget_duration": "30d"}}, "budget_fallbacks": {"claude-opus-5-5": ["claude-sonnet-5-5"]}}'

Expected result: the key is created with both windows. budget_fallbacks goes with model_max_budget: once the key has spent its 50 dollar monthly cap on claude-opus-5-5, its requests for that model go to claude-sonnet-5-5 instead of failing, as long as the fallback model is within its own budget and allowed for the key and team. With no fallback left within budget, the request is refused with 422. The window spend is counted in Redis, so after a Redis flush each window starts again from zero for the rest of its current period.

Temporary budget increases​

A temporary increase raises a key's or a team member's budget until a date, then drops back by itself, for example for a launch week. It is added on top of the normal budget, so the normal max_budget must be set.

curl -X POST http://localhost:4000/team/member_update \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"team_id": "team-ds", "user_id": "dana", "temp_budget_increase": 25, "temp_budget_expiry": "2026-12-01T00:00:00Z"}'

curl -X POST http://localhost:4000/key/update \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"key": "sk-9f3a2c7e41b8d6059012ijkl3456mnop", "temp_budget_increase": 25, "temp_budget_expiry": "2026-12-01T00:00:00Z"}'

Expected result: until the expiry the member or key may spend 25 dollars more than its budget, and after it the normal budget applies again with no further change. Sending one of the two fields without the other is refused with 422 Value error, temp_budget_increase and temp_budget_expiry must be set together. A team as a whole has no temporary increase, raise its max_budget instead.

Reporting​

/team/spend/by_user and the daily activity endpoints under /team/daily/activity report spend by team, member, key and model, and the Usage page in the Admin UI charts the same data. GET /team/spend/report and the other spend reports need a Spanway license that includes spend_reports. See cost tracking for how costs are calculated, and billing to invoice teams for their usage.

Errors​

ErrorCauseFix
422 Budget has been exceeded! Current cost: ..., Max budget: ... or ExceededBudget: ...The team, a member, the key, a budget window or the organization spent its budget. The message names the amounts. The status is spanway_settings.budget_exceeded_status_code, 422 by default.Raise the budget, wait for the reset, or reset a member with /team/{team_id}/member/{user_id}/reset_spend.
429 naming a modelThe team's model_tpm_limit or model_rpm_limit for that model is used up this minute.Raise the ceiling or wait a minute. Other models keep working.
429 without a modelThe team's tpm_limit or rpm_limit is used up.Raise the limit or slow the clients down.
400 about the team budget and the organizationThe team budget is above the organization's.Lower it or raise the organization's budget.
400 naming a team field from a team adminTeam admins may not change that field.Ask a proxy admin, or allow the field as access control describes.
403 Assigning admins is an enterprise-only featureA team admin role was assigned without a license.Add a license, or add the person as a user.
503 when a budget cannot be checkedThe gateway cannot reach Redis or its database and refuses requests it cannot count.Restore the connection. Redis requirements explains the fail closed setting.
Soft budget crossed but no alertAlerting or email is not configured, or the soft budget is on a tag, customer or organization, which send no soft budget alert.Set up alerting or email, and put the soft budget on the team or key.
422 Value error, temp_budget_increase and temp_budget_expiry must be set togetherOnly one of the two temporary increase fields was sent.Send both.

Logs​

LevelLineMeaningAction
DEBUGCrossed Soft Budget for team <id>, spend <n>, soft_budget <n>The team passed its soft budget, and the alert goes out when alerting is on.None.
WARNINGUnrecognized budget_duration '<value>'; falling back to a next-midnight reset. ...A stored budget period cannot be read, so it resets every midnight.Set a valid budget_duration.

The log reference lists every budget line.