Skip to main content
The Ably Server-Sent Events (SSE) API provides a simple way to receive real-time messages over HTTP using the Server-Sent Events standard. This is useful for browser clients that support SSE and scenarios where the full Ably client library SDK is not suitable.

Overview

The SSE API enables you to:
  • Receive real-time messages over HTTP
  • Subscribe to one or more channels
  • Use standard SSE libraries and the browser EventSource API
  • Automatically reconnect on connection loss

When to Use SSE

The SSE API is ideal for:
  • Browser applications that need simple real-time updates
  • Environments with limited WebSocket support
  • Read-only real-time data consumption
  • Lightweight integrations
For full bidirectional communication and advanced features, use the Realtime SDK.

Getting Started

Basic Usage

Connect to the SSE endpoint and subscribe to a channel:

Endpoint

The SSE endpoint is:

Parameters

channels
string
required
One or more channel names, separated by commas. Non-URL-safe characters should be URL-encoded.Example: channels=channel1,channel2
v
string
required
API version. Use v=1.2 for the current version.
key
string
Your Ably API key for Basic authentication.
accessToken
string
An Ably auth token for Token authentication.
lastEvent
string
Event ID to resume from when reconnecting.
rewind
integer
Number of recent messages to retrieve on connection. Maximum 100.Example: rewind=10 retrieves the last 10 messages.
enveloped
boolean
default:"true"
If true, message data is wrapped in a Message object. If false, returns raw message payload.
heartbeats
boolean
default:"false"
If true, sends explicit heartbeat events. If false, uses newlines as keepalive.
separator
string
Custom separator for channel names (useful when channel names contain commas).Example: separator=|&channels=ch1|ch2

Message Format

Messages are delivered as SSE events:

Event Types

The SSE API sends the following event types:
message
event
A message published to the channel.
presence
event
A presence event on the channel.
error
event
An error occurred (for example, token expired).
heartbeat
event
Keepalive heartbeat (when heartbeats=true).

Connection Management

Automatic Reconnection

The browser EventSource API automatically reconnects on connection loss. Use the lastEvent parameter to resume from the last received message:

Keepalive

The SSE connection sends keepalive packets to maintain the connection:
  • By default, newline characters (\n) are sent
  • With heartbeats=true, explicit heartbeat events are sent

Authentication

Basic Authentication

Use your API key in the URL:

Token Authentication

Use an Ably Token:

Examples

Subscribe to Multiple Channels

Retrieve Recent Messages

Handle Errors

Limitations

Read-Only

The SSE API is read-only. To publish messages, use:

No Presence

While you can receive presence events, you cannot enter presence using the SSE API. Use the Realtime SDK for full presence functionality.

Connection Limits

Browsers typically limit concurrent SSE connections to 6 per domain.

Build docs developers (and LLMs) love