Create relay state subscriptions and stream live updates over Server-Sent Events (SSE) to get real-time relay monitoring data from the rstate REST API.
Use this file to discover all available pages before exploring further.
The subscriptions endpoints let you receive real-time relay state updates without polling. You first create a subscription with a set of filter criteria, then connect to the Server-Sent Events stream to receive updates as monitors publish new relay check results. This pattern is useful for dashboards, alerting systems, and any application that needs fresh relay data without repeatedly polling the REST endpoints.
Subscriptions require the server-side FEATURE_SUBSCRIPTIONS feature flag to be enabled. On self-hosted instances, set this in your config.yaml or environment. The hosted nostr.watch API has subscriptions enabled.
Connect to the Server-Sent Events stream for a subscription. The server sends a state-update event each time a relay’s aggregated state changes.Query parameters:
The EventSource API reconnects automatically on connection loss with exponential backoff. For production use, handle the error event to log issues:
eventSource.onerror = (event) => { if (eventSource.readyState === EventSource.CLOSED) { console.log('SSE connection closed — not reconnecting') } else { console.warn('SSE connection lost — browser will reconnect automatically') }}
Subscription IDs are in-memory and do not persist across server restarts. If the server restarts, create a new subscription and reconnect to the SSE stream. The EventSource error event fires when this happens.
For relay state updates that don’t require real-time streaming, consider using the CVM relays/subscribe_state tool instead — it provides the same filtering options over the Nostr protocol without an HTTP connection. See the CVM tools reference for details.