Skip to main content

Agent Management API

This page documents the 5 gateway endpoints tagged Agent 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/agent/daily/activity/aggregatedDaily activity per agent
GET/agent/daily/activity/aggregated/keysKeys ranked by spend for a agent
GET/agent/daily/activity/aggregated/searchSearch the keys with activity for a agent
GET/agent/daily/activity/aggregated/model_top_keysTop keys for one model in a agent
GET/agent/daily/activity/exportDownload agent daily activity as CSV or JSON

Endpoints​

GET /agent/daily/activity/aggregated​

Daily activity per agent

Spend, tokens and requests per day for each agent 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 agent 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
agent_idsquerystring or nullNoComma-separated agent ids to include, all agents if empty
start_datequerystring or nullNoFirst day of the range, YYYY-MM-DD
end_datequerystring or nullNoLast day of the range, YYYY-MM-DD
modelquerystring or nullNoOnly count requests to this model
api_keyquerystring or nullNoOnly count requests made with this virtual key
exclude_agent_idsquerystring or nullNoComma-separated agent ids to leave out
timezonequeryinteger or nullNoTimezone offset in minutes as JavaScript getTimezoneOffset gives it, e.g. 480

Example request:

curl -X GET "http://localhost:4000/agent/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 /agent/daily/activity/aggregated/keys​

Keys ranked by spend for a agent

One page of the virtual keys that spent the most inside the agent 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
agent_idsquerystring or nullNoComma-separated agent ids to include, all agents if empty
start_datequerystring or nullNoFirst day of the range, YYYY-MM-DD
end_datequerystring or nullNoLast day of the range, YYYY-MM-DD
modelquerystring or nullNoOnly count requests to this model
api_keyquerystring or nullNoOnly count requests made with this virtual key
exclude_agent_idsquerystring or nullNoComma-separated agent ids to leave out
timezonequeryinteger or nullNoTimezone offset in minutes as JavaScript getTimezoneOffset gives it, e.g. 480

Example request:

curl -X GET "http://localhost:4000/agent/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 agent

Find virtual keys with activity inside the agent 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
agent_idsquerystring or nullNoComma-separated agent ids to include, all agents if empty
start_datequerystring or nullNoFirst day of the range, YYYY-MM-DD
end_datequerystring or nullNoLast day of the range, YYYY-MM-DD
modelquerystring or nullNoOnly count requests to this model
api_keyquerystring or nullNoOnly count requests made with this virtual key
exclude_agent_idsquerystring or nullNoComma-separated agent ids to leave out
timezonequeryinteger or nullNoTimezone offset in minutes as JavaScript getTimezoneOffset gives it, e.g. 480

Example request:

curl -X GET "http://localhost:4000/agent/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 /agent/daily/activity/aggregated/model_top_keys​

Top keys for one model in a agent

The virtual keys that spent the most on one model inside the agent 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
agent_idsquerystring or nullNoComma-separated agent ids to include, all agents if empty
start_datequerystring or nullNoFirst day of the range, YYYY-MM-DD
end_datequerystring or nullNoLast day of the range, YYYY-MM-DD
modelquerystring or nullNoOnly count requests to this model
api_keyquerystring or nullNoOnly count requests made with this virtual key
exclude_agent_idsquerystring or nullNoComma-separated agent ids to leave out
timezonequeryinteger or nullNoTimezone offset in minutes as JavaScript getTimezoneOffset gives it, e.g. 480

Example request:

curl -X GET "http://localhost:4000/agent/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 /agent/daily/activity/export​

Download agent daily activity as CSV or JSON

Stream one row per day for each agent 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
agent_idsquerystring or nullNoComma-separated agent ids to include, all agents if empty
start_datequerystring or nullNoFirst day of the range, YYYY-MM-DD
end_datequerystring or nullNoLast day of the range, YYYY-MM-DD
modelquerystring or nullNoOnly count requests to this model
api_keyquerystring or nullNoOnly count requests made with this virtual key
exclude_agent_idsquerystring or nullNoComma-separated agent ids to leave out
timezonequeryinteger or nullNoTimezone offset in minutes as JavaScript getTimezoneOffset gives it, e.g. 480

Example request:

curl -X GET "http://localhost:4000/agent/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