Skip to main content
The Alerts API lets you monitor your voice agents in real time. Configure alert rules to watch key operational metrics, then receive webhook notifications when something goes wrong.

Key features

  • Alert rules - Monitor metrics like turn latency, API errors, function errors, call crashes, and call volume
  • Webhook notifications - Receive signed HTTP POST requests when alerts trigger
  • Project scoping - Scope alerts to specific projects or monitor account-wide

Available metrics

All count-based metrics represent absolute counts within the evaluation window, not rates. For example, if you set window_duration_seconds: 300 and threshold_value: 10 for api_errors, the alert triggers when there are 10 or more API errors in the 5-minute window.
MetricDescriptionUnitTypical threshold guidance
turn_latency_p50Median turn latencymilliseconds800-1500ms depending on use case
turn_latency_p9595th percentile turn latencymilliseconds1500-3000ms depending on use case
api_errorsNumber of API errors in windowcountConsider 0 for critical flows
function_errorsNumber of function execution errors in windowcountConsider 0 for critical functions
call_crashesNumber of call crashes in windowcountTypically 0 (any crash is concerning)
call_volumeNumber of calls in windowcountDepends on expected traffic patterns
When setting thresholds, consider the metric type and business impact:
  • Error metrics (api_errors, function_errors, call_crashes): Consider setting threshold to 0 for critical flows where any error requires attention
  • Latency metrics: Use longer windows (5-15 minutes) to smooth out transient spikes
  • Volume metrics: Base thresholds on historical traffic patterns and expected business hours

Alert states

StateDescriptionWhen it occurs
okThe metric is within the configured thresholdAfter successful evaluation shows metric below threshold
alertThe metric has breached the threshold and the alert is firingMetric exceeds threshold during evaluation
no_dataNo data is available for evaluationNo metric data reported during the evaluation window (e.g., no calls)
unknownThe state could not be determinedInitial state before first evaluation, or evaluation system error
no_data vs unknown: Use no_data to detect when your agents aren’t receiving traffic (which may itself be a problem). unknown is typically only seen briefly when a rule is first created or if there’s an evaluation system issue.

Quick start

1. Create an alert rule

curl -X POST https://api.poly.ai/v1/alert-rules \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "High turn latency (p95)",
    "project_id": "proj_abc123",
    "metric": "turn_latency_p95",
    "operator": ">=",
    "threshold_value": 1500,
    "window_duration_seconds": 300
  }'

2. Register a webhook endpoint

curl -X POST https://api.poly.ai/v1/webhook-endpoints \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production alert notifications",
    "url": "https://example.com/webhooks/polyai",
    "event_types": ["alerts.triggered"]
  }'
The signing_secret is returned only once when you create a webhook endpoint. Store it securely immediately.Lost your signing secret? You must delete the webhook endpoint and create a new one. There is no way to retrieve or rotate the secret after creation.

3. Check active alerts

curl https://api.poly.ai/v1/alerts \
  -H "x-api-key: YOUR_API_KEY"

Webhook delivery

Event types

EventDescription
alerts.triggeredSent when an alert rule transitions into a firing state
No alerts.resolved event: Webhooks only fire when an alert transitions into the firing state. There is no automatic notification when alerts recover. To detect recovery, poll GET /v1/alerts or GET /v1/alert-rules to check when the current_state changes back to ok.If you’re building a PagerDuty-style integration, you’ll need to implement polling to auto-resolve incidents.

Webhook payload

{
  "event_type": "alerts.triggered",
  "alert": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "High turn latency (p95)",
    "project_id": "proj_abc123",
    "metric": "turn_latency_p95",
    "operator": ">=",
    "threshold_value": 1500,
    "current_value": 1823,
    "previous_state": "ok",
    "triggered_at": "2024-03-15T10:30:00Z"
  }
}

Webhook headers

Each webhook request includes these headers:
HeaderDescription
X-PolyAI-TimestampUnix timestamp (seconds) when the webhook was sent
X-PolyAI-SignatureHMAC-SHA256 signature for verification
X-PolyAI-Event-IDUnique event identifier for deduplication

Retry policy

Failed webhook deliveries are retried with exponential backoff:
AttemptDelayCumulative time
1Immediate0
21 minute1 minute
35 minutes6 minutes
415 minutes21 minutes
51 hour~1.5 hours
64 hours~5.5 hours
Retried failures:
  • Timeout
  • Network error
  • HTTP 408, 429, 5xx
Not retried:
  • Other 4xx errors

Signature verification

Verify webhook signatures to ensure requests are from PolyAI. Algorithm: HMAC-SHA256 Signed message format: {timestamp}.{raw_request_body}
import hmac
import hashlib
import time

def verify_webhook(payload: bytes, timestamp: str, signature: str, secret: str) -> bool:
    # Reject requests older than 5 minutes
    if abs(time.time() - int(timestamp)) > 300:
        return False
    
    # Compute expected signature
    message = f"{timestamp}.{payload.decode('utf-8')}"
    expected = hmac.new(
        secret.encode('utf-8'),
        message.encode('utf-8'),
        hashlib.sha256
    ).hexdigest()
    
    # Constant-time comparison
    return hmac.compare_digest(expected, signature)
Use X-PolyAI-Event-ID for deduplication since retries can deliver the same event more than once.

Authentication

All Alerts API endpoints use API key authentication via the x-api-key header. Resources are automatically scoped to your account.
curl https://api.poly.ai/v1/alerts \
  -H "x-api-key: YOUR_API_KEY"

Error responses

StatusDescription
400Validation error - check request body or parameters
401Missing or invalid API key
404Resource not found
500Internal server error

Example error response

{
  "message": "Validation failed",
  "errors": [
    {
      "field": "threshold_value",
      "message": "must be a non-negative integer"
    },
    {
      "field": "metric",
      "message": "must be one of: turn_latency_p50, turn_latency_p95, api_errors, function_errors, call_crashes, call_volume"
    }
  ]
}

Pagination

List endpoints currently return all results without pagination. For accounts with many alert rules or webhook endpoints, consider filtering by project_id, metric, or enabled status to reduce response size.

Update request format

Important: PATCH requests use a JSON:API-style envelope, which differs from the flat JSON used in POST/create requests.Creating a resource (POST) uses flat JSON:
{
  "name": "My alert rule",
  "metric": "api_errors",
  "threshold_value": 10
}
Updating a resource (PATCH) requires a JSON:API envelope:
{
  "data": {
    "type": "alert-rules",
    "id": "00aa00aa-bb11-cc22-dd33-eeeeeeeeeeee",
    "attributes": {
      "threshold_value": 20
    }
  }
}
The id in the request body must match the rule_id or endpoint_id in the URL path.

Window duration

The window_duration_seconds field accepts values from 60 seconds (1 minute) to 86400 seconds (24 hours). Recommended ranges:
  • Latency alerts: 300-900 seconds (5-15 minutes) to smooth transient spikes
  • Error count alerts: 60-300 seconds (1-5 minutes) for faster detection
  • Volume alerts: 300-3600 seconds (5-60 minutes) depending on traffic patterns
Very short windows (under 60 seconds) may produce noisy alerts due to metric collection intervals. Very long windows (over 1 hour) may delay alert detection significantly.