Alerts inbox and usage baselines
The alerts inbox tells you when one user or one virtual key starts behaving very differently from its own history, for example a leaked key that suddenly spends money, a script stuck in a retry loop, or an integration that starts failing. The gateway learns what normal looks like for each user and each key from the daily usage it already records, flags today's numbers when they are far above that, and puts each flag in an inbox where your team can acknowledge it, give it an owner and close it with a note. Every change is written to the audit log.
The inbox also collects quality drops from online evals. When an online eval rule's pass rate on sampled live traffic falls under its minimum, or drops sharply against the hour before, the regression lands here as an eval_regression alert next to the usage alerts, so one team works both from one place.
The same page set also shows how fast each deployment answers right now and how often its provider refuses with HTTP 429 (too many requests), in the Admin UI and as Prometheus metrics.
A real-world scenario
A team's CI key normally makes about 300 requests and spends about 2 dollars a day. On Tuesday a test job gets stuck retrying and by lunch the key has made 9,000 requests and spent 41 dollars. At the next hourly scan the key shows up in Alerts Inbox as a critical spend alert and a critical requests alert. The on-call admin acknowledges both so her colleagues know she is on it, assigns them to the team lead, who stops the job, then resolves them with the note "CI job looped, retry limit fixed". The next morning the key starts a new day with a clean slate, and the whole story is in the audit log.
How it decides what is unusual
For every user and every virtual key with usage today (UTC), the gateway reads the daily usage rollup and compares four numbers for today with the same numbers on each of the past days:
- Requests, how many calls were made.
- Tokens, prompt plus completion tokens.
- Spend, the cost in USD.
- Error rate, the share of calls that failed. Only days that had calls count towards the error rate baseline.
The usual level is the p95 of the past days, the value that 95 of 100 past days stayed under. With the default 14 days that is the busiest past day. Days without any usage count as zero, so a key that is normally quiet keeps a low usual level. A number is flagged when it is above both:
- the usual level times the multiplier (3 by default), and
- a minimum, so small amounts never flag: 100 requests, 100,000 tokens, 5 USD, or a 20 percent error rate with at least 20 calls today.
A brand new user or key has a usual level of zero, so it is held to the minimums only. An alert is critical when the number is at least twice the threshold, and warning otherwise. Each user or key gets at most one alert per metric per day. When the number keeps growing during the day, the same alert is updated with the higher value. A resolved alert stays resolved for the rest of that day.
Only usage totals are read. Prompts, responses and keys are never looked at, and the key column holds the key's hash, never the key itself.
Online eval regressions
An online eval rule with alert settings is checked every 5 minutes, separately from the usage scan. Each model group and scorer whose pass rate regressed becomes one alert with kind eval_regression, entity_type online_eval_rule, the rule id as entity_id and metric pass_rate. observed is the pass rate now, baseline_p95 the pass rate in the window before (the rule's minimum pass rate when that window had too few scores) and threshold the pass rate it had to stay above. It is critical when the pass rate is at most half the threshold and warning otherwise. There is at most one alert per rule, model group, scorer and day, and a lower pass rate later that day updates it, while a higher one does not. Scan now does not run this check. Online evals explains how a regression is found.
The scan
The gateway runs the scan every hour, starting five minutes after it boots, on every gateway instance that has a database. Running it on several instances at once is safe, because an alert is stored only once per user or key, metric and day. A proxy admin can also run it straight away with Scan now or POST /alerts/scan.
Resolved alerts are deleted 90 days after they were resolved. Open and acknowledged alerts are kept until someone resolves them.
Live deployment speed and 429s
Every gateway instance keeps a rolling 30 minute record of each deployment's calls. GET /health/deployments and the Live deployment speed card on Model Leaderboard show, for every deployment that served traffic in that window:
- Latency, time to first token on streamed answers and the whole call otherwise. This is the number the router's speed preferences use.
- Time to first token, only for streamed answers.
- Total time, the whole call from the first byte to the last.
- Tokens per second, the typical output speed.
- Requests, successes, provider side failures (timeouts, connection errors and 5xx) and rate limited, the number of HTTP 429 answers the provider returned.
Each time is shown as the typical value and the slow end (p50 and p90, the API also returns p99). Values are bucket upper bounds, so 500 ms means "at most 500 ms". A value of null, shown as "over 21 s" or "over 144 s", means slower than the largest bucket. When a coordination Redis is configured the numbers are shared across gateway instances, otherwise each instance reports its own traffic. A 429 from the gateway's own limits never counts, only one the provider sent back.
The same signals are on Prometheus when the prometheus callback is on: spanway_llm_api_latency_metric and spanway_llm_api_time_to_first_token_metric carry model_id, model_group and api_provider, and the new counter spanway_deployment_rate_limited_responses counts provider 429s per deployment with the labels model_group, spanway_model_name, model_id, api_base and api_provider. For example, to chart 429s per deployment:
sum(rate(spanway_deployment_rate_limited_responses_total[5m])) by (model_group, model_id)
and the p90 time to first token per deployment:
histogram_quantile(0.9, sum(rate(spanway_llm_api_time_to_first_token_metric_bucket[5m])) by (le, model_id))
The bundled Grafana dashboard with all metrics has a panel for the new counter.
Settings
All settings sit under general_settings.usage_anomalies in the config file. Leave it out to use the defaults.
general_settings:
usage_anomalies:
scan_minutes: 60
baseline_days: 14
multiplier: 3
min_requests: 100
min_tokens: 100000
min_spend: 5
min_error_rate: 0.2
min_error_requests: 20
| Setting | Default | What it does and when to change it |
|---|---|---|
scan_minutes | 60 | How often the scan runs. Lower it to hear about a runaway key sooner, at the cost of one more aggregate query on the daily rollup each time. 0 turns the scheduled scan off, and only Scan now fills the inbox. Changing it needs a restart. |
baseline_days | 14 | How many past days make up each user's and key's usual level, from 3 to 60. More days smooth out one busy day, fewer days adapt faster to a team that grew. |
multiplier | 3 | How many times the usual level counts as unusual. Raise it if the inbox is noisy, lower it to catch smaller jumps. |
min_requests, min_tokens, min_spend | 100, 100000, 5 | The least a day must reach before requests, tokens or spend (USD) can flag at all, so a test key going from 2 to 20 calls never raises an alert. |
min_error_rate, min_error_requests | 0.2, 20 | The lowest error rate (0 to 1) that can flag, and how many calls a day needs first, so a single failed call is not a 100 percent error rate alert. |
An invalid block is ignored with a warning and the defaults are used, see the logs below.
Step by step
-
Make sure the gateway has a database (
DATABASE_URL). Baselines read the daily usage rollup that every request already updates. Optionally add theusage_anomaliesblock above and restart. -
In the Admin UI open Observability, then Alerts Inbox. The page explains what is listed, and the Usage baselines table at the bottom shows every user (or, on the Keys tab, every key) with usage today next to its usual level, with the unusual ones marked. Over the API:
curl "http://localhost:4000/alerts/baselines?entity_type=key" -H "Authorization: Bearer $SPANWAY_MASTER_KEY"Expected result:
{"entity_type": "key", "day": "2026-11-23", "baseline_days": 14, "multiplier": 3.0, "entities": [...]}with flagged keys first, each withobserved,mean,p95,thresholdandflaggedper metric. -
Click Scan now to fill the inbox straight away instead of waiting for the hourly run:
curl -X POST http://localhost:4000/alerts/scan -H "Authorization: Bearer $SPANWAY_MASTER_KEY"Expected result:
{"day": "2026-11-23", "flagged": 3, "created": 1}, how many numbers were unusual and how many of them were new alerts. -
Read the inbox. Show defaults to Needs attention, the open and acknowledged alerts:
curl "http://localhost:4000/alerts/inbox?status=active" -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -
Click Acknowledge on an alert, then Assign and type the owner, then Resolve with a short note. Over the API:
curl -X POST http://localhost:4000/alerts/inbox/$ALERT_ID/acknowledge -H "Authorization: Bearer $SPANWAY_MASTER_KEY"curl -X POST http://localhost:4000/alerts/inbox/$ALERT_ID/assign \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"assigned_to": "oncall@example.com"}'curl -X POST http://localhost:4000/alerts/inbox/$ALERT_ID/resolve \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"note": "A batch job looped, the key owner fixed the retry setting."}'Expected result: each call answers the alert with its new
status,acknowledged_by,assigned_to, orresolved_byandresolution_note. -
Open Observability, then Model Leaderboard and look at Live deployment speed, or call:
curl http://localhost:4000/health/deployments -H "Authorization: Bearer $SPANWAY_MASTER_KEY"Expected result:
{"generated_at": "...", "window_minutes": 30, "deployments": [{"model_id": "...", "model_group": "gpt-5.5", "provider": "openai", "latency": {"p50_ms": 500.0, "p90_ms": 1500.0, "p99_ms": 3000.0}, ..., "rate_limited": 7}]}. -
Open Logs, then Audit logs, and filter on the table Alerts inbox to see who acknowledged, assigned and resolved each alert.
Routes
| Method | Path | What it does | Who |
|---|---|---|---|
| GET | /alerts/baselines | Today's usage next to each user's or key's usual level, entity_type user or key. | Proxy admins and admin viewers |
| GET | /alerts/inbox | Alerts newest first, status active (default), open, acknowledged, resolved or all, with page and page_size. | Proxy admins and admin viewers |
| GET | /alerts/inbox/{alert_id} | One alert. | Proxy admins and admin viewers |
| POST | /alerts/scan | Runs the scan now. | Proxy admins |
| POST | /alerts/inbox/{alert_id}/acknowledge | Marks an open alert as seen. | Proxy admins |
| POST | /alerts/inbox/{alert_id}/assign | Sets or clears the owner of an alert that is not resolved. | Proxy admins |
| POST | /alerts/inbox/{alert_id}/resolve | Closes an alert with an optional note. | Proxy admins |
| GET | /health/deployments | Live speed and 429 counts per deployment over the last 30 minutes. | Proxy admins and admin viewers |
A custom role with alerts.read opens the reads and alerts.write the changes. The Admin UI shows the action buttons to proxy admins only, admin viewers see the alerts with a note that they cannot change them.
Audit
Every change writes an audit row to the table Spanway_AlertInboxTable, shown as Alerts inbox in the Admin UI audit log:
createdfor each new alert, by the actorusage_anomaly_scanfor usage alerts andonline_eval_alertsfor online eval regressions, with the whole alert.updatedfor acknowledge, assign and resolve, by the admin who made it, with the alert before and after.invokedfor Scan now, by the admin, withobject_idscan:<day>and the scan result.
Privacy
An alert names the user id, the key hash or the online eval rule it is about, and the admins who acknowledged, own and resolved it. It holds numbers and a generated summary, never a prompt, a response or a key. An online eval alert's summary names the rule, the model group and the scorer type, never a graded answer or the judge's reason. A data subject request exports the alerts about a user and the ones they acknowledged, own or resolved, and erasure replaces the user id with the pseudonym in all of them.
Errors
Errors answer as {"detail": {"error": "<message>"}}.
| Status and message | Meaning | Fix |
|---|---|---|
403 Only proxy admins and admin viewers can read alerts | The key is neither a proxy admin nor an admin viewer and no custom role grants alerts.read. | Use an admin key, or grant alerts.read. |
403 Only proxy admins can change alerts | Admin viewers and other roles cannot scan, acknowledge, assign or resolve. | Use a proxy admin key, or grant alerts.write. |
404 alert_id=<id> not found | No alert has that id, or it was resolved more than 90 days ago and deleted. | Check the id in the list. |
409 alert_id=<id> is not open | Acknowledge only works on an open alert. | It is already acknowledged or resolved, nothing to do. |
409 alert_id=<id> is already resolved | A resolved alert cannot be assigned or resolved again. | Nothing to do, or wait for the next day's alert. |
422 Value error, text must not contain control characters or Value error, text must be a single line | The owner or note holds characters that could forge log lines. | Send plain text. The owner must be one line of at most 255 characters, the note at most 1,000. |
500 No connected database | Baselines and the inbox need Postgres. | Set DATABASE_URL. |
/health/deployments needs no database. It answers an empty deployments list when nothing served traffic in the last 30 minutes.
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| INFO | Usage anomaly scan for <day>: <n> flags, <n> new alerts, <n> old resolved alerts removed | A scan finished. | None. |
| INFO | Online eval rule <rule_id> regressed: <n> series, <n> new alerts in the alerts inbox | An online eval rule's pass rate dropped and its regressed series were written to the inbox. | Work the alert. |
| WARNING | Usage anomaly scan failed, the next scheduled run retries: <error> | The scan could not read the rollup or write the inbox, usually a database problem. | Check the database if it repeats. |
| WARNING | general_settings.usage_anomalies is invalid, using the defaults: <error> | A value in the usage_anomalies block is out of range or of the wrong type. Unknown keys are ignored, so check the spelling when a setting seems to have no effect. | Fix the value named in the error. |
Related
- Prometheus metrics for the per-deployment latency, time to first token and 429 series.
- Model Leaderboard for the page that carries the live deployment speed card.
- Online evals for the pass rate regressions that land in the inbox.
- Alerting for Slack, email and webhook alerts on budgets, outages and slow responses.
- Audit logs for reading the alert history.
- Database tables for what
Spanway_AlertInboxTableholds.