Customer Management API
This page documents the 13 gateway endpoints tagged Customer Management in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| 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 |
Endpoints
GET /customer/daily/activity/aggregated
Daily activity per customer
Spend, tokens and requests per day for each customer between start_date and end_date (YYYY-MM-DD), with a breakdown by model, provider, endpoint and key. Every day in the range is returned in one answer, so there is nothing to page. This is the query behind the customer usage view of the Admin UI. Docs (https://docs.spanway.ai/docs/proxy/spend_logs_export)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
api_key_limit | query | integer | No | How many top keys to return |
end_user_ids | query | string or null | No | |
start_date | query | string or null | No | |
end_date | query | string or null | No | |
model | query | string or null | No | |
api_key | query | string or null | No | |
exclude_end_user_ids | query | string or null | No | |
timezone | query | integer or null | No |
Example request:
curl -X GET "http://localhost:4000/customer/daily/activity/aggregated" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json SpendAnalyticsPaginatedResponse |
| 400 | The date range is invalid | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller may not read this scope | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The analytics query failed, the gateway log has the cause | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
results | array of DailySpendData | Yes | Results |
metadata | DailySpendMetadata | No |
GET /customer/daily/activity/aggregated/keys
Keys ranked by spend for a customer
One page of the virtual keys that spent the most inside the customer scope and date range, with the spend, tokens and request counts of each. offset and limit page through the list and total_api_keys says how many keys there are in all. Docs (https://docs.spanway.ai/docs/proxy/spend_logs_export)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
offset | query | integer | No | How many rows to skip, for paging |
limit | query | integer | No | How many rows to return |
end_user_ids | query | string or null | No | |
start_date | query | string or null | No | |
end_date | query | string or null | No | |
model | query | string or null | No | |
api_key | query | string or null | No | |
exclude_end_user_ids | query | string or null | No | |
timezone | query | integer or null | No |
Example request:
curl -X GET "http://localhost:4000/customer/daily/activity/aggregated/keys" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json DailyActivityKeyPageResponse |
| 400 | The date range is invalid | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller may not read this scope | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The analytics query failed, the gateway log has the cause | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
api_keys | array of KeySpendActivityRow | Yes | Api Keys |
total_api_keys | integer | Yes | Total Api Keys |
offset | integer | Yes | Offset |
limit | integer | Yes | Limit |
GET /customer/daily/activity/aggregated/search
Search the keys with activity for a customer
Find virtual keys with activity inside the customer scope and date range whose alias, hash, user id or email matches the search text, each with its spend, tokens and request counts. This is the key search box of the Usage page. Docs (https://docs.spanway.ai/docs/proxy/spend_logs_export)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
search | query | string | Yes | Text to find in key aliases and key hashes |
limit | query | integer | No | How many rows to return |
end_user_ids | query | string or null | No | |
start_date | query | string or null | No | |
end_date | query | string or null | No | |
model | query | string or null | No | |
api_key | query | string or null | No | |
exclude_end_user_ids | query | string or null | No | |
timezone | query | integer or null | No |
Example request:
curl -X GET "http://localhost:4000/customer/daily/activity/aggregated/search?search=string" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json DailyActivityKeySearchResponse |
| 400 | The date range is invalid | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller may not read this scope | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The analytics query failed, the gateway log has the cause | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
api_keys | array of KeyActivityRow | Yes | Api Keys |
GET /customer/daily/activity/aggregated/model_top_keys
Top keys for one model in a customer
The virtual keys that spent the most on one model inside the customer scope and date range. by_model_group tells whether model was matched as the public model group or as the individual deployment. Docs (https://docs.spanway.ai/docs/proxy/spend_logs_export)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model_group | query | string | Yes | The model or model group to rank keys for |
by_model_group | query | boolean | No | Match model_group as a model group, not a model |
limit | query | integer | No | How many rows to return |
end_user_ids | query | string or null | No | |
start_date | query | string or null | No | |
end_date | query | string or null | No | |
model | query | string or null | No | |
api_key | query | string or null | No | |
exclude_end_user_ids | query | string or null | No | |
timezone | query | integer or null | No |
Example request:
curl -X GET "http://localhost:4000/customer/daily/activity/aggregated/model_top_keys?model_group=claude-sonnet-5-5" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json ModelTopKeysResponse |
| 400 | The date range is invalid | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller may not read this scope | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The analytics query failed, the gateway log has the cause | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
by_model_group | boolean | Yes | By Model Group |
api_keys | array of KeySpendActivityRow | Yes | Api Keys |
GET /customer/daily/activity/export
Download customer daily activity as CSV or JSON
Stream one row per day for each customer in the range, with requests, tokens and spend. export_type picks the breakdown: daily, daily_with_keys, daily_with_models or daily_with_users. format is csv (the default) or json. The file name carries the entity, the range and the breakdown. This is the Export Data dialog of the Usage page. Docs (https://docs.spanway.ai/docs/proxy/spend_logs_export)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
export_type | query | ExportType | No | The breakdown of each row |
format | query | enum: "csv", "json" | No | csv or json |
end_user_ids | query | string or null | No | |
start_date | query | string or null | No | |
end_date | query | string or null | No | |
model | query | string or null | No | |
api_key | query | string or null | No | |
exclude_end_user_ids | query | string or null | No | |
timezone | query | integer or null | No |
Example request:
curl -X GET "http://localhost:4000/customer/daily/activity/export" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Streamed daily activity export | text/csv string |
| 400 | Bad Request | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller may not read this scope | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The analytics query failed, the gateway log has the cause | application/json ErrorDetail |
POST /customer/block
Block customers
Blocks one or more customers, so every model request that names them in the user field is refused until
they are unblocked. A customer that does not exist yet is created already blocked. Only proxy admins may call
it, and each blocked customer writes an audit row.
Docs (https://docs.spanway.ai/docs/proxy/customers)
Request body (application/json, schema BlockUsers):
| Field | Type | Required | Description |
|---|---|---|---|
user_ids | array of string | Yes | User Ids |
Example request:
curl -X POST "http://localhost:4000/customer/block" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_ids": [
"acct-48213"
]
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json BlockUsersResponse |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database is not connected or the write failed | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
blocked_users | array of Spanway_EndUserTable | Yes | Blocked Users |
POST /customer/unblock
Unblock customers
Lifts the block on one or more customers so their requests are served again. The answer lists the ids that stay blocked because the proxy configuration file blocks them, which only a change to that file can lift. Only proxy admins may call it, and each customer it unblocks writes an audit row.
Docs (https://docs.spanway.ai/docs/proxy/customers)
Request body (application/json, schema BlockUsers):
| Field | Type | Required | Description |
|---|---|---|---|
user_ids | array of string | Yes | User Ids |
Example request:
curl -X POST "http://localhost:4000/customer/unblock" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_ids": [
"acct-48213"
]
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json UnblockUsersResponse |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | No database is connected and no block list is configured | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
blocked_users | array of string | Yes | User IDs that remain blocked after this unblock call |
POST /customer/new
Create a customer
Creates a customer, which is an end user of your application that you name in the user field of a model
request, so you can give that person or account its own budget, rate limits, allowed models and region. Only
proxy admins may call it, and it writes an audit row.
Give either max_budget (a new budget is created for the customer) or budget_id (an existing budget is
attached), not both. budget_duration such as 30d resets the spend on that schedule.
allowed_model_region keeps every request of the customer on models in that region. default_model is stored
for reference only and must name a model on the gateway, routing does not use it. object_permission limits which MCP servers, vector stores and
agents the customer may use, and an empty value leaves them unrestricted. The older path /end_user/new
still works.
Docs (https://docs.spanway.ai/docs/proxy/customers)
Request body (application/json, schema NewCustomerRequest):
| Field | Type | Required | Description |
|---|---|---|---|
budget_id | string or null | No | Budget Id |
max_budget | number or null | No | Requests will fail if this budget (in USD) is exceeded. |
soft_budget | number or null | No | Stored for compatibility, but the gateway does not act on it for customers. |
max_parallel_requests | integer or null | No | Max concurrent requests allowed for this budget id. |
tpm_limit | integer or null | No | Max tokens per minute, allowed for this budget id. |
rpm_limit | integer or null | No | Max requests per minute, allowed for this budget id. |
tpd_limit | integer or null | No | Max tokens per day, charged by batch submissions, allowed for this budget id. |
budget_duration | string or null | No | How often spend resets to zero, for example '1h', '1d', '7d', '30d' or '1mo' |
model_max_budget | object or null | No | Max budget for each model (e.g. {'gpt-4o': {'max_budget': '0.0000001', 'budget_duration': '1d', 'tpm_limit': 1000, 'rpm_limit': 1000}}) |
budget_reset_at | string or null | No | Datetime when the budget is reset |
user_id | string | Yes | User Id |
alias | string or null | No | Alias |
blocked | boolean | No | Blocked |
spend | number or null | No | Spend |
allowed_model_region | enum: "eu", "uk", "ch", "us", "ca", "apac" or null | No | Allowed Model Region |
default_model | string or null | No | Default Model |
models | array of string or null | No | Models |
object_permission | Spanway_ObjectPermissionBase or null | No |
Example request:
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": "Pilot workspace",
"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"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json CustomerResponse |
| 400 | Customer already exists, passed user_id=acct-48213. Please pass a new user_id. | application/json ProxyError |
| 401 | Authentication Error, No api key passed in. | application/json ProxyError |
| 403 | user not allowed to access this route, role= proxy_admin_viewer. Trying to access: /customer/new | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys or Could not create the customer's budget. The gateway log has the cause. or Could not create the customer. The gateway log has the cause. | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | User Id |
blocked | boolean | Yes | Blocked |
alias | string or null | No | Alias |
spend | number | No | Spend |
allowed_model_region | enum: "eu", "us" or null | No | Allowed Model Region |
default_model | string or null | No | Default Model |
models | array of string | No | Models |
budget_id | string or null | No | Budget Id |
spanway_budget_table | Spanway_BudgetTableFull or null | No | |
object_permission_id | string or null | No | Object Permission Id |
object_permission | Spanway_ObjectPermissionTable or null | No | |
organization_id | string or null | No | Organization Id |
GET /customer/info
Get a customer with their spend
Shows one customer with its budget, spend so far, allowed models and region. Proxy admins and admin viewers may call it, and it changes nothing. It answers 404 when no customer has that id.
Docs (https://docs.spanway.ai/docs/proxy/customers)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
end_user_id | query | string | Yes | End User ID in the request parameters |
Example request:
curl -X GET "http://localhost:4000/customer/info?end_user_id=end_user_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json CustomerResponse |
| 401 | Authentication Error, No api key passed in. | application/json ProxyError |
| 403 | user not allowed to access this route, role= internal_user. Trying to access: /customer/info | application/json ProxyError |
| 404 | End User Id=acct-48213 does not exist in db | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | User Id |
blocked | boolean | Yes | Blocked |
alias | string or null | No | Alias |
spend | number | No | Spend |
allowed_model_region | enum: "eu", "us" or null | No | Allowed Model Region |
default_model | string or null | No | Default Model |
models | array of string | No | Models |
budget_id | string or null | No | Budget Id |
spanway_budget_table | Spanway_BudgetTableFull or null | No | |
object_permission_id | string or null | No | Object Permission Id |
object_permission | Spanway_ObjectPermissionTable or null | No | |
organization_id | string or null | No | Organization Id |
POST /customer/update
Update a customer
Changes a customer's name, block flag, budget, region or allowed models. Fields you leave out keep their
stored value, models set to an empty list clears the list, and budget fields update the customer's budget
or create one when it has none. Only proxy admins may call it, and it writes an audit row with the values
before and after.
Docs (https://docs.spanway.ai/docs/proxy/customers)
Request body (application/json, schema UpdateCustomerRequest):
| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | User Id |
alias | string or null | No | Alias |
blocked | boolean | No | Blocked |
max_budget | number or null | No | Max Budget |
budget_id | string or null | No | Budget Id |
allowed_model_region | enum: "eu", "uk", "ch", "us", "ca", "apac" or null | No | Allowed Model Region |
default_model | string or null | No | Default Model |
models | array of string or null | No | Models |
object_permission | Spanway_ObjectPermissionBase or null | No |
Example request:
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
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json CustomerResponse |
| 400 | Set either 'max_budget' or 'budget_id', not both. | application/json ProxyError |
| 401 | Authentication Error, No api key passed in. | application/json ProxyError |
| 403 | user not allowed to access this route, role= proxy_admin_viewer. Trying to access: /customer/update | application/json ProxyError |
| 404 | End User Id=acct-48213 does not exist in db | application/json ProxyError |
| 422 | default_model names a model the gateway does not serve | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys or Could not save the customer's budget. The gateway log has the cause. or Could not update the customer. The gateway log has the cause. | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | User Id |
blocked | boolean | Yes | Blocked |
alias | string or null | No | Alias |
spend | number | No | Spend |
allowed_model_region | enum: "eu", "us" or null | No | Allowed Model Region |
default_model | string or null | No | Default Model |
models | array of string | No | Models |
budget_id | string or null | No | Budget Id |
spanway_budget_table | Spanway_BudgetTableFull or null | No | |
object_permission_id | string or null | No | Object Permission Id |
object_permission | Spanway_ObjectPermissionTable or null | No | |
organization_id | string or null | No | Organization Id |
POST /customer/delete
Delete customers
Deletes one or more customers for good. When any of the ids does not exist nothing is deleted and the answer is 404 naming the missing ids. Only proxy admins may call it, and each deleted customer writes an audit row with its last stored values.
Docs (https://docs.spanway.ai/docs/proxy/customers)
Request body (application/json, schema DeleteCustomerRequest):
| Field | Type | Required | Description |
|---|---|---|---|
user_ids | array of string | Yes | User Ids |
Example request:
curl -X POST "http://localhost:4000/customer/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_ids": [
"acct-48213"
]
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json DeleteCustomersResponse |
| 400 | user_ids is required and must not be empty | application/json ProxyError |
| 401 | Authentication Error, No api key passed in. | application/json ProxyError |
| 403 | user not allowed to access this route, role= proxy_admin_viewer. Trying to access: /customer/delete | application/json ProxyError |
| 404 | End User Id(s)=acct-48213 do not exist in db | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys or Could not delete the customers. The gateway log has the cause. | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
deleted_customers | integer | Yes | Deleted Customers |
message | string | Yes | Message |
GET /customer/list
List customers
Lists every customer with its budget, spend and allowed models. Proxy admins and admin viewers may call it, and it changes nothing. Any other role gets 403.
Docs (https://docs.spanway.ai/docs/proxy/customers)
Example request:
curl -X GET "http://localhost:4000/customer/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json array of CustomerResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key is not a proxy admin or admin viewer | application/json ErrorDetail |
| 500 | The database is not connected | application/json ErrorDetail |
GET /customer/daily/activity
Daily spend and usage of customers
Shows spend, tokens and request counts per day for customers, for the usage charts in the Admin UI. Narrow it
with end_user_ids or exclude_end_user_ids (comma separated), start_date and end_date (YYYY-MM-DD),
model and api_key, and page through it with page and page_size. Proxy admins and admin viewers may
call it, and it changes nothing.
Docs (https://docs.spanway.ai/docs/proxy/customers)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
end_user_ids | query | string or null | No | |
start_date | query | string or null | No | |
end_date | query | string or null | No | |
model | query | string or null | No | |
api_key | query | string or null | No | |
page | query | integer | No | |
page_size | query | integer | No | |
exclude_end_user_ids | query | string or null | No |
Example request:
curl -X GET "http://localhost:4000/customer/daily/activity" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json SpendAnalyticsPaginatedResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key is not a proxy admin or admin viewer | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
results | array of DailySpendData | Yes | Results |
metadata | DailySpendMetadata | No |