Skip to main content

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.

MethodPathSummary
GET/customer/daily/activity/aggregatedDaily activity per customer
GET/customer/daily/activity/aggregated/keysKeys ranked by spend for a customer
GET/customer/daily/activity/aggregated/searchSearch the keys with activity for a customer
GET/customer/daily/activity/aggregated/model_top_keysTop keys for one model in a customer
GET/customer/daily/activity/exportDownload customer daily activity as CSV or JSON
POST/customer/blockBlock customers
POST/customer/unblockUnblock customers
POST/customer/newCreate a customer
GET/customer/infoGet a customer with their spend
POST/customer/updateUpdate a customer
POST/customer/deleteDelete customers
GET/customer/listList customers
GET/customer/daily/activityDaily 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:

NameInTypeRequiredDescription
api_key_limitqueryintegerNoHow many top keys to return
end_user_idsquerystring or nullNo
start_datequerystring or nullNo
end_datequerystring or nullNo
modelquerystring or nullNo
api_keyquerystring or nullNo
exclude_end_user_idsquerystring or nullNo
timezonequeryinteger or nullNo

Example request:

curl -X GET "http://localhost:4000/customer/daily/activity/aggregated" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json SpendAnalyticsPaginatedResponse
400The date range is invalidapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read this scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The analytics query failed, the gateway log has the causeapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
resultsarray of DailySpendDataYesResults
metadataDailySpendMetadataNo

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:

NameInTypeRequiredDescription
offsetqueryintegerNoHow many rows to skip, for paging
limitqueryintegerNoHow many rows to return
end_user_idsquerystring or nullNo
start_datequerystring or nullNo
end_datequerystring or nullNo
modelquerystring or nullNo
api_keyquerystring or nullNo
exclude_end_user_idsquerystring or nullNo
timezonequeryinteger or nullNo

Example request:

curl -X GET "http://localhost:4000/customer/daily/activity/aggregated/keys" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json DailyActivityKeyPageResponse
400The date range is invalidapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read this scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The analytics query failed, the gateway log has the causeapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
api_keysarray of KeySpendActivityRowYesApi Keys
total_api_keysintegerYesTotal Api Keys
offsetintegerYesOffset
limitintegerYesLimit

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:

NameInTypeRequiredDescription
searchquerystringYesText to find in key aliases and key hashes
limitqueryintegerNoHow many rows to return
end_user_idsquerystring or nullNo
start_datequerystring or nullNo
end_datequerystring or nullNo
modelquerystring or nullNo
api_keyquerystring or nullNo
exclude_end_user_idsquerystring or nullNo
timezonequeryinteger or nullNo

Example request:

curl -X GET "http://localhost:4000/customer/daily/activity/aggregated/search?search=string" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json DailyActivityKeySearchResponse
400The date range is invalidapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read this scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The analytics query failed, the gateway log has the causeapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
api_keysarray of KeyActivityRowYesApi 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:

NameInTypeRequiredDescription
model_groupquerystringYesThe model or model group to rank keys for
by_model_groupquerybooleanNoMatch model_group as a model group, not a model
limitqueryintegerNoHow many rows to return
end_user_idsquerystring or nullNo
start_datequerystring or nullNo
end_datequerystring or nullNo
modelquerystring or nullNo
api_keyquerystring or nullNo
exclude_end_user_idsquerystring or nullNo
timezonequeryinteger or nullNo

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:

StatusDescriptionBody
200Successful Responseapplication/json ModelTopKeysResponse
400The date range is invalidapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read this scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The analytics query failed, the gateway log has the causeapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
modelstringYesModel
by_model_groupbooleanYesBy Model Group
api_keysarray of KeySpendActivityRowYesApi 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:

NameInTypeRequiredDescription
export_typequeryExportTypeNoThe breakdown of each row
formatqueryenum: "csv", "json"Nocsv or json
end_user_idsquerystring or nullNo
start_datequerystring or nullNo
end_datequerystring or nullNo
modelquerystring or nullNo
api_keyquerystring or nullNo
exclude_end_user_idsquerystring or nullNo
timezonequeryinteger or nullNo

Example request:

curl -X GET "http://localhost:4000/customer/daily/activity/export" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Streamed daily activity exporttext/csv string
400Bad Requestapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller may not read this scopeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The analytics query failed, the gateway log has the causeapplication/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):

FieldTypeRequiredDescription
user_idsarray of stringYesUser 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:

StatusDescriptionBody
200Successful Responseapplication/json BlockUsersResponse
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database is not connected or the write failedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
blocked_usersarray of Spanway_EndUserTableYesBlocked 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):

FieldTypeRequiredDescription
user_idsarray of stringYesUser 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:

StatusDescriptionBody
200Successful Responseapplication/json UnblockUsersResponse
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500No database is connected and no block list is configuredapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
blocked_usersarray of stringYesUser 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):

