Model insights API
This page documents the 2 gateway endpoints tagged model_insights 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 | /model-insights | Rank the models the whole gateway used over a date range |
| GET | /model-insights/tasks | Break the gateway's usage down by task type |
Endpoints
GET /model-insights
Rank the models the whole gateway used over a date range
Which models carried the gateway's traffic, spend or tokens between two dates, from the per-day usage rollup.
top_models ranks the ten leading model groups by metric, daily has one row per day for each of
them and daily_totals sums every model per day. Days are UTC and both dates are included. The range
defaults to the last 365 days and may not be longer than that. Proxy admins and admin viewers only, because
the data covers every team.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
start_date | query | string or null | No | YYYY-MM-DD, defaults to 365 days ago |
end_date | query | string or null | No | YYYY-MM-DD, defaults to today |
metric | query | enum: "requests", "spend", "tokens" | No | Metric the top models are ranked by |
Example request:
curl -X GET "http://localhost:4000/model-insights" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The top ten models by the chosen metric, their daily rows and the daily totals across every model. | application/json ModelInsightsResponse |
| 400 | Dates must use YYYY-MM-DD or Date range must be between 1 and 365 days | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Only proxy admins can view deployment-wide model insights | application/json ErrorDetail |
| 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 ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
daily | array of ModelInsightDailyMetric | Yes | Daily |
daily_totals | array of ModelInsightDailyTotal | Yes | Daily Totals |
end_date | string | Yes | End Date |
start_date | string | Yes | Start Date |
top_models | array of ModelInsightMetric | Yes | Top Models |
GET /model-insights/tasks
Break the gateway's usage down by task type
How the gateway's usage splits across task types. A request declares its task with a task:<type> tag,
sent in the x-spanway-tags header or in metadata.tags, and requests with no recognised task roll up
as uncategorized. Each row carries the task's label and category, its total of metric, its share of
the grand total in percent and the model group and provider that lead it. Same date rules and roles as
GET /model-insights.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
start_date | query | string or null | No | YYYY-MM-DD, defaults to 365 days ago |
end_date | query | string or null | No | YYYY-MM-DD, defaults to today |
metric | query | enum: "requests", "spend", "tokens" | No | Metric task shares are computed from |
Example request:
curl -X GET "http://localhost:4000/model-insights/tasks" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | One row per task type seen in the range, sorted by the chosen metric, with the model that leads it. | application/json ModelInsightTasksResponse |
| 400 | Dates must use YYYY-MM-DD or Date range must be between 1 and 365 days | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Only proxy admins can view deployment-wide model insights | application/json ErrorDetail |
| 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 ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
end_date | string | Yes | End Date |
start_date | string | Yes | Start Date |
tasks | array of ModelInsightTaskSummary | Yes | Tasks |