---
title: Server-Sent Events
project: OpenSync
version: 1.0
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/opensync/1-0/reference/server-sent-events/
updated: 2026-11-19T09:22:09.965Z
---

# Server-Sent Events

> Receive messages as a Server-Sent Events stream, for scripts and command-line tools.

Server-Sent Events is a one-way stream: the client only receives. Use it when your tool cannot speak WebSocket.

## Connect

Send `GET /` with the header `Accept: text/event-stream` and your token, in the `token` query argument or the `x-token` header:

```bash
curl -N -H "Accept: text/event-stream" -H "x-token: YOUR_TOKEN" "https://sync.example.com/"
```

The stream starts with the `init` message and a retry time, then one `data:` line for each message:

```text
data: {"type":"init","name":"Demo sync","version":1,"id":"OpenSync"}
retry: 3000

data: {"id":"24nb4004pu50d","type":"application/json","channel":"orders","method":"POST","headers":{"host":"sync.example.com","user-agent":"curl/8.7.1","accept":"*/*","content-type":"application/json","content-length":"27"},"ua":"","query":{},"body":{"id":1002,"status":"paid"},"ts":"2026-11-19T08:04:51.361Z","ip":"203.0.113.10","files":[]}
```

Each `data:` line holds one [message](../message-format/). The token's [channels](../../guides/token-channels/) apply, as with WebSocket.

## Wrong token

With a wrong token OpenSync does not open a stream. It answers `200` with the plain text `OpenSync v1`. Failed attempts count toward the lock described in [Access problems](../../faq/access/).

## In a browser

Browsers block an `EventSource` to OpenSync from a page on another address, because OpenSync does not send CORS headers. In web pages, use [WebSocket](../websocket/) instead. See [Listen in a web page](../../recipes/web-page/).

Clients connected with Server-Sent Events are not listed on the [Clients](../../guides/clients/) page.
