Users
An internal user is a person who signs in to the Admin UI or owns keys. Each user has a role that says what they may manage, an optional budget that caps what they spend on their personal keys (keys that belong to no team), a list of models they may use, and the keys they created. Users are created by admins, by invitation link, or automatically on first single sign-on.
When you would use this
A new developer joins. You create a user for them with the internal_user role, a 25 dollar monthly budget and one model, and send them the invitation link. They sign in, create their own key on the Virtual Keys page, and can never spend more than 25 dollars a month on their personal keys. Keys they create inside a team count against the team's budget instead, unless general_settings.apply_user_budget_to_team_keys is on, see settings reference. When they move to another project you change the budget and models on the user, not on each key.
Before you start
The gateway needs a database and a master key. In the Admin UI you need the Admin role to create users, or the Org Admin role to create users inside your organization. For the invitation email, configure email first, otherwise copy the link from the dialog.
Step by step
-
Create the user. In the Admin UI open Internal Users and click + Invite User. Fill in User Email, pick the Global Proxy Role, optionally a Team and Organization, open Personal Key Creation to pick the Models the user may use outside a team, leave Send invitation email ticked and click Invite User. Over the API call
POST /user/new.curl -X POST http://localhost:4000/user/new \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"user_email": "dev@example.com","user_role": "internal_user","max_budget": 25,"budget_duration": "30d","models": ["claude-sonnet-5-5"]}'{"user_id": "user-123","user_email": "dev@example.com","user_role": "internal_user","key": "sk-9f3a2c7e41b8d605","key_alias": null,"max_budget": 25.0,"budget_duration": "30d","models": ["claude-sonnet-5-5"],"teams": []}The response includes the
user_idand, unless you passauto_create_key: false, a first key for the user. Setsend_invite_email: trueto email an invitation link when email is configured. The Admin UI shows the Invitation Link dialog with the link to copy. -
Look the user up. Click the user's row on Internal Users to open the detail view with the Overview and Details tabs. Over the API call
GET /user/info, which returns the user with their keys and teams, orGET /v2/user/infofor the profile and limits alone.curl "http://localhost:4000/user/info?user_id=user-123" -H "Authorization: Bearer $SPANWAY_API_KEY" -
Change the role or budget. On the Details tab click Edit Settings, change Global Proxy Role or Max Budget (USD) and save. Over the API call
POST /user/update. Whenmax_internal_user_budgetorinternal_user_budget_durationis set underspanway_settings, an update that sendsuser_role: internal_userwithout a budget resets the user's budget and reset period to those defaults, even if the role did not change, so sendmax_budgetandbudget_durationtoo when you only change the role.curl -X POST http://localhost:4000/user/update \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"user_id": "user-123", "user_role": "internal_user", "max_budget": 50}' -
List and remove users. Internal Users pages through every user with search and role filters, and the row menu has Delete user. Over the API
GET /user/listsupports paging and filters by role, team and email, andPOST /user/deleteremoves users and their keys. Deleting a user does not delete spend logs, so historical reports stay intact. To block a person temporarily, block their keys with/key/blockinstead.curl "http://localhost:4000/user/list?page=1&page_size=25" -H "Authorization: Bearer $SPANWAY_API_KEY"curl -X POST http://localhost:4000/user/delete \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"user_ids": ["user-123"]}' -
Change many users at once. Select rows on Internal Users and use Bulk Edit, or call
POST /user/bulk_updatewith a list of users, orall_users: truewithuser_updates.curl -X POST http://localhost:4000/user/bulk_update \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"users": [{"user_id": "user-123", "max_budget": 50}, {"user_id": "user-456", "max_budget": 50}]}'
What you should see
The user appears on Internal Users with their role, spend and budget. When they sign in they see the pages their role allows, and every personal key they create counts against their user budget. GET /v2/user/info shows spend growing and budget_reset_at for the next reset. When the user's spend reaches max_budget, requests with their personal keys fail with 422 budget_exceeded until the reset. Team keys keep working unless apply_user_budget_to_team_keys is on.
Roles
| Role | What the user can do |
|---|---|
proxy_admin | Everything on the gateway. |
proxy_admin_viewer | Sign in and view all keys, teams and spend, without changing anything. |
internal_user | Sign in, create and delete their own keys, and view their own spend. |
internal_user_viewer | Sign in and view their own keys and spend. |
Organization admin is not a role you pick here. It is set per organization membership, see organizations, and user_role: org_admin on /user/new or /user/update is refused with 422. Team roles (admin and user) are set per team membership and are separate from the user role. Enterprise deployments can define custom roles with a chosen set of permissions.
Defaults for new users
New users created by SSO, by /user/new or by bulk invite without explicit values get the defaults from spanway_settings. Existing users are not changed. The Admin UI Invite User dialog sends No Default Models when you pick no models, so the default model list does not apply to people invited from the Admin UI. The Default User Settings tab of Internal Users edits the same values.
spanway_settings:
default_internal_user_params:
user_role: internal_user
max_budget: 10
budget_duration: 30d
models: ["claude-haiku-5-5"]
max_internal_user_budget: 100
internal_user_budget_duration: 30d
max_internal_user_budget is the budget a new internal_user gets when the request sends none. It is a default, not a ceiling, so an admin can still give a user more. internal_user_budget_duration is the default reset period. Every key is listed in the settings reference.
| Method | Path | Summary |
|---|---|---|
| POST | /user/new | Create an internal user |
| GET | /user/info | Get a user with their keys and teams |
| POST | /user/update | Update an internal user |
| POST | /user/bulk_update | Update several users at once |
| GET | /user/list | List internal users |
| POST | /user/delete | Delete internal users |
Add model-specific limits to keys
model_rpm_limit and model_tpm_limit set request and token limits per model on a single key. They are useful when one key may call several models but should only use a small share of an expensive one. In the Admin UI they are the Model TPM Limit and Model RPM Limit fields on a key's Settings tab.
curl -X POST http://localhost:4000/key/generate \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"models": ["claude-sonnet-5-5", "claude-haiku-5-5"],
"model_rpm_limit": {"claude-sonnet-5-5": 10, "claude-haiku-5-5": 200},
"model_tpm_limit": {"claude-sonnet-5-5": 20000}
}'
When a limit is reached the gateway returns a 429 for that model only, and the key keeps working for its other models. The limits are tracked in Redis when it is configured, so they hold across instances. Redis is required for exact limits across replicas, and while a configured Redis is unreachable the gateway returns a 503 instead of admitting requests it cannot count, see Redis requirements.
Add model-specific budgets to keys
model_max_budget gives a key a separate spend cap per model, each with its own reset period. The overall max_budget still applies on top. In the Admin UI it is Per-Model Budgets under Optional Settings on the key form, which needs a Spanway license.
curl -X POST http://localhost:4000/key/generate \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"models": ["claude-sonnet-5-5", "gpt-6.1-sol"],
"model_max_budget": {
"claude-sonnet-5-5": {"budget_limit": 5, "time_period": "1d"},
"gpt-6.1-sol": {"budget_limit": 20, "time_period": "30d"}
}
}'
Once a model's budget is used up, requests for that model fail with a budget error until the period resets, while other models stay available. /key/info shows spend per model in model_spend.
Errors
| Error | Cause | Fix |
|---|---|---|
409 User with email dev@example.com already exists or User with id user-123 already exists | A user with that user_id or user_email exists. | Look it up with /user/info and update it instead. |
403 License is over limit. Please contact https://spanway.ai/support to upgrade your license. | The license allows no more users. | Delete unused users or extend the license. |
403 User does not have permission to update this user. Only PROXY_ADMIN can update other users. | An organization admin or internal user tried to save changes to another user. | Ask a proxy admin. |
422 naming user_role | The role is not one of proxy_admin, proxy_admin_viewer, internal_user or internal_user_viewer. | Pick one of the four. |
400 No user id passed in | /user/delete was called without user_ids. | Send the ids. |
400 Invalid sort column. Must be one of: ... or Invalid sort order. Must be 'asc' or 'desc' | /user/list got an unknown sort_by or sort_order. | Use a listed column and asc or desc. |
400 DB not connected. This endpoint needs a database; set DATABASE_URL to ... | The gateway runs without a database. | Set DATABASE_URL. |
500 The gateway hit a database error and could not finish the request. The gateway log has the cause. | The database failed in a way the gateway did not expect, for example it went away while a user was being created. The answer leaves out the database host and driver text on purpose. | Read the /user/new: Exception occured line in the gateway log for the cause, then check the database. |
500 Could not create the user. The gateway log has the cause. | Creating the user failed for another reason the gateway did not expect. The answer and the log line /user/new could not create the user: <ExceptionType> name no email address or raw error on purpose. | Read the gateway log for the error type, fix the cause and send the request again. |
403 naming the role or the route | A non admin tried to create a user, or to give someone an admin role. | Use a proxy admin key, or an organization admin for users in your organization. |
403 when an organization admin creates a user | The user is not placed in one of the admin's organizations. | Pass organizations with your organization id, or use Organization in the dialog. |
404 User not found | The user_id does not exist. | Check it with /user/list. |
422 ExceededBudget: User=<id> over budget. Spend=<spend>, Budget=<budget> with type budget_exceeded | The user's spend on personal keys reached max_budget. The status is 429 when spanway_settings.budget_exceeded_status_code is 429. | Raise the budget or wait for the reset. See budget_exceeded. |
| Invitation email never arrives | No email integration is configured. | Copy the link from the Invitation Link dialog, or set up email. |
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| ERROR | /user/new: Exception occured - <error> | Creating a user failed or was refused. | None for a 4xx you expected, check the database for a 500. |
| WARNING | Failed to create audit log for user <id>: <error> | A user change was saved, but its audit row was not. | Check the database. |
| WARNING | Unable to create audit log for user on /user/new - <error> | A new user was created, but its audit row was not. | Check the database. |
| ERROR | users/bulk_delete: failed to delete users <ids>: <error> | A bulk delete failed for those users. | Retry, then check the database. |
See the log reference.
Related
- User management hierarchy for how users, teams and organizations relate.
- Self-serve onboarding for invitation links and defaults.
- Access control for what each role may change.
- Two-factor sign-in for protecting password sign-ins.
- Internal Users page for every control on the Admin UI page.