Skip to main content

Alerts API

This page documents the 8 gateway endpoints tagged alerts 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/alerts/baselinesUsage baselines per user or per key
GET/alerts/inboxList alerts in the inbox
POST/alerts/scanScan for usage anomalies now
GET/alerts/inbox/{alert_id}Read one alert
POST/alerts/inbox/{alert_id}/acknowledgeAcknowledge an alert
POST/alerts/inbox/{alert_id}/assignAssign an alert
POST/alerts/inbox/{alert_id}/resolveResolve an alert
GET/health/deploymentsLive speed and rate limits per deployment

Endpoints​

GET /alerts/baselines​

Usage baselines per user or per key

For every user or key with usage today (UTC), today's requests, tokens, spend and error rate next to the mean and p95 of its own past days, the threshold that counts as unusual and whether today crosses it. Flagged rows come first. Proxy admins and admin viewers may call it and it changes nothing.

Parameters:

NameInTypeRequiredDescription
entity_typequeryenum: "user", "key"NoCompare users or virtual keys

Example request:

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

Responses:

StatusDescriptionBody
200Today's usage next to each user's or key's own baselineapplication/json BaselineReport
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin or admin viewer key and no custom role grants the routeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
entity_typeenum: "user", "key"YesEntity Type
daystringYesDay
baseline_daysintegerYesBaseline Days
multipliernumberYesMultiplier
entitiesarray of EntityBaselineYesEntities

GET /alerts/inbox​

List alerts in the inbox

Alerts newest first, one page at a time, by default only the ones still open or acknowledged. Proxy admins and admin viewers may call it and it changes nothing.

Parameters:

NameInTypeRequiredDescription
statusqueryenum: "active", "open", "acknowledged", "resolved", "all"Noactive is open plus acknowledged, all includes resolved
pagequeryintegerNo
page_sizequeryintegerNo

Example request:

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

Responses:

StatusDescriptionBody
200One page of alerts, newest firstapplication/json AlertList
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin or admin viewer key and no custom role grants the routeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
alertsarray of InboxAlertYesAlerts
totalintegerYesTotal
pageintegerYesPage
page_sizeintegerYesPage Size

POST /alerts/scan​

Scan for usage anomalies now

Runs the usage anomaly scan now instead of waiting for the scheduled run. A flag that is already in the inbox for today is updated, not added twice. Proxy admins only, and the run and every new alert go to the audit log.

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/alerts/scan" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200How many flags today's scan found and how many became new alertsapplication/json ScanResult
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin key and no custom role grants the routeapplication/json ErrorDetail
500The gateway runs without a databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
daystringYesDay
flaggedintegerYesFlagged
createdintegerYesCreated

GET /alerts/inbox/{alert_id}​

Read one alert

One alert with who acknowledged, owns and resolved it. Proxy admins and admin viewers may call it.

Parameters:

NameInTypeRequiredDescription
alert_idpathstringYes

Example request:

curl -X GET "http://localhost:4000/alerts/inbox/alert_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The alertapplication/json InboxAlert
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin or admin viewer key and no custom role grants the routeapplication/json ErrorDetail
404No alert has that idapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
alert_idstringYesAlert Id
kindenum: "usage_anomaly", "eval_regression"YesKind
severityenum: "warning", "critical"YesSeverity
entity_typeenum: "user", "key", "online_eval_rule"YesEntity Type
entity_idstringYesEntity Id
metricenum: "requests", "tokens", "spend", "error_rate", "pass_rate"YesMetric
daystringYesDay
observednumberYesObserved
baseline_p95numberYesBaseline P95
thresholdnumberYesThreshold
summarystringYesSummary
statusenum: "open", "acknowledged", "resolved"YesStatus
assigned_tostring or nullYesAssigned To
acknowledged_bystring or nullYesAcknowledged By
acknowledged_atstring or nullYesAcknowledged At
resolved_bystring or nullYesResolved By
resolved_atstring or nullYesResolved At
resolution_notestring or nullYesResolution Note
created_atstringYesCreated At
updated_atstringYesUpdated At

POST /alerts/inbox/{alert_id}/acknowledge​

Acknowledge an alert

Marks an open alert as seen so others know someone is on it. Proxy admins only, and the before and after values go to the audit log.

Parameters:

NameInTypeRequiredDescription
alert_idpathstringYes

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/alerts/inbox/alert_id-123/acknowledge" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200The alert marked acknowledgedapplication/json InboxAlert
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin key and no custom role grants the routeapplication/json ErrorDetail
404No alert has that idapplication/json ErrorDetail
409The alert is not openapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
alert_idstringYesAlert Id
kindenum: "usage_anomaly", "eval_regression"YesKind
severityenum: "warning", "critical"YesSeverity
entity_typeenum: "user", "key", "online_eval_rule"YesEntity Type
entity_idstringYesEntity Id
metricenum: "requests", "tokens", "spend", "error_rate", "pass_rate"YesMetric
daystringYesDay
observednumberYesObserved
baseline_p95numberYesBaseline P95
thresholdnumberYesThreshold
summarystringYesSummary
statusenum: "open", "acknowledged", "resolved"YesStatus
assigned_tostring or nullYesAssigned To
acknowledged_bystring or nullYesAcknowledged By
acknowledged_atstring or nullYesAcknowledged At
resolved_bystring or nullYesResolved By
resolved_atstring or nullYesResolved At
resolution_notestring or nullYesResolution Note
created_atstringYesCreated At
updated_atstringYesUpdated At

