Overview
Server-Sent Events (SSE) provide real-time progress updates for running audits. SSE replaces polling and reduces server load while improving responsiveness.SSE requires standard JWT Bearer authentication via the Authorization header.
Stream Audit Progress
GET/api/v1/sse/audits/{audit_id}/progress
Establishes an SSE connection for real-time audit progress updates.
Event Data Structure
Each SSE message contains a JSON payload with the following fields:Audit ID
Current status:
pending, running, completed, failedProgress percentage (0-100)
Human-readable progress message
GEO score (present when available)
Number of pages analyzed (when available)
Error message (only present on failure)
Stream Behavior
Initial Event
The stream immediately sends the current audit state upon connection.Progress Updates
Progress updates are sent in real-time:- Redis mode (production): Updates pushed via Redis pub/sub
- Database mode (fallback): Polls database every 10 seconds
- Heartbeat: Sent every 30 seconds if no updates
Terminal Events
The stream automatically closes when the audit reaches a terminal state:completed: Audit finished successfullyfailed: Audit failed with an error
Timeouts
- Max duration: 3600 seconds (1 hour)
- Reconnect retry: 5000ms (client should retry with this interval)
Configuration
SSE behavior is controlled by environment variables:| Variable | Default | Description |
|---|---|---|
SSE_SOURCE | redis | Data source (redis or db) |
SSE_MAX_DURATION | 3600 | Max stream duration (seconds) |
SSE_HEARTBEAT_SECONDS | 30 | Heartbeat interval (seconds) |
SSE_FALLBACK_DB_INTERVAL_SECONDS | 10 | DB polling interval (seconds) |
SSE_RETRY_MS | 5000 | Client retry interval (milliseconds) |
Error Handling
Stream Timeout
Internal Error
Best Practices
Connection Management
- Automatic reconnection: Browsers automatically reconnect on disconnect
- Manual close: Call
eventSource.close()on terminal events - Error handling: Implement exponential backoff on repeated errors
Fallback Strategy
If SSE is not supported or fails:- Detect SSE support: Check
typeof EventSource !== 'undefined' - Fallback to polling: Use
GET /api/v1/audits/{audit_id}/status - Poll interval: 5-10 seconds for running audits
Example: React Hook
Error Codes
Missing or invalid authentication token
Cross-user access denied
Audit not found