FieldTypeRequiredDescription
budget_idstring or nullNoBudget Id
max_budgetnumber or nullNoRequests will fail if this budget (in USD) is exceeded.
soft_budgetnumber or nullNoStored for compatibility, but the gateway does not act on it for customers.
max_parallel_requestsinteger or nullNoMax concurrent requests allowed for this budget id.
tpm_limitinteger or nullNoMax tokens per minute, allowed for this budget id.
rpm_limitinteger or nullNoMax requests per minute, allowed for this budget id.
tpd_limitinteger or nullNoMax tokens per day, charged by batch submissions, allowed for this budget id.
budget_durationstring or nullNoHow often spend resets to zero, for example '1h', '1d', '7d', '30d' or '1mo'
model_max_budgetobject or nullNoMax budget for each model (e.g. {'gpt-4o': {'max_budget': '0.0000001', 'budget_duration': '1d', 'tpm_limit': 1000, 'rpm_limit': 1000}})
budget_reset_atstring or nullNoDatetime when the budget is reset
user_idstringYesUser Id
aliasstring or nullNoAlias
blockedbooleanNoBlocked
spendnumber or nullNoSpend
allowed_model_regionenum: "eu", "uk", "ch", "us", "ca", "apac" or nullNoAllowed Model Region
default_modelstring or nullNoDefault Model
modelsarray of string or nullNoModels
object_permissionSpanway_ObjectPermissionBase or nullNo

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:

StatusDescriptionBody
200Successful Responseapplication/json CustomerResponse
400Customer already exists, passed user_id=acct-48213. Please pass a new user_id.application/json ProxyError
401Authentication Error, No api key passed in.application/json ProxyError
403user not allowed to access this route, role= proxy_admin_viewer. Trying to access: /customer/newapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500DB 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):

FieldTypeRequiredDescription
user_idstringYesUser Id
blockedbooleanYesBlocked
aliasstring or nullNoAlias
spendnumberNoSpend
allowed_model_regionenum: "eu", "us" or nullNoAllowed Model Region
default_modelstring or nullNoDefault Model
modelsarray of stringNoModels
budget_idstring or nullNoBudget Id
spanway_budget_tableSpanway_BudgetTableFull or nullNo
object_permission_idstring or nullNoObject Permission Id
object_permissionSpanway_ObjectPermissionTable or nullNo
organization_idstring or nullNoOrganization 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:

NameInTypeRequiredDescription
end_user_idquerystringYesEnd 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:

StatusDescriptionBody
200Successful Responseapplication/json CustomerResponse
401Authentication Error, No api key passed in.application/json ProxyError
403user not allowed to access this route, role= internal_user. Trying to access: /customer/infoapplication/json ProxyError
404End User Id=acct-48213 does not exist in dbapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500DB 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_keysapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
user_idstringYesUser Id
blockedbooleanYesBlocked
aliasstring or nullNoAlias
spendnumberNoSpend
allowed_model_regionenum: "eu", "us" or nullNoAllowed Model Region
default_modelstring or nullNoDefault Model
modelsarray of stringNoModels
budget_idstring or nullNoBudget Id
spanway_budget_tableSpanway_BudgetTableFull or nullNo
object_permission_idstring or nullNoObject Permission Id
object_permissionSpanway_ObjectPermissionTable or nullNo
organization_idstring or nullNoOrganization 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):

FieldTypeRequiredDescription
user_idstringYesUser Id
aliasstring or nullNoAlias
blockedbooleanNoBlocked
max_budgetnumber or nullNoMax Budget
budget_idstring or nullNoBudget Id
allowed_model_regionenum: "eu", "uk", "ch", "us", "ca", "apac" or nullNoAllowed Model Region
default_modelstring or nullNoDefault Model
modelsarray of string or nullNoModels
object_permissionSpanway_ObjectPermissionBase or nullNo

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:

StatusDescriptionBody
200Successful Responseapplication/json CustomerResponse
400Set either 'max_budget' or 'budget_id', not both.application/json ProxyError
401Authentication Error, No api key passed in.application/json ProxyError
403user not allowed to access this route, role= proxy_admin_viewer. Trying to access: /customer/updateapplication/json ProxyError
404End User Id=acct-48213 does not exist in dbapplication/json ProxyError
422default_model names a model the gateway does not serveapplication/json HTTPValidationError
500DB 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):

FieldTypeRequiredDescription
user_idstringYesUser Id
blockedbooleanYesBlocked
aliasstring or nullNoAlias
spendnumberNoSpend
allowed_model_regionenum: "eu", "us" or nullNoAllowed Model Region
default_modelstring or nullNoDefault Model
modelsarray of stringNoModels
budget_idstring or nullNoBudget Id
spanway_budget_tableSpanway_BudgetTableFull or nullNo
object_permission_idstring or nullNoObject Permission Id
object_permissionSpanway_ObjectPermissionTable or nullNo
organization_idstring or nullNoOrganization 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):

FieldTypeRequiredDescription
user_idsarray of stringYesUser 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:

StatusDescriptionBody
200Successful Responseapplication/json DeleteCustomersResponse
400user_ids is required and must not be emptyapplication/json ProxyError
401Authentication Error, No api key passed in.application/json ProxyError
403user not allowed to access this route, role= proxy_admin_viewer. Trying to access: /customer/deleteapplication/json ProxyError
404End User Id(s)=acct-48213 do not exist in dbapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500DB 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):

FieldTypeRequiredDescription
deleted_customersintegerYesDeleted Customers
messagestringYesMessage

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:

StatusDescriptionBody
200Successful Responseapplication/json array of CustomerResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin or admin viewerapplication/json ErrorDetail
500The database is not connectedapplication/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:

NameInTypeRequiredDescription
end_user_idsquerystring or nullNo
start_datequerystring or nullNo
end_datequerystring or nullNo
modelquerystring or nullNo
api_keyquerystring or nullNo
pagequeryintegerNo
page_sizequeryintegerNo
exclude_end_user_idsquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/customer/daily/activity" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json SpendAnalyticsPaginatedResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin or admin viewerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
resultsarray of DailySpendDataYesResults
metadataDailySpendMetadataNo