> ## Documentation Index
> Fetch the complete documentation index at: https://docs.scrape.st/llms.txt
> Use this file to discover all available pages before exploring further.

# Streams

> Real-time data streaming via WebSocket and Server-Sent Events

Receive data from X, Telegram, and Discord the instant it's captured — via WebSocket or SSE. All streams deliver the same `SourceEvent` payload used by webhooks.

<CardGroup cols={2}>
  <Card title="WebSocket" icon="plug" href="./websocket-connections">
    Full-duplex, bidirectional — authenticate via `x-api-key` header. Supports
    ping/pong keepalive, `fast-x` mode, and payload filtering.
  </Card>

  <Card title="Server-Sent Events" icon="satellite-dish" href="./public-sse">
    Unidirectional, auto-reconnect — public stream (no auth, truncated) or
    private stream (token auth, full data).
  </Card>
</CardGroup>

## At a Glance

| Feature       | WebSocket                   | Public SSE                         | Private SSE                                     |
| ------------- | --------------------------- | ---------------------------------- | ----------------------------------------------- |
| **Endpoint**  | `wss://scrape.st/ws`        | `https://scrape.st/stream`         | `https://scrape.st/stream?token=`               |
| **Auth**      | `x-api-key` header          | None                               | Token via [/stream/token](./generate-sse-token) |
| **Payload**   | Full `SourceEvent`          | Truncated (first 100 chars)        | Full `SourceEvent`                              |
| **Direction** | Bidirectional               | Server → Client                    | Server → Client                                 |
| **Reconnect** | Manual (implement yourself) | Automatic (`EventSource` built-in) | Automatic                                       |
| **Sources**   | X, Telegram, Discord        | fast-x, Telegram, Discord          | fast-x, Telegram, Discord                       |

## Stream Payload

All streams deliver the same `SourceEvent` shape — identical to what webhooks receive:

```json theme={null}
{
  "mid": "1886493083207827456",
  "sid": "44196397",
  "source": "x",
  "timestamp": 1712072400000,
  "payload": { ... }
}
```

See [X](/sources/x#webhook-payload), [Telegram](/sources/telegram#webhook-payload), or [Discord](/sources/discord#webhook-payload) for full payload examples per source.

## Query Parameters

Both WebSocket and SSE support these query parameters:

| Parameter           | Type    | Description                                                           |
| ------------------- | ------- | --------------------------------------------------------------------- |
| `useFastX`          | boolean | Receive `fast-x` push events immediately (before GraphQL enrichment)  |
| `ignoreFullPayload` | boolean | Skip full enriched X payloads — only receive `fast-x` + other sources |

<Info>
  **fast-x** delivers post data within \~50ms of posting, before the full GraphQL
  enrichment pass. The enriched `x` payload follows shortly after with complete
  metadata (engagement counts, media, entities).
</Info>

## Quick Start

<Steps>
  <Step title="WebSocket">
    Connect with your API key for full bidirectional streaming.

    ```javascript theme={null}
    const ws = new WebSocket("wss://scrape.st/ws", {
      headers: { "x-api-key": "YOUR_API_KEY" },
    });
    ws.onmessage = (e) => console.log(JSON.parse(e.data));
    ```
  </Step>

  <Step title="Public SSE (no auth)">
    Open a stream instantly — no API key needed. Data is truncated.

    ```javascript theme={null}
    const es = new EventSource("https://scrape.st/stream");
    es.onmessage = (e) => console.log(JSON.parse(e.data));
    ```
  </Step>

  <Step title="Private SSE (full data)">
    Generate a token, then connect for full payloads.

    ```bash theme={null}
    # 1. Generate token
    curl -X POST https://scrape.st/stream/token \
      -H "x-api-key: YOUR_API_KEY"

    # 2. Connect with token
    curl -N "https://scrape.st/stream?token=YOUR_TOKEN"
    ```
  </Step>
</Steps>
