Alerting
Alerting tells you about problems before users do. The gateway watches its own traffic and sends alerts when providers fail, requests hang or run slowly, deployments go into cooldown, budgets are close to or over their limit, spend tracking fails, or the database errors. Alerts go to Slack compatible webhooks, Microsoft Teams, any webhook, email or PagerDuty. Every destination, PagerDuty and email included, is free.
A real-world scenario
A team runs its customer chat through the gateway with a primary model and a fallback. On a Friday evening the primary provider starts returning errors. Within a minute the on-call channel gets an llm_exceptions alert naming the model and the provider error, then a cooldown_deployment alert when the router takes the deployment out of rotation, and later a fallback_reports summary showing how many requests the fallback served. Nobody had to look at a dashboard, and the finance channel, which only receives budget_alerts, stayed quiet.
Turn it on in the config file
-
Add the destination and, if you want, the alert types to
general_settings:general_settings:alerting: ["slack"]alerting_threshold: 300alert_types:- llm_exceptions- llm_too_slow- llm_requests_hanging- budget_alerts- cooldown_deployment- db_exceptions -
Set the webhook in the environment and restart the gateway:
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..." -
Send a test alert:
curl "http://localhost:4000/health/services?service=slack" \-H "Authorization: Bearer $SPANWAY_API_KEY"Expected result:
{"status": "success", "alert_types": ["llm_exceptions", "llm_too_slow", "llm_requests_hanging", "budget_alerts", "cooldown_deployment", "db_exceptions"], "message": "Mock Slack Alert sent, verify Slack Alert Received on your channel"}A test message arrives in the channel within a few seconds. With a database connected, the test also posts this week's and this month's spend report to the channel. Only proxy admins can run the test, because it posts to a real channel.
alerting value | Destination and variable |
|---|---|
slack | Slack format messages to SLACK_WEBHOOK_URL, or to ALERTING_WEBHOOK_URL when that one is unset. Works with any Slack compatible incoming webhook. |
ms_teams | MS_TEAMS_WEBHOOK_URL |
webhook | Signed JSON for every alert type to WEBHOOK_URL, see signed webhooks |
email | The configured email logger, see email |
pagerduty | PagerDuty Events API with PAGERDUTY_API_KEY, see PagerDuty |
alerting_threshold is the number of seconds after which a request counts as hanging or slow. It defaults to 300 seconds, which the DEFAULT_SLACK_ALERTING_THRESHOLD environment variable changes. A lower value warns sooner about slow providers but also flags long answers that are normal for your traffic. alert_to_webhook_url maps an alert type to a different webhook, so budget alerts can go to a finance channel and outages to on-call.
Create the Slack webhook
A Slack incoming webhook is a secret address that posts to one channel. Anyone who has it can post there, so treat it like a password.
- Open the Slack app management page at api.slack.com/apps and click Create New App. Give it a name such as
Spanway alertsand pick your workspace. - In the app's settings open Incoming Webhooks and switch Activate Incoming Webhooks on.
- Click Add New Webhook to Workspace, choose the channel, such as
#ai-gateway-alerts, and click Authorize. - Copy the URL from Webhook URLs for Your Workspace. It starts with
https://hooks.slack.com/services/. - Give it to the gateway as
SLACK_WEBHOOK_URL, or paste it into a type's Webhook URL (Slack-compatible) field in the Admin UI, then send the test alert from step 3 above.
For a second channel, such as finance for budget alerts, add another webhook to the same app and map it per type.
general_settings:
alerting: ["slack"]
alert_to_webhook_url:
budget_alerts: "os.environ/SLACK_FINANCE_WEBHOOK_URL"
llm_exceptions: "os.environ/SLACK_ONCALL_WEBHOOK_URL"
Create the Teams webhook
Microsoft Teams takes webhooks from its Workflows app. The older Office 365 incoming webhook connectors were retired, so a connector URL made before that no longer works and must be replaced.
-
In Teams, go to the channel that should receive alerts, open its More options menu and choose Workflows.
-
Pick the Send webhook alerts to a channel template, sign in if asked, confirm the team and channel, and save the workflow.
-
Copy the webhook URL the workflow shows. If you lose it, open the Workflows app, edit the workflow and expand its webhook trigger.
-
Turn on the destination and set the URL, then restart the gateway.
general_settings:alerting: ["ms_teams"]export MS_TEAMS_WEBHOOK_URL="https://<your workflow webhook URL>" -
Send a test alert.
curl "http://localhost:4000/health/services?service=ms_teams" \-H "Authorization: Bearer $SPANWAY_API_KEY"Expected result:
{"status": "success", "message": "Mock MS Teams Alert sent, verify MS Teams Alert Received in your channel"}
The gateway posts each alert as an Adaptive Card, which the template accepts, so the card appears in the channel as a post from the workflow. Slack and Teams can be on together, alerting: ["slack", "ms_teams"], and each alert goes to both.
What an alert looks like
Slack and Teams alerts carry the same text, with the alert type, its level, the time and the message.
Alert type: `llm_exceptions`
Level: `High`
Timestamp: `14:02:37`
Message: LLM API call failed: `<the provider's error text>`
Proxy URL: `https://gateway.example.com`
When the same alert fires several times in a short window, the gateway sends it once with [Num Alerts: <count>] on the first line instead of flooding the channel. Budget alerts repeat at most once per budget_alert_ttl, which defaults to 24 hours. The Proxy URL line appears when PROXY_BASE_URL is set. Exception alerts carry the provider's error text, which usually names the model, and budget alerts name the key, user or team, so search Logs for that model or key around the time of the alert to find the requests behind it.
Turn it on from the Admin UI
- Sign in as a proxy admin and open Settings, then Logging & Alerts, then the Alerting Types tab.
- Switch on the alert types you want. For a type that should go to its own channel, paste that channel's webhook into its Webhook URL (Slack-compatible) field. A type with an empty field uses the general Slack webhook.
- Click Save Changes. The page shows "Alerts updated successfully", and Slack is added to the gateway's alerting destinations if it was missing.
- Click Test Alerts. The page shows "Alert test triggered. Test request to slack made - check logs/alerts on slack to verify", and the test message arrives in the channel.
- For thresholds and intervals, open the Alerting Settings tab, change the values and click Update Settings. The page says "Wait 10s for proxy to update." and the new values apply on every replica.
The Email Alerts and MS Teams Alerts tabs set up those two destinations the same way, each with its own Save Changes and test button.
Alert types
When alert_types is not set, the types marked on by default are sent. Set alert_types to choose exactly which ones you get.
| Type | On by default | Sent when |
|---|---|---|
llm_exceptions | yes | A provider call fails. |
llm_too_slow | yes | A call takes longer than the threshold. |
llm_requests_hanging | yes | A call has not returned after the threshold. |
cooldown_deployment | yes | The router puts a deployment into cooldown. |
new_model_added | yes | A model is added. |
model_deprecation_warnings | yes | A model the gateway serves is close to its provider's retirement date. |
outage_alerts | yes | A deployment keeps failing, so it looks like a provider outage. |
region_outage_alerts | yes | Several deployments in one provider region keep failing. |
fallback_reports | yes | A summary of the fallbacks the router made. |
budget_alerts | yes | A key, user, team or end user crosses its soft budget, has used 85% or 95% of its max budget (15% and 5% left), or reaches 100%. |
budget_tier_shift | yes | A team or organization moved to a cheaper budget tier as its spend crossed a shift percentage (sent as Medium), or back up after its budget reset (sent as Low). |
user_spend_thresholds | yes | A user's spend crosses a threshold. |
user_spend_anomalies | no | A user's spend deviates from its usual pattern. |
spend_reports, daily_reports | yes | Scheduled spend summaries, sent every general_settings.spend_report_frequency (7d by default). |
failed_tracking_spend | yes | Spend could not be written to the database, or the daily spend capture rate check found the rate below its threshold, no admin key to read the provider bill, or a bill it could not read. |
db_exceptions | yes | A database error. |
mcp_tool_description_blocked | yes | An MCP server's tool description was blocked by the tool catalog scan. |
mcp_pinned_tools_changed | yes | An MCP server's tool list no longer matches its pinned list. |
eval_regression | yes | A scheduled eval run or an online scoring rule's pass rate falls under its minimum or drops by more than its threshold. Online rule regressions also land in the alerts inbox whether or not this type is sent. |
workflow_runner_backlog | yes | Workflow steps are ready but none has been picked up for workflow_runner.backlog_alert_seconds and no live process is running steps. See queue mode. |
sanctions_alerts | yes | A sanctions screening event that needs a person, see sanctions. |
approval_requested | yes | A human approval request is waiting, with signed approve and reject links. It names the tool or workflow step only, never its arguments or message. |
access_request_created | yes | Someone filed an access request for a key, models, a team seat, more budget or higher rate limits, so approvers know it is waiting. It names ids and amounts only, never the requester's justification. Sent as Low. |
workflow_trigger_disabled | no | A workflow trigger was turned off after five refusals in a row or because its stored schedule no longer validates. The alert names the trigger and the reason only. |
workflow_run_failed | no | A workflow runner run that asked for an alert in its on_failure failed. It carries ids and error codes only, never error text, inputs or outputs. |
new_virtual_key_created, virtual_key_updated, virtual_key_deleted | no | A key is created, changed or deleted. |
logging_degraded | yes | Request logging fell behind on a worker process, so the gateway is sampling trace and analytics destinations or dropping log records to keep requests fast. Sent at most every LOGGING_DEGRADED_ALERT_REPEAT_SECONDS (600 by default), as High when records were dropped and Medium when only sampling. See logging under load. |
prompt_created | no | A new prompt was saved, including one pulled from a Git repository. Turn it on to hear about every new prompt. See prompt operations. |
prompt_updated | no | A prompt got a new version through the Prompt Studio, the API or a Git pull. Useful while a team edits prompts together, noisy otherwise. |
prompt_deleted | yes | A prompt was deleted from one environment or from all of them, sent as Medium. |
prompt_promoted | yes | A tested version was promoted into another environment, usually production, with the eval run that allowed it. Sent as Medium. |
compromised_key_reported | yes | A virtual key was reported as leaked through POST /public/compromised_key and has been blocked, see leaked keys. |
new_team_created, team_updated, team_deleted | no | A team is created, changed or deleted. |
new_internal_user_created, internal_user_updated, internal_user_deleted | no | An internal user is created, changed or deleted. |
alerting_args tunes the behaviour, including daily_report_frequency (43200 seconds, 12 hours, by default, or SLACK_DAILY_REPORT_FREQUENCY) and report_check_interval (300 seconds) for scheduled reports and budget_alert_ttl (86400 seconds), which stops the same budget alert from repeating within the window. The Alerting Settings tab in the Admin UI edits the same values, with each one's meaning and default as help text.
Digest mode
A busy outage can send the same alert many times. Digest mode collects repeats of one alert type, for the same model and endpoint, into one summary message per window, so the channel stays readable. It is off by default, and with it on you learn about a new problem only when the window closes, so keep it for noisy types such as llm_too_slow.
general_settings:
alerting: ["slack"]
alert_type_config:
llm_too_slow:
digest: true
digest_interval: 3600
digest turns it on for that type and digest_interval is the window in seconds, 86400 (24 hours) by default.
PagerDuty
PagerDuty does not follow alert_types. It pages when requests fail or hang often enough inside a window, read from general_settings.alerting_args.
| Setting | Default | Pages when |
|---|---|---|
failure_threshold | 1 | This many requests failed within failure_threshold_window_seconds. |
failure_threshold_window_seconds | 600 | The window for failed requests. |
hanging_threshold_seconds | 600 | A request counts as hanging after this many seconds. |
hanging_threshold_fails | 60 | This many requests hung within hanging_threshold_window_seconds. |
hanging_threshold_window_seconds | 600 | The window for hanging requests. |
The default pages on the first failure, which suits a low traffic service where every failure matters. Raise failure_threshold on busy gateways so one bad request does not wake someone up.
Signed webhooks
With webhook in alerting, every type listed in alert_types is sent as JSON to your endpoint, even when webhook is the only destination. The gateway follows the Standard Webhooks spec, so existing verification libraries work unchanged.
export WEBHOOK_URL="https://alerts.example.com/hooks/spanway"
export WEBHOOK_SIGNING_SECRET="whsec_$(openssl rand -base64 32)"
When webhook is the only destination, alert_to_webhook_url and default_webhook_url choose the endpoint per alert type and WEBHOOK_URL is the fallback. When slack or ms_teams is also on, those settings stay with the chat destination and the JSON goes to WEBHOOK_URL only, so chat webhooks never receive raw JSON.
Each request carries a webhook-id, a webhook-timestamp in Unix seconds and, when WEBHOOK_SIGNING_SECRET is set, a webhook-signature of the form v1,<base64 HMAC-SHA256> over {webhook-id}.{webhook-timestamp}.{body}. A secret that starts with whsec_ is base64 decoded first, as the spec describes. Any other value is used as raw bytes. The key must be at least 24 bytes. A secret that is too short or is not valid base64 after whsec_ is logged as an error at startup and no webhook alerts are sent until it is fixed, while Slack, Teams and email alerts keep working. Without a secret the request is unsigned and the gateway logs a warning at startup, so set one in production.
Every type in alert_types reaches WEBHOOK_URL, and when alert_types is unset the types marked on by default in the alert types table are sent. Slow request alerts leave out the prompt by default because redact_messages_in_exceptions defaults to true. With it set to false, they include the first 100 characters of the prompt unless turn_off_message_logging is set or the request is under zero data retention, and hanging request alerts never include it. Exception alerts include provider error text, and in those same cases they leave out the prompt and any request input the provider quoted back. If your receiver should only see budget events, set alert_types to ["budget_alerts"] or turn on redaction.
The body looks like this.
{
"alert_type": "llm_exceptions",
"level": "High",
"message": "...",
"timestamp": "2026-10-19T12:00:00Z",
"alerting_metadata": {},
"proxy_base_url": "https://gateway.example.com"
}
Budget alerts and customer spend events also keep every field of the older budget body, such as event, event_message, event_group, spend, max_budget, user_id and token, at the top level, so existing receivers keep working.
Receivers should reject a request when the signature does not match or when webhook-timestamp is more than five minutes from their clock, which stops replays of captured requests. Deduplicate on webhook-id, because a retry reuses it. The gateway retries timeouts, connection errors, 429 and 5xx responses up to three times with backoff that doubles from half a second and is capped at eight seconds. Other 4xx responses are not retried. Customer spend events are sent once per request without retries, so a slow receiver cannot hold up cost tracking. Failures are logged without the URL path, so tokens in the URL stay out of logs.
Testing
GET /health/services?service=slack sends a test alert to the configured channel and returns any error, which is the fastest way to validate a webhook. The same route takes ms_teams, webhook and email, where the email test goes to TEST_EMAIL_ADDRESS. Every one of these tests posts to a real channel, so only proxy admins may run them, and any other key gets 403 Only proxy admins can trigger the <service> test alert. (for the webhook, Only proxy admins can trigger the webhook test alert.).
GET /alerting/settings reads the alerting settings with their values and sources, and POST /config/field/update with field_name alerting_args saves them, which is what the Alerting Settings tab does.
curl -X POST http://localhost:4000/config/field/update \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
-d '{"config_type": "general_settings", "field_name": "alerting_args", "field_value": {"budget_alert_ttl": 43200}}'
Errors
| Status | Where | Meaning | Fix |
|---|---|---|---|
422 "slack" not in proxy config: general_settings. Unable to test this. | GET /health/services?service=slack, also for ms_teams | The destination is not in general_settings.alerting, so there is nothing to test. | Add it to alerting, or save the tab for it in the Admin UI, which adds it. |
422 "webhook" not in proxy config: general_settings. Unable to test this. | GET /health/services?service=webhook | webhook is not in general_settings.alerting. | Add it to alerting. |
422 MS_TEAMS_WEBHOOK_URL not set. Unable to test this. or WEBHOOK_URL not set. Unable to test this. | GET /health/services?service=ms_teams or webhook | The destination is on but its URL variable is unset. | Set MS_TEAMS_WEBHOOK_URL or WEBHOOK_URL. |
403 Only proxy admins can trigger the <service> test alert. | GET /health/services for slack, slack_budget_alerts, ms_teams, email and webhook | The test posts to a real channel. | Sign in as a proxy admin. |
500 MS Teams webhook returned status <code>: ... | GET /health/services?service=ms_teams | Teams rejected the test post. The text is the answer from Teams. | Create a new webhook with the Workflows app in Teams (the Post to a channel when a webhook request is received template) and paste its URL. Microsoft retired the old Office 365 incoming webhook connectors, so a connector URL stops working. |
| 200 from the Slack test, but nothing arrives | GET /health/services?service=slack | The test only queues the alert. Slack refused it afterwards, for example with no_service when the webhook was removed, channel_not_found or channel_is_archived for the channel, invalid_token or action_prohibited when a workspace admin restricted the app. | Create a new webhook as in create the Slack webhook, and check the gateway log at --detailed_debug for Slack's answer. |
| No alert from a gateway behind a company proxy | Any destination | The gateway cannot reach hooks.slack.com or the Teams workflow address, or does not trust the proxy's certificate. | Allow the host in the outbound proxy and the egress allowlist, and give the gateway the company root certificate. |
400 Service must be in list. Service=<name> not in [...] | GET /health/services | The service name is not one the route can test. | Use one of the names in the message. |
403 Only proxy admins can update config | Saving alert types (Alerting Types tab, /config/update) | The caller is a proxy admin viewer or another non-admin role. | Sign in as a proxy admin. |
403 Admin-only endpoint. Not allowed to access this. | Saving alert settings (Alerting Settings tab, POST /config/field/update) | The same, for the settings. | Sign in as a proxy admin. |
403 Admin-only endpoint. Not allowed to access this., your role=<role> | GET /alerting/settings | The caller is neither a proxy admin nor an admin viewer. | Use an admin key. |
400 general_settings key '<key>' is set in the config file and cannot be changed here. | Saving alert settings in the Admin UI | The setting is fixed in the config file. The answer's resolution field says what to do. | Change it in the config file, or remove it from there first. |
| Enterprise Feature button in place of a switch | Alerting Types tab | region_outage_alerts and some alerting settings need a license. | Add a license, or use the other alert types. |
Logs
| Level | Line | Meaning |
|---|---|---|
| WARNING | Webhook alerting is enabled without WEBHOOK_SIGNING_SECRET, so alerts are sent unsigned and receivers cannot verify them or reject replays | Webhook alerts work but are unsigned. Set the secret before production. |
| ERROR | WEBHOOK_SIGNING_SECRET is invalid (<reason>). Webhook alerts will not be sent until it is fixed | The secret is too short or not valid base64 after whsec_. No webhook alert is sent until it is fixed. Other destinations keep working. |
| ERROR | Error sending spend report: ... or Error sending weekly spend report ... | A scheduled report could not be sent. Check the destination and alerting_args. |
| ERROR | Error sending email alert ... or Trying to send email alert to no recipient | The email destination failed or had nobody to send to. Check the email logger and that the key or team has an owner with an email address. |
| ERROR | Error sending send_virtual_key_event_slack ... | A key event alert could not be posted to Slack. Check SLACK_WEBHOOK_URL. |
| ERROR | Webhook alerting is enabled but no webhook URL is configured for alert type=<type>. Set WEBHOOK_URL | The webhook destination is on with no address. Set WEBHOOK_URL. |
| WARNING | Webhook alert <type> to <host> was rejected with status <code> after <n> attempt(s) | The receiver answered with an error. Check its logs. |
| WARNING | Webhook alert <type> to <host> failed after <n> attempt(s): <error> | The receiver could not be reached after the retries. Check the address and the network. |
| ERROR | PagerDuty: PAGERDUTY_API_KEY is not set, dropping alert: <summary> | PagerDuty is on with no routing key, so no page was sent. Set PAGERDUTY_API_KEY. |
Troubleshooting
- Send the test alert for the destination. A 422 names what is missing, and a 500 from the Teams test carries Teams' own answer.
- If the Slack test answers 200 and nothing arrives, run the gateway with
--detailed_debugand send the test again. The log shows the answer Slack gave for the post. That debug log contains the webhook address, so do not share it. - If test alerts arrive but real ones do not, check that the type is in
alert_typesor switched on in the Alerting Types tab, and that it is not waiting outbudget_alert_ttlor the outage windows inalerting_args. - Check
GET /alerting/settingsand the config file foralert_to_webhook_url, which sends a type to its own webhook instead of the general one.
Rotate or remove a webhook
A webhook address is a secret, so replace it when it may have leaked or when someone who had it leaves. For Slack, add a new webhook in the app's Incoming Webhooks page, give it to the gateway, send the test alert, then remove the old webhook from the same page so the old address stops working. For Teams, create a new workflow from the template, give its URL to the gateway, test it and turn off or delete the old workflow in the Workflows app. Set the new address in SLACK_WEBHOOK_URL or MS_TEAMS_WEBHOOK_URL and restart the gateway, or save it on the matching tab in the Admin UI. To stop alerts to a destination, remove it from general_settings.alerting.
Related
- Logging & Alerts page for every control on the Admin UI page.
- Email notifications for the email destination and the per event switches.
- Spend capture rate and provider budget routing, which alert through the same channels.
- Logging for a full record of failures next to the alerts.
- Error reference and log reference.