> For the complete documentation index, see [llms.txt](https://docs.eyepop.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eyepop.ai/deploying/on-premise/relay.md). Agents can also search and read this documentation through its [MCP server](https://docs.eyepop.ai/~gitbook/mcp).

# Relay to the Cloud

Send local cameras and video to EyePop's cloud through an instance, with no GPU and no models on the machine

Some cameras can only be reached from inside a site's network, and the machine next to them has no GPU. **Relay mode** covers that case: an instance on that machine reads the source, a camera, a webcam, a file or a url, and uploads it to EyePop's cloud, which runs the pop. Nothing runs on the machine but the reading and the upload.

* **Who pays.** The cloud's work is billed to the account the instance is registered to, as for any cloud source. Nothing is billed for what the instance itself does.
* **What leaves the machine.** The video as the camera sent it, or, when you ask for `--fps`, `--target-resolution` or motion detection, only what the pop needs after those are applied here. See [Local media optimization](#local-media-optimization).
* **When the connection drops.** A relayed stream keeps what it reads while EyePop cannot be reached, by default up to 5 minutes or 256 MiB per stream, and uploads it once the connection is back, while the live video goes on. Results of that catch-up carry `"backlog": true`, so a receiver tells them from live ones. Each frame keeps the time the camera captured it.

<figure><img src="https://1072321683-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDoCvfjveqiJFmk0cnXCp%2Fuploads%2Fgit-blob-57b1af355db5f682656b3e8f595a8f5dd39565fe%2Frelay-network-overview.svg?alt=media" alt="Your network, behind a NAT firewall, holds your cameras, a host running an EyePop on-premise instance in relay-only mode, and optionally your own app using the CLI, Python or Node SDK, and a webhook sink. The instance reads the cameras over RTSP, or takes a pop and media from your app, and sends the video out through the firewall over HTTPS to EyePop&#x27;s cloud, with no inbound port. In the cloud the pipeline API runs the pop, scaling out on GPU compute. Results come back to the instance on the same connection, which hands them to your app or the webhook sink on your network, or they stay in the cloud, which sends them to a webhook sink on the public internet."><figcaption><p>The instance reads the camera and sends its video out; EyePop's cloud runs the pop, and the results come back into your network or go to a public webhook.</p></figcaption></figure>

## A relay-only instance

Relaying from the CLI, a stream or an `eyepop run` with `--relay`, needs the [EyePop CLI](https://docs.eyepop.ai/cli/getting-started.md) 0.28.0 or later. An instance whose only job is to relay needs no GPU, no models and no pop of its own:

```bash
eyepop instance init --relay-only --history on
```

It runs the CPU runtime and boots no pipeline. `--history on` is for [persistent streams](https://docs.eyepop.ai/deploying/on-premise/streams.md); leave it off if you only run `eyepop run --relay`. Everything else about the instance, starting, stopping, logs and settings, is as for any instance.

An instance that serves its own pop can relay its streams too (`--relay` on a stream), but it relays no `eyepop run`: `eyepop run --relay` needs a relay-only instance.

## Relay a stream

The examples use this pop, saved as `person-tracking.json`: it detects people and tracks each one across frames.

```json
{
  "components": [
    {
      "type": "inference",
      "ability": "eyepop.person:latest",
      "categoryName": "person",
      "forward": {
        "operator": { "type": "crop" },
        "targets": [
          { "type": "tracking", "reidModel": "eyepop.person.reid:latest" }
        ]
      }
    }
  ]
}
```

On a relay-only instance a stream always needs `--relay` and its pop. Every source of a [persistent stream](https://docs.eyepop.ai/deploying/on-premise/streams.md) can be relayed: a camera, a url, a webcam (`--video-device`) or a file (`--file`). `--relay-results` says where the results go:

* `instance` brings them back into the instance, as a stream that runs here would have them: into its history, its event sinks and its own outputs. Use it when the system that wants the results is on the site's own network:

  ```bash
  eyepop instance stream start door --url rtsp://192.168.1.20:554/stream1 \
    --pop ./person-tracking.json --relay --relay-results instance
  ```

  To have them sent to a webhook behind your firewall, give the stream an output there. The instance delivers it, not the cloud, so the webhook can be on a private address, and nothing outside your network needs to reach it:

  ```bash
  export HOOK_TOKEN="Bearer <your webhook token>"
  eyepop instance stream start door --url rtsp://192.168.1.20:554/stream1 \
    --pop ./person-tracking.json --relay --relay-results instance \
    --output webhook=http://192.168.1.50:9099/hook,header=Authorization:env:HOOK_TOKEN
  ```

  `header=Authorization:env:HOOK_TOKEN` sends the value of `HOOK_TOKEN` as the `Authorization` header. The instance keeps the value with its streams, in a file only its user can read, so it holds across restarts; `stream list` never shows it. The webhook receives one JSON request per event: `stream.status_changed` as the stream starts and runs, `prediction.made` for each frame, and the tracker's track events such as `track.started`. A prediction looks like this, with `captured_at` the time the camera captured the frame, in nanoseconds:

  ```json
  {
    "schema": "eyepop.agent_event.v1",
    "event_id": "prediction.made:door:default:agent-door-default-19f8cee1-…:1796062666834076478",
    "event_type": "prediction.made",
    "occurred_at_ns": 1796062666834076478,
    "stream_id": "door",
    "stream_job_id": "default",
    "pipeline_id": "agent-door-default",
    "source_id": "agent-door-default-19f8cee1-…",
    "content": {
      "captured_at": 1796062665217428000,
      "seconds": 4.845,
      "source_width": 1920,
      "source_height": 1080,
      "objects": [
        { "classLabel": "person", "category": "person", "confidence": 0.9394, "trackId": 1,
          "x": 888.824, "y": 498.372, "width": 133.653, "height": 354.37 }
      ]
    }
  }
  ```

  `eyepop instance stream list` counts what the output delivered:

  ```
  door  running
    source: rtsp://192.168.1.20:554/stream1
    relay:  instance, connected
    output: webhook http://192.168.1.50:9099, 443 delivered, 0 dropped
  ```
* `cloud`, the default, keeps them in the cloud, which delivers them to the stream's outputs. A relayed stream without outputs keeps its results nowhere, so give it one:

  ```bash
  export CRM_TOKEN="Bearer <your webhook token>"
  eyepop instance stream start door --url rtsp://192.168.1.20:554/stream1 \
    --pop ./person-tracking.json --relay \
    --output webhook=https://hooks.example.com/eyepop,header=Authorization:env:CRM_TOKEN
  ```

  The cloud delivers to public addresses only, and only the prediction events and `stream.status_changed`.

`eyepop instance stream list` shows a relayed stream's connection, and while it is disconnected, what it holds to upload:

```
door  degraded (relay_disconnected)
  source: rtsp://192.168.1.20:554/stream1
  relay:  cloud, disconnected (backlog 41 segments, 52428800 bytes; dropped 0)
```

A relayed live upload is marked real time, so EyePop's cloud does not pace it again, and a stall on the uplink does not stay on the stream's latency. This needs eyepop-worker 4.31.2 or later on the instance and in the cloud. Against an older pipeline API, the instance sends the upload without the mark and logs it once. A file or url relayed with `run --relay` goes up as it is, not live, and is not affected.

## Relay a single run

A relayed run is the same thing as any ad hoc inference in EyePop's cloud, from the CLI, the Python SDK or the Node SDK: you hand over a pop and some media, and get predictions back. The one difference is where the media comes from: a file, a url or a camera that only this machine can reach, behind your firewall. Your code talks to the relay-only instance as it would to any on-premise instance; the instance uploads the media, the cloud runs the pop, and the predictions come back to your code. The cloud's work is billed to the instance's account.

{% tabs %}
{% tab title="CLI" %}

```bash
eyepop run --relay --pop ./person-tracking.json --media-path ./clip.mp4
eyepop run --relay --pop ./person-tracking.json --media-path https://example.com/clip.mp4
```

The CLI starts a relayed pipeline on the instance for the run, sends each source through it, prints the results, and stops the pipeline when the run is over, also when you press Ctrl-C.
{% endtab %}

{% tab title="Python" %}

```python
import json
from eyepop import EyePopSdk
from eyepop.worker.worker_types import Pop

pop = Pop.model_validate(json.load(open("person-tracking.json")))

with EyePopSdk.sync_worker(is_local_mode=True, relay=True, pop=pop) as endpoint:
    job = endpoint.upload("./clip.mp4")
    while result := job.predict():
        print(result)
```

`is_local_mode=True` talks to the instance on this machine, and `relay=True` makes the endpoint's pipeline a relayed one. Leaving the `with` block stops it. It needs `eyepop` 4.3.0 or later.
{% endtab %}

{% tab title="Node" %}

```typescript
import fs from 'fs'
import { EyePop } from '@eyepop.ai/eyepop'

const pop = JSON.parse(fs.readFileSync('person-tracking.json', 'utf8'))

const endpoint = await EyePop.workerEndpoint({ isLocalMode: true, relay: true, pop }).connect()
const results = await endpoint.process({ path: './clip.mp4' })
for await (const result of results) {
    console.log(result)
}
await endpoint.disconnect()
```

`isLocalMode: true` talks to the instance on this machine, and `relay: true` makes the endpoint's pipeline a relayed one. `disconnect()` stops it. It needs `@eyepop.ai/eyepop` 4.4.0 or later.
{% endtab %}
{% endtabs %}

Without `relay`, the same code would run the pop on the instance itself, which a relay-only instance cannot do; with `relay` on an instance that serves its own pop, the instance refuses, so use a relay-only instance.

A file is uploaded as it is, and an `http://` or `https://` url is fetched by the instance. A camera is better started as a [persistent stream](https://docs.eyepop.ai/deploying/on-premise/streams.md), which reconnects when the camera drops. Results are prediction version 4. `outputs` and `--output` work here too, for url sources: the cloud delivers them, to public addresses only.

## Capture time on a relayed camera

Predictions from a relayed camera carry `captured_at`: the moment the **camera** captured the frame, on the camera's own clock, not the moment EyePop received it. That matters whenever you correlate predictions with anything outside the stream, such as another camera, a sensor or a transaction log, because the delay between the camera and EyePop varies and would otherwise be baked into every timestamp. It is the same value a camera read directly from EyePop's cloud reports.

**What it needs from your camera.** The camera must send RTCP sender reports, and its clock must be kept in time, usually by NTP. Most business and industrial cameras do both, though it is often a setting you have to switch on. Point the camera at the same time source as the rest of your systems.

**When it is missing.** `captured_at` is left out of a prediction, never sent as null:

* **At the start of a stream**, for any frame that arrives before the camera's first clock reference. Most cameras send one within the first seconds.
* **For the whole stream**, when the camera sends no sender reports at all. That is a property of the camera, and no setting on EyePop's side changes it.

A missing `captured_at` is never a guessed one: where the capture time is not known, it is absent.

## Relay settings

| Setting                         | What it does                                                                                        | Default     |
| ------------------------------- | --------------------------------------------------------------------------------------------------- | ----------- |
| `--relay-backlog <DURATION>`    | How much of a relayed stream to keep while EyePop cannot be reached, such as `10m`; `0` keeps none. | `5m`        |
| `--relay-backlog-size <SIZE>`   | The most one relayed stream's backlog holds, such as `1GiB`; `0` keeps none.                        | `256MiB`    |
| `--relay-bandwidth-kbps <KBPS>` | What the backlogs upload together once EyePop is back, in kbit/s; live video is never capped.       | `0`, no cap |

Set them with `eyepop instance init` or `eyepop instance set`:

```bash
eyepop instance set --relay-backlog 15m --relay-backlog-size 1GiB --relay-bandwidth-kbps 4000
```

When a backlog is full, its oldest video is dropped first; `stream list` counts what was dropped.

## Local media optimization

A relayed stream reaches the cloud in one of two ways, and the options you give it choose which.

**As the camera sent it.** Without `--fps`, `--target-resolution` or motion detection, the instance does not decode the video at all: it repackages the camera's encoded stream and uploads it as it came, cut at the camera's own keyframes. This works for the codecs an MPEG transport stream carries: H.264, H.265 (HEVC), MPEG-1, MPEG-2 and MPEG-4 Part 2.

* The machine does almost no work, so a small CPU box relays many cameras.
* The cloud sees the camera's full quality.
* The upload is as large as the camera's stream, and the cloud processes every frame it sends.

**Optimized on the machine.** With `--fps`, `--target-resolution` or motion detection, the instance decodes the video, applies them, and encodes the result again as H.264 before it uploads it. The encoder keeps a constant quality, with a keyframe every 2 seconds, up to a maximum bitrate that follows the output's resolution and frame rate: 3 Mbit/s for 720p at 30 fps, about 1 Mbit/s for 720p at 5 fps, and about 5.5 Mbit/s for 1080p at 30 fps. A still scene uploads well below the maximum.

* The upload shrinks with the options: fewer frames per second, smaller frames, and nothing while the scene is still.
* The cloud processes only the frames that are left, which is what you pay for.
* Decoding and encoding take CPU on the machine for every stream, and re-encoding loses some quality.

A camera at 25 fps watching a door that people pass now and then is a good case for optimizing: `--fps 5 --motion` sends a fraction of the frames, and only while someone is there. A camera whose every frame matters, or a machine too small to encode, is better relayed as it came.

## Plan capacity

The limiting resource depends on how a stream is relayed:

* **As the camera sent it:** the uplink. The instance repackages the video without decoding it, so CPU use per camera is low, and the upload equals the camera's bitrate.
* **Optimized on the machine:** the CPU. The instance decodes and re-encodes each camera, and the upload shrinks according to the options.

The figures below were measured on one reference machine and serve as a directional reference only:

* a relay-only instance on an Intel Core i7 CPU;
* relaying 1080p cameras at 30 fps and about 6 Mbit/s.

| Per 1080p 30 fps camera | As the camera sent it                 | Optimized to 720p @ 5 fps | With motion detection, 720p @ 30 fps                        |
| ----------------------- | ------------------------------------- | ------------------------- | ----------------------------------------------------------- |
| CPU                     | \~0.13 core                           | \~0.3 core                | \~0.3 core while the scene is still, \~0.6 core with motion |
| Upload                  | the camera's bitrate, here \~6 Mbit/s | \~0.75 Mbit/s             | \~2.7 Mbit/s × the share of time with motion                |

**Uplink.** The required uplink is the sum of the bitrates the cameras upload. Plan for about 20% headroom. A relay whose uplink cannot keep up drops its oldest live video so that results stay current; `eyepop instance stream list` reports the stream's uplink as saturated and counts what was dropped.

**CPU.** Capacity scales with physical cores:

* **SMT threads:** two hardware threads of one core (Hyper-Threading, SMT) do not double it. On the reference machine, a camera cost up to a third more CPU when both threads of a core were in use.
* **Clock speed:** many CPUs, laptop parts in particular, lower their clock as more cores are busy, so the cost per camera rises with the number of cores in use.
* **Headroom:** keep CPU use below about 75% at the full camera count, to leave room for motion, reconnects and backlogs.

**Verification.** Run the planned cameras for several minutes and watch the machine's CPU and `eyepop instance stream list`.

* **CPU-limited:** lower the frame rate or resolution, or relay cameras as they send their video. Motion detection saves upload, not CPU: it decodes every frame even while the scene is still.
* **Uplink-limited:** optimize more streams on the machine, or relay fewer cameras through it.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.eyepop.ai/deploying/on-premise/relay.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
