Skip to main content

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.

MethodPathSummary
GET/model-insightsRank the models the whole gateway used over a date range
GET/model-insights/tasksBreak 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:

NameInTypeRequiredDescription
start_datequerystring or nullNoYYYY-MM-DD, defaults to 365 days ago
end_datequerystring or nullNoYYYY-MM-DD, defaults to today
metricqueryenum: "requests", "spend", "tokens"NoMetric the top models are ranked by

Example request:

curl -X GET "http://localhost:4000/model-insights" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The top ten models by the chosen metric, their daily rows and the daily totals across every model.application/json ModelInsightsResponse
400Dates must use YYYY-MM-DD or Date range must be between 1 and 365 daysapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Only proxy admins can view deployment-wide model insightsapplication/json ErrorDetail
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 ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
dailyarray of ModelInsightDailyMetricYesDaily
daily_totalsarray of ModelInsightDailyTotalYesDaily Totals
end_datestringYesEnd Date
start_datestringYesStart Date
top_modelsarray of ModelInsightMetricYesTop 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:

NameInTypeRequiredDescription
start_datequerystring or nullNoYYYY-MM-DD, defaults to 365 days ago
end_datequerystring or nullNoYYYY-MM-DD, defaults to today
metricqueryenum: "requests", "spend", "tokens"NoMetric task shares are computed from

Example request:

curl -X GET "http://localhost:4000/model-insights/tasks" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200One row per task type seen in the range, sorted by the chosen metric, with the model that leads it.application/json ModelInsightTasksResponse
400Dates must use YYYY-MM-DD or Date range must be between 1 and 365 daysapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Only proxy admins can view deployment-wide model insightsapplication/json ErrorDetail
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 ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
end_datestringYesEnd Date
start_datestringYesStart Date
tasksarray of ModelInsightTaskSummaryYesTasks