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.
| Method | Path | Summary |
|---|---|---|
| GET | /agent/daily/activity/aggregated | Daily activity per agent |
| GET | /agent/daily/activity/aggregated/keys | Keys ranked by spend for a agent |
| GET | /agent/daily/activity/aggregated/search | Search the keys with activity for a agent |
| GET | /agent/daily/activity/aggregated/model_top_keys | Top keys for one model in a agent |
| GET | /agent/daily/activity/export | Download 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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
api_key_limit | query | integer | No | How many top keys to return |
agent_ids | query | string or null | No | Comma-separated agent ids to include, all agents if empty |
start_date | query | string or null | No | First day of the range, YYYY-MM-DD |
end_date | query | string or null | No | Last day of the range, YYYY-MM-DD |
model | query | string or null | No | Only count requests to this model |
api_key | query | string or null | No | Only count requests made with this virtual key |
exclude_agent_ids | query | string or null | No | Comma-separated agent ids to leave out |
timezone | query | integer or null | No | Timezone 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:
| 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 /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:
| 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 |
agent_ids | query | string or null | No | Comma-separated agent ids to include, all agents if empty |
start_date | query | string or null | No | First day of the range, YYYY-MM-DD |
end_date | query | string or null | No | Last day of the range, YYYY-MM-DD |
model | query | string or null | No | Only count requests to this model |
api_key | query | string or null | No | Only count requests made with this virtual key |
exclude_agent_ids | query | string or null | No | Comma-separated agent ids to leave out |
timezone | query | integer or null | No | Timezone 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:
| 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 /agent/daily/activity/aggregated/search
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:
| 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 |
agent_ids | query | string or null | No | Comma-separated agent ids to include, all agents if empty |
start_date | query | string or null | No | First day of the range, YYYY-MM-DD |
end_date | query | string or null | No | Last day of the range, YYYY-MM-DD |
model | query | string or null | No | Only count requests to this model |
api_key | query | string or null | No | Only count requests made with this virtual key |
exclude_agent_ids | query | string or null | No | Comma-separated agent ids to leave out |
timezone | query | integer or null | No | Timezone 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:
| 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 /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:
| 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 |
agent_ids | query | string or null | No | Comma-separated agent ids to include, all agents if empty |
start_date | query | string or null | No | First day of the range, YYYY-MM-DD |
end_date | query | string or null | No | Last day of the range, YYYY-MM-DD |
model | query | string or null | No | Only count requests to this model |
api_key | query | string or null | No | Only count requests made with this virtual key |
exclude_agent_ids | query | string or null | No | Comma-separated agent ids to leave out |
timezone | query | integer or null | No | Timezone 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:
| 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 /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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
export_type | query | ExportType | No | The breakdown of each row |
format | query | enum: "csv", "json" | No | csv or json |
agent_ids | query | string or null | No | Comma-separated agent ids to include, all agents if empty |
start_date | query | string or null | No | First day of the range, YYYY-MM-DD |
end_date | query | string or null | No | Last day of the range, YYYY-MM-DD |
model | query | string or null | No | Only count requests to this model |
api_key | query | string or null | No | Only count requests made with this virtual key |
exclude_agent_ids | query | string or null | No | Comma-separated agent ids to leave out |
timezone | query | integer or null | No | Timezone 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:
| 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 |