Skip to content

Stream Server-Sent Events

Subscribe to events from a stream using Server-Sent Events (SSE) protocol.

Request

http
GET /v4/stream/{stream}/sse?start_tx={start_tx}
Accept: text/event-stream
Authorization: Bearer <api_key>

Parameters

NameTypeRequiredDescription
streamstringYesStream name to subscribe to
start_txint64NoEvent ID to start subscribing from. If not provided, subscribes to new events only

Response

Server sends events in SSE format with data field containing JSON object:

ts
{
  tx: number,
  data: any,
  binary: boolean
}
FieldTypeDescription
txnumberID of the event
dataanyEvent data - string, JSON object, or base64 encoded binary data
binarybooleanIndicates if the event data is in binary format.

Example

Request:

bash
curl --location 'https://api.litebase.io/v4/stream/sample/sse' \
--header 'Accept: text/event-stream' \
--header "Authorization: Bearer $LITEBASE_API_KEY"

Response stream:

data: {"tx":1,"data":"hello world"}

data: {"tx":2,"data":{"name":"Braavos","type":"city_created"}}

data: {"tx":3,"data":"base64EncodedBinaryData"}