Customers and end users
A customer, also called an end user, is a person outside your organisation whose requests your application sends through the gateway. Customers are not gateway users, they have no sign-in and no keys. They are identified per request, spend is attributed to them, and they can be given budgets, model allow-lists, a required region and a block, all independently of the key the application uses. Customers need no license. The audit rows they write are part of Spanway Enterprise, see Audit.
When you would use this
Your application offers a free trial. Each trial account gets 20 dollars of model usage a month, may only use the two cheap models, and because the account is in Europe its requests must stay on deployments in the EU. You create the customer with those limits before the first request, your application sends the account id in the user field, and the gateway enforces the budget, the model list and the region on every call. When the trial turns abusive you block the customer and nothing else changes.
Before you start
Your application has to send a customer id with each request, in the user field of the body or in the x-spanway-customer-id or x-spanway-end-user-id header. general_settings.user_header_mappings can name another header. Customers are also created on first sight when the gateway needs to track their spend.
Step by step
-
Create the customer with its limits. In the Admin UI open Customers, click + Create Customer, fill in Customer ID, Alias, Max Budget (USD) and Budget Reset, pick the Allowed Model Region, a Default Model and the Allowed Models, and click Create Customer. Over the API call
POST /customer/new.curl -X POST http://localhost:4000/customer/new \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"user_id": "acct-48213","alias": "Northwind trial","max_budget": 20,"budget_duration": "30d","models": ["claude-haiku-5-5", "claude-sonnet-5-5"],"allowed_model_region": "eu","default_model": "claude-haiku-5-5"}'{"user_id": "acct-48213","alias": "Northwind trial","blocked": false,"spend": 2.75,"allowed_model_region": "eu","default_model": "claude-haiku-5-5","models": ["claude-haiku-5-5", "claude-sonnet-5-5"],"budget_id": "budget-9c21","spanway_budget_table": {"budget_id": "budget-9c21", "max_budget": 20.0, "budget_duration": "30d"}} -
Send the customer id with each request.
curl -X POST http://localhost:4000/v1/chat/completions \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"model": "claude-haiku-5-5", "user": "acct-48213", "messages": [{"role": "user", "content": "Hello"}]}' -
Check the customer's spend. The Customers table shows Spend / Budget, Region and Allowed Models per customer. Over the API call
GET /customer/info, orGET /customer/listfor everyone.curl "http://localhost:4000/customer/info?end_user_id=acct-48213" -H "Authorization: Bearer $SPANWAY_API_KEY" -
Change the limits. Open the row menu, click Edit, change Max Budget (USD), the region or the models, and click Save Customer. Over the API call
POST /customer/update.curl -X POST http://localhost:4000/customer/update \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"user_id": "acct-48213", "max_budget": 50, "blocked": false}' -
Block, unblock or delete. In the row menu click Block and confirm Block customer?, Unblock to let the requests through again, or Delete to remove the customer record while its spend logs stay. Over the API call
POST /customer/block,POST /customer/unblockandPOST /customer/delete.curl -X POST http://localhost:4000/customer/block \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"user_ids": ["acct-48213"]}' -
Report per customer. The Usage page breaks spend down by customer, and the enterprise spend reports group by customer for chargeback, see enterprise spend tracking. Over the API the daily activity routes return spend and usage per customer per day, by key and by model, and
GET /customer/daily/activity/exportdownloads them.curl "http://localhost:4000/customer/daily/activity?start_date=2026-11-01&end_date=2026-11-21&end_user_ids=acct-48213" \-H "Authorization: Bearer $SPANWAY_API_KEY"
What you should see
The customer appears on Customers with an Active badge and its spend meter. A request with "user": "acct-48213" for claude-haiku-5-5 is served by an EU deployment, a request for a model outside the allow-list is refused with a 403, and a request for a model with no EU deployment fails with a 400. When the customer's spend reaches max_budget, their next request gets a budget exceeded error while the key keeps working for everyone else. A blocked customer's model requests are refused at once with a 403 and the customer_blocked code, on every gateway and with no extra setting, and GET /customer/info shows the running spend.
Fields
| Field | Meaning |
|---|---|
user_id | The customer id your application sends. |
alias | Human readable name. |
max_budget, budget_duration or budget_id | A budget of their own, reset every budget_duration, or a shared budget by id. One of max_budget and budget_id, not both, on create and on update. On create, when budget_id comes with another budget field such as budget_duration or a rate limit, budget_id is ignored and a new budget is created from those fields. On update, those fields change the customer's current budget, or create one when the customer has none. On update max_budget: 0 is ignored, so send a small positive amount to stop spend. |
soft_budget | Create only. Accepted for compatibility, but the gateway sends no alert and does nothing else with it for customers. |
budget_reset_at | Create only. When the first reset happens. Left out, it is one budget_duration after creation. |
rpm_limit, tpm_limit | Create only. Requests and tokens per minute across every key that sends this customer id. |
tpd_limit | Create only. Tokens per day for batch submissions, which are charged against it instead of the per minute limits. |
max_parallel_requests | Create only. Concurrent requests allowed for the customer's budget. |
model_max_budget | Create only. Spend cap per model, each with its own max_budget and budget_duration. |
spend | Create only. Starting spend, for example when you move a customer from another system. Left out, it is 0. |
models | Models this customer may call. Omitting it on update keeps the list, an empty list clears it. |
allowed_model_region | eu, uk, ch, us, ca or apac. Requests may only use deployments in that region, worked out as Regions describes, so eu-west-1 counts as eu. A deployment with no region never qualifies, and a request fails with a 400 when no deployment of the model qualifies. |
default_model | Stored with the customer for your reference. It must name a model on the gateway, but routing does not use it, so it never replaces the requested model. |
blocked | Refuse every model request from this customer. Usually set with /customer/block instead. |
metadata | Free form, for example a data training opt out flag. |
object_permission | MCP servers, access groups, tool permissions, vector stores and agents the customer may use. |
The fields marked create only are set when the customer is created. To change them later, edit the customer's budget on the Budgets page or with /budget/update.
A customer without a budget of their own can still be limited. The gateway uses the first budget it finds, in this order: the customer's own budget, then the key's Default Customer Budget (key metadata end_user_budget_id, see Budgets), then the gateway wide spanway_settings.max_end_user_budget_id. A key's end_user_max_budget also caps every customer that key sends. The older spanway_settings.max_end_user_budget setting is not applied, so point max_end_user_budget_id at a shared budget instead. The same routes are available with the /end_user/ prefix.
| Method | Path | Summary |
|---|---|---|
| GET | /customer/daily/activity/aggregated | Daily activity per customer |
| GET | /customer/daily/activity/aggregated/keys | Keys ranked by spend for a customer |
| GET | /customer/daily/activity/aggregated/search | Search the keys with activity for a customer |
| GET | /customer/daily/activity/aggregated/model_top_keys | Top keys for one model in a customer |
| GET | /customer/daily/activity/export | Download customer daily activity as CSV or JSON |
| POST | /customer/block | Block customers |
| POST | /customer/unblock | Unblock customers |
| POST | /customer/new | Create a customer |
| GET | /customer/info | Get a customer with their spend |
| POST | /customer/update | Update a customer |
| POST | /customer/delete | Delete customers |
| GET | /customer/list | List customers |
| GET | /customer/daily/activity | Daily spend and usage of customers |
Admin UI
The Customers page (/ui/?page=customers) lists every customer with their status, region, spend and allowed models, and lets a proxy admin create, edit, block, unblock or delete them. Admin viewers see the list read only.
A typical case is a trial account that may spend 20 USD a month across at most 60 requests a minute, and may only reach the documentation MCP server. To set that up:
- Open Customers in the left navigation and click + Create Customer.
- Enter the Customer ID your application sends in the
userfield, and an Alias if you want a readable name. - Leave Budget on Budget set on this customer to give the customer a budget of their own, or pick a budget created on the Budgets page to share it. Picking a shared budget hides the inline budget fields, because the gateway accepts one or the other.
- For an own budget, fill Max Budget (USD), choose how often it resets under Budget Reset and, if the first reset should land on a particular date, set First Reset At. Leaving Max Budget (USD) blank means no cap.
- Set Requests per Minute, Tokens per Minute, Tokens per Day (batch) and Max Parallel Requests as needed. Blank means no gateway limit.
- Add Per-Model Budgets to cap spend on a single model over its own window.
- Choose an Allowed Model Region and the comma separated Allowed Models, optionally note a Default Model for your records, then restrict MCP Servers / Access Groups and Vector Stores if the customer should not reach all of them.
- Click Create Customer. The dialog closes and the new row appears in the list.
The same request with curl:
curl -X POST http://localhost:4000/customer/new -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{
"user_id": "acct-48213",
"alias": "Northwind trial",
"max_budget": 20,
"budget_duration": "30d",
"rpm_limit": 60,
"tpm_limit": 100000,
"object_permission": {"mcp_servers": ["docs-mcp"]}
}'
Editing a customer changes its alias, region, models and MCP or vector store grants, or moves it onto another budget. The dialog opens on the budget the customer is linked to, so saving never changes that budget. To change the amount, rate limits, reset schedule or per-model budgets of a linked budget, edit it on the Budgets page, where the change applies to every customer that uses it. Over the API /customer/update with max_budget changes the budget the customer is linked to, and every customer sharing that budget sees the new amount.
The Usage page breaks spend down by customer, and the enterprise spend reports group by customer for chargeback, see enterprise spend tracking. Budgets shared between customers are managed under Budgets.
Customers on Spanway Cloud
On a gateway with cloud.enabled, each tenant's customers are kept apart. The gateway prefixes the customer id it receives with the organization id of the calling key, so alice sent by one tenant is stored, budgeted, blocked and logged as <organization_id>/alice and never shares a row, spend or budget with another tenant's alice. A new customer row also records the tenant in its organization_id column. Proxy admin keys are not prefixed and see the stored ids as they are, so a proxy admin who creates or blocks a tenant's customer with /customer/new or /customer/block sends the full id, <organization_id>/alice. An id sent without the prefix never matches that tenant's requests. A data subject export or erasure of an end user by a tenant's caller acts only on that tenant's customer, and a Cloud caller outside any organization cannot export or erase end users. Rows written before this change keep their ids.
Errors
| Error | Cause | Fix |
|---|---|---|
422 ExceededBudget: End User=acct-48213 over budget. Spend=20.4, Budget=20.0, type budget_exceeded | The customer's spend reached max_budget. The status is 429 when spanway_settings.budget_exceeded_status_code is 429. See budget exceeded. | Raise the budget on the Budgets page or with /customer/update, or wait for the reset. |
400 naming the allowed regions | allowed_model_region is set and no deployment of the model is in that region. | Add a deployment in the region, or widen the region. |
403 The requested model 'gpt-4o' is not in the allowed models for this customer., type customer_model_access_denied | The model is not in the customer's models. | Add it, or send an empty list to allow every model. |
403 Customer=acct-48213 is blocked. An admin can lift it with /customer/unblock., type customer_blocked | The customer is blocked in the database. | Unblock with /customer/unblock or the Unblock menu item. |
400 User blocked from making LLM API Calls. User=acct-48213 | The id is in spanway_settings.blocked_user_list and the blocked_user_check callback is on. | Remove the id from that list in the config file and reload. /customer/unblock reports such ids as still blocked. |
400 Customer already exists, passed user_id=acct-48213. Please pass a new user_id. | A customer with that user_id exists. | Update it with /customer/update instead. |
404 End User Id=acct-48213 does not exist in db | The user_id does not exist. /customer/update also answers this when someone deleted the customer while the update was running. | Check GET /customer/list. |
403 Admin-only endpoint. Your user role=internal_user | The caller is not a proxy admin or admin viewer, on list and the daily activity routes. Other customer routes answer 403 user not allowed to access this route. | Use an admin key. |
422 Value error, Set either 'max_budget' or 'budget_id', not both. on create, 400 with the same text on update | The body sends both. | Send one of them. |
422 Default model claude-x is not on this gateway. Add it with /model/new or config.yaml first. | default_model names a model the gateway does not serve. | Add the model first or leave the field out. |
400 user_ids is required and must not be empty | /customer/delete got an empty list. | Send at least one id. |
500 DB not connected. This endpoint needs a database ... | The gateway has no database. | Set DATABASE_URL. |
500 Failed to fetch analytics. The gateway log has the cause. | A daily activity query failed. | Read the Daily activity error line in the gateway log. |
500 Could not create the customer's budget. The gateway log has the cause. | /customer/new sent max_budget or other budget fields and saving the budget failed, usually because the database is down. No customer was created. | Read the Could not create the customer budget log line, then retry. |
500 Could not block the customers. The gateway log has the cause. | /customer/block failed while saving. | Read the Could not block customers log line, then retry. |
500 Could not save the customer's budget. The gateway log has the cause. | /customer/update sent max_budget or other budget fields and creating or changing the budget failed. The customer row was not updated. | Read the Could not save the customer budget log line, then retry. |
500 Could not create the customer. The gateway log has the cause., Could not update the customer. ... or Could not delete the customers. ... | /customer/new, /customer/update or /customer/delete failed for a reason the gateway did not expect, usually because the database is down. The database error is never sent back, because it can carry the database host or customer values. | Read the matching Could not ... log line, then retry. |
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| ERROR | Could not block customers: <error type> | /customer/block failed, usually because the database is down. Only the error type is logged, so customer ids stay out of the log. | Check the database connection and retry. |
| ERROR | Could not create the customer budget: <error type> | /customer/new could not save the customer's budget. | Check the database connection and retry. |
| ERROR | Could not save the customer budget: <error type> | /customer/update could not create or change the customer's budget. | Check the database connection and retry. |
| ERROR | Could not create the customer: <error type>, Could not update the customer: <error type> or Could not delete the customers: <error type> | The route failed for a reason the gateway did not expect. Only the error type is logged, so customer ids and database messages stay out of the log. | Check the database connection and retry. |
| WARNING | object_permission still in new_end_user_obj after _set_object_permission | The MCP or vector store grants could not be stored separately. The customer is created without them. | Send object_permission again with /customer/update. |
| ERROR | Daily activity aggregation failed: <reason> | A usage chart query failed and the caller got the analytics 500. | Read the reason, usually the database. |
| ERROR | Daily activity key page failed: <reason>, Daily activity key search failed: <reason>, Daily activity model top keys failed: <reason> or Daily activity export failed: <reason> | The key list, key search, top keys chart or export of the customer usage view failed and the caller got the analytics 500. | Read the reason, usually the database. |
| ERROR | ...customer_endpoints.end_user_info(): Exception occured - <reason> or ...list_end_user(): Exception occured - <reason> | A customer read or list call failed. | Read the reason, usually the database, then retry. |
| WARNING | object_permission still in update_end_user_table_data | On update, the MCP or vector store grants could not be stored separately. The customer is saved without the new grants. | Send object_permission again. |
Audit
With Spanway Enterprise each change writes an audit row on Spanway_EndUserTable: created for /customer/new and for a block that creates a new customer, updated for /customer/update, blocked and unblocked with the value before and after, and deleted with the last stored values. A budget created or changed through the customer routes also writes a created or updated row on Spanway_BudgetTable. Find them under Audit Logs, see Audit logs.
Related
- Calling the gateway for the
userfield in SDK calls. - Shared budgets and the Budgets page for
budget_id. - Data policy routing for regions.
- Cost tracking for how customer spend is recorded.
- Customers page for every control on the Admin UI page.
- Settings reference for
max_end_user_budget_id,blocked_user_list,enforce_user_paramandbudget_exceeded_status_code.