Connect to realtime
Establish a realtime SSE connection.Response
The connection returns Server-Sent Events in the following format:string
Unique client connection identifier returned in the initial
PB_CONNECT eventSet subscriptions
Subscribe to specific topics to receive real-time updates.Request body
string
required
The client ID from the initial connection (returned in
PB_CONNECT)array
required
Array of subscription topics (max 1000 subscriptions, each max 2500 chars)
Subscription topics
You can subscribe to: Individual record:Response
Returns 204 No Content on success.Realtime events
When subscribed, you’ll receive events when records change:Event structure
string
The type of change:
create, update, or deleteobject
The affected record data (respects API rules and field permissions)
Example event
Client-side subscriptions
JavaScript example
Access control
Realtime subscriptions respect collection API rules:- listRule - For wildcard subscriptions (
posts/*) - viewRule - For specific record subscriptions (
posts/RECORD_ID)
Users only receive updates for records they have permission to view based on the collection’s API rules.
Authentication state
You can upgrade a guest connection to authenticated:- Establish SSE connection (guest)
- Make POST request to
/api/realtimewith auth token - Subscription permissions are updated based on the auth record
Subscription options
Add query parameters to subscription topics:Filter
Only receive events for records matching the filter:Expand
Automatically expand relation fields:Fields
Limit fields included in the event:Combined options
Connection management
Idle timeout
Connections automatically close after 5 minutes of inactivity (no events sent). The client should reconnect and resubscribe.Reconnection
When the connection drops:- Establish a new realtime connection
- Get new
clientIdfromPB_CONNECTevent - Resubmit all subscriptions
Unsubscribing
To change subscriptions, send a new subscription list. Previous subscriptions are automatically cleared:Performance considerations
- Maximum 1000 subscriptions per client
- Each subscription topic max 2500 characters
- Realtime events are processed in chunks of 150 clients
Best practices
- Subscribe to specific collections rather than all records
- Use filters to reduce event volume
- Limit fields to only what you need
- Close connections when not needed
- Implement reconnection logic