> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/deployment/roboflow-cloud/cloud-streaming/live-results.md).

# Live Results

Receive every JSON result of a running Cloud Streaming job in your own application over a WebSocket feed, and resume after a dropped connection.

The live results feed is a WebSocket that delivers each JSON result of a running Cloud Streaming job to your application as the Workflow produces it. Results are numbered, so your client can reconnect, resume after the last result it received, and see when results were skipped.

Use the feed when your own service needs the result of every processed frame (ex: counting, logging, driving a dashboard). To push only selected results to an HTTPS endpoint, use a [Workflow sink](https://docs.roboflow.com/deployment/roboflow-cloud/cloud-streaming/consume-results.md#send-results-with-a-workflow-sink). To watch annotated video, request a [watch grant](https://docs.roboflow.com/deployment/roboflow-cloud/cloud-streaming/consume-results.md#watch-live-output).

The feed is the streaming option. The subscription also returns a `pollUrl` that serves the same results as finite JSON pages, for clients that cannot hold a WebSocket open. It returns no URL for server-sent events.

{% hint style="info" %}
A feed exists only while a job is claimed or running. For any other job that has not ended, the subscription returns `retryAfterSeconds` in place of a feed. Results from before you connect are not stored: to keep results, read the feed continuously or use a Workflow sink.
{% endhint %}

## Before you start

You need:

* A Cloud Streaming job. [Start one with the HTTP API](https://docs.roboflow.com/deployment/roboflow-cloud/cloud-streaming/run-a-workflow.md#http-api) or in the Web App, and copy its job ID.
* A workspace API key with the `video-inference-job:read` scope. See [scoped API keys](https://docs.roboflow.com/reference/authentication/authentication/scoped-api-keys). Keep the key on your server.

Reading results takes two steps: ask the Roboflow API where the job's feed is, then open the WebSocket it returns.

## Subscribe to a job

Subscribing changes nothing on the job and starts no video. Call it before every connection, and again each time a connection ends.

{% openapi src="/files/HZKHykExD3Pp9vVK5PrS" path="/{workspace}/video-jobs/v1/{jobId}/results/subscribe" method="post" %}
[cloud-streaming.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-2927c06848d4341631bbd3bafea073b855e32b47%2Fcloud-streaming.yaml?alt=media)
{% endopenapi %}

The response is one of three answers. Check them in this order:

1. `ended` is `true`: the job will produce no more results. If `successorJobId` is present, the job continues under that ID, so subscribe to it. Otherwise stop.
2. `retryAfterSeconds` is present: the job has no feed right now (ex: it is queued, waiting for its source, or restarting). Wait that many seconds and subscribe again.
3. `eventsUrl` and `accessToken` are present: connect to the feed.

## Connect to the feed

Open a WebSocket to `eventsUrl` exactly as returned, and send `accessToken` in the `Authorization` header:

```
GET /PROCESSOR_ID/events/ws?job=JOB_ID HTTP/1.1
Host: processor.example.invalid
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: ...
Authorization: Bearer lr1.1800000600.RESULTS_TOKEN_SIGNATURE
```

A client that cannot set headers can append the token as an `access_token` query parameter. Query strings are often logged, so prefer the header.

To resume after a dropped connection, append `after` with the `seq` of the last result you received (ex: `&after=1041`). The feed then replays the results that followed it. Without `after`, the feed starts at the next new result.

The feed sends a WebSocket ping every 15 seconds and closes the connection when it hears nothing from your client for 30 seconds after a ping. Most WebSocket libraries answer pings for you. The feed is one-way: it ignores messages your client sends.

If the feed refuses the connection, it answers with a plain HTTP status:

<table data-search="false"><thead><tr><th>Status</th><th>Meaning</th><th>What to do</th></tr></thead><tbody><tr><td>400</td><td>The request is not a valid WebSocket upgrade.</td><td>Fix the client.</td></tr><tr><td>401</td><td>The token is missing, expired, or from an earlier execution of the job.</td><td>Subscribe again for a new token.</td></tr><tr><td>404</td><td>The job is no longer running on this processor.</td><td>Subscribe again.</td></tr><tr><td>429</td><td>The job already has 16 subscribers.</td><td>Wait at least 5 seconds, then subscribe again.</td></tr></tbody></table>

## Messages

Every message is a JSON text frame with a `type`.

<table data-search="false"><thead><tr><th>Type</th><th>Sent</th><th>Fields</th></tr></thead><tbody><tr><td><code>hello</code></td><td>Once, first</td><td><code>protocol</code>, <code>jobId</code>, <code>executionGeneration</code>, <code>nextSeq</code></td></tr><tr><td><code>result</code></td><td>Once per Workflow result</td><td><code>seq</code>, <code>result</code></td></tr><tr><td><code>gap</code></td><td>When results were skipped</td><td><code>fromSeq</code>, <code>toSeq</code></td></tr><tr><td><code>end</code></td><td>Once, last, when the run stops</td><td><code>reason</code></td></tr></tbody></table>

### hello

`nextSeq` is the `seq` of the next result this connection sends. `protocol` is `1`.

```json
{"type": "hello", "protocol": 1, "jobId": "JOB_ID", "executionGeneration": 1, "nextSeq": 1042}
```

### result

`seq` counts results from 0 within one execution of the job. `result` holds the frame's Workflow outputs by name. Images are never sent on the feed: an image output appears as an `image_ref` placeholder. `latencyMs` can be `null`.

```json
{
  "type": "result",
  "seq": 1042,
  "result": {
    "frameId": 31260,
    "timestamp": "2026-01-15T17:04:05.123456Z",
    "latencyMs": 41.7,
    "outputs": {
      "predictions": {
        "image": {"width": 1920, "height": 1080},
        "predictions": [
          {
            "x": 812.5,
            "y": 440.0,
            "width": 96.0,
            "height": 210.0,
            "confidence": 0.91,
            "class": "person",
            "class_id": 0,
            "detection_id": "0f6b2c1e-7a4d-4c39-9d0e-5b1f8a2c3d4e"
          }
        ]
      },
      "bounding_box_visualization": {"type": "image_ref", "output": "bounding_box_visualization"}
    }
  }
}
```

The shape of each entry in `outputs` depends on your Workflow's blocks.

### gap

A `gap` reports results your connection can no longer receive, from `fromSeq` through `toSeq` inclusive. It is sent when you resume after results have left the replay window, or when your client reads slower than the job produces results.

```json
{"type": "gap", "fromSeq": 1043, "toSeq": 1100}
```

### end

When the run stops, the feed sends `end` and closes the WebSocket with code 1000. `reason` is `completed`, `error`, `stopped`, or `replaced` (a newer execution of the job took over).

```json
{"type": "end", "reason": "completed"}
```

A stopped job can also drop the connection with no `end` message, so do not rely on `end` to learn that a job is over.

## Reconnect and follow the job

Treat every close the same way, whatever its cause: subscribe again and follow the answer.

1. Remember the `seq` of the last `result` you received.
2. When the connection ends, subscribe again. The response tells you whether the job ended, moved to a successor, has no feed yet, or has a feed to reconnect to.
3. If `executionGeneration` differs from the one you were reading, the job restarted and numbering began again at 0. Forget your last `seq` and connect without `after`.
4. Otherwise connect with `after` set to your last `seq`.
5. Start connections at least one second apart. When the feed keeps refusing a connection, back off (ex: 1, 2, 4, up to 30 seconds).

The feed keeps the most recent 300 results of a run for replay, or fewer when they exceed 4 MiB (about 10 seconds at 30 results per second). A resume from further back starts with a `gap`.

## Python client

This example subscribes once, connects, and prints each message. It needs the `websockets` package (`pip install websockets`). Set `ROBOFLOW_API_KEY` and replace `YOUR_WORKSPACE` and `JOB_ID`.

```python
import json
import os
import urllib.request

from websockets.sync.client import connect

url = "https://api.roboflow.com/YOUR_WORKSPACE/video-jobs/v1/JOB_ID/results/subscribe"
headers = {"Authorization": f"Bearer {os.environ['ROBOFLOW_API_KEY']}", "Content-Type": "application/json"}
request = urllib.request.Request(url, method="POST", data=b"{}", headers=headers)
grant = json.load(urllib.request.urlopen(request))

token = {"Authorization": f"Bearer {grant['accessToken']}"}
with connect(grant["eventsUrl"], additional_headers=token) as feed:
    for message in feed:
        print(message)
```

## Node.js client

This example does the same with Node.js 18 or later and the `ws` package (`npm install ws`).

```javascript
const WebSocket = require("ws");

const url = "https://api.roboflow.com/YOUR_WORKSPACE/video-jobs/v1/JOB_ID/results/subscribe";
const headers = { Authorization: `Bearer ${process.env.ROBOFLOW_API_KEY}`, "Content-Type": "application/json" };

fetch(url, { method: "POST", headers, body: "{}" })
  .then((response) => response.json())
  .then((grant) => {
    const token = { Authorization: `Bearer ${grant.accessToken}` };
    const feed = new WebSocket(grant.eventsUrl, { headers: token });
    feed.on("message", (message) => console.log(message.toString()));
  });
```

Both examples stop when the connection ends, and fail if the job has no feed yet. For a client that keeps running, handle the three subscription answers and [reconnect and follow the job](#reconnect-and-follow-the-job).

## Limits and security

* A job serves at most 16 result subscribers at once. A 17th connection is refused with HTTP 429.
* Each subscriber has a queue of 200 results. A client that falls further behind gets a `gap` in place of the results it missed. The job never slows down for a subscriber.
* `accessToken` expires ten minutes after the subscription response (`accessTokenExpiresAt`, Unix time in milliseconds). A connection opened before then stays open past the expiry. Subscribe again for each new connection.
* The token stops working when the job moves to a new execution. Subscribe again to get a token for the current one.
* The token is results-only. It opens the feed and `pollUrl`. It cannot open live video, job status, or result files, and it cannot change the job.
* Treat `eventsUrl` and `accessToken` as credentials: keep them out of logs, shared links, and source control. Do not ship your API key to a browser. Subscribe from your server.