POST /alerts/inbox/{alert_id}/assign​

Assign an alert

Sets who looks after an alert that is not resolved yet, or clears it with null. Proxy admins only, and the before and after values go to the audit log.

Parameters:

NameInTypeRequiredDescription
alert_idpathstringYes

Request body (application/json, schema AssignAlert):

FieldTypeRequiredDescription
assigned_tostring or nullYesWho looks after the alert, a user id or email; null clears the assignment

Example request:

curl -X POST "http://localhost:4000/alerts/inbox/alert_id-123/assign" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"assigned_to": "oncall@example.com"
}'

Responses:

StatusDescriptionBody
200The alert with its new ownerapplication/json InboxAlert
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin key and no custom role grants the routeapplication/json ErrorDetail
404No alert has that idapplication/json ErrorDetail
409The alert is resolvedapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
alert_idstringYesAlert Id
kindenum: "usage_anomaly", "eval_regression"YesKind
severityenum: "warning", "critical"YesSeverity
entity_typeenum: "user", "key", "online_eval_rule"YesEntity Type
entity_idstringYesEntity Id
metricenum: "requests", "tokens", "spend", "error_rate", "pass_rate"YesMetric
daystringYesDay
observednumberYesObserved
baseline_p95numberYesBaseline P95
thresholdnumberYesThreshold
summarystringYesSummary
statusenum: "open", "acknowledged", "resolved"YesStatus
assigned_tostring or nullYesAssigned To
acknowledged_bystring or nullYesAcknowledged By
acknowledged_atstring or nullYesAcknowledged At
resolved_bystring or nullYesResolved By
resolved_atstring or nullYesResolved At
resolution_notestring or nullYesResolution Note
created_atstringYesCreated At
updated_atstringYesUpdated At

POST /alerts/inbox/{alert_id}/resolve​

Resolve an alert

Closes an open or acknowledged alert with an optional note. A resolved alert stays resolved for the rest of its day even when the scan flags the same user or key again. Proxy admins only, and the before and after values go to the audit log.

Parameters:

NameInTypeRequiredDescription
alert_idpathstringYes

Request body (application/json, schema ResolveAlert):

FieldTypeRequiredDescription
notestring or nullNoWhat was found or done, kept on the alert and in the audit log

Example request:

curl -X POST "http://localhost:4000/alerts/inbox/alert_id-123/resolve" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"note": "A batch job looped, the key owner fixed the retry setting."
}'

Responses:

StatusDescriptionBody
200The alert marked resolvedapplication/json InboxAlert
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin key and no custom role grants the routeapplication/json ErrorDetail
404No alert has that idapplication/json ErrorDetail
409The alert is already resolvedapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a databaseapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
alert_idstringYesAlert Id
kindenum: "usage_anomaly", "eval_regression"YesKind
severityenum: "warning", "critical"YesSeverity
entity_typeenum: "user", "key", "online_eval_rule"YesEntity Type
entity_idstringYesEntity Id
metricenum: "requests", "tokens", "spend", "error_rate", "pass_rate"YesMetric
daystringYesDay
observednumberYesObserved
baseline_p95numberYesBaseline P95
thresholdnumberYesThreshold
summarystringYesSummary
statusenum: "open", "acknowledged", "resolved"YesStatus
assigned_tostring or nullYesAssigned To
acknowledged_bystring or nullYesAcknowledged By
acknowledged_atstring or nullYesAcknowledged At
resolved_bystring or nullYesResolved By
resolved_atstring or nullYesResolved At
resolution_notestring or nullYesResolution Note
created_atstringYesCreated At
updated_atstringYesUpdated At

GET /health/deployments​

Live speed and rate limits per deployment

For every deployment that served traffic in the last 30 minutes: latency, time to first token on streamed answers, total duration, output tokens per second, successes, provider side failures and 429 rate limit answers. Percentiles are bucket upper bounds, and a null percentile means slower than the largest bucket. The numbers are shared across gateway instances when Redis is configured. Proxy admins and admin viewers may call it.

Example request:

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

Responses:

StatusDescriptionBody
200Latency, time to first token, duration, throughput and 429 counts over the last 30 minutesapplication/json DeploymentSpeedReport
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin or admin viewer key and no custom role grants the routeapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
generated_atstringYesGenerated At
window_minutesintegerYesWindow Minutes
deploymentsarray of DeploymentSpeedRowYesDeployments