Self-Hosting the Relay
The Relay (apps/relay) is an optional Node.js service that lets your Sora devices act as one assistant. It tracks presence, routes bot sessions, worker tasks, orchestrator host handovers, workspace files, and media chunks, and stores shared Memory v3 state.
Clients call models and tools and store provider API keys. The Relay handles pairing, task routing, attachment transfer, and configured memory sync. Keep its data directory on persistent storage.
What it does
| Capability | Details |
|---|---|
| Account and devices | One account per deployment, revocable device tokens, short-lived pairing codes, QR / link onboarding. |
| Presence | Online state is derived from active WebSocket sessions, never self-reported. |
| Routing | Remote bot actions, session management, persistent worker delegation, workspace attachments, artifact chunks, and Orch host failover. |
| Shared memory | Incremental Memory v3 sync for profiles, entities, events, relations, and proposals, with last-write-wins merge and consolidation leases. |
| Transport | HTTPS and WSS, pinned by a CA SHA-256 fingerprint. |
Requirements
- Node.js 24 or newer (the server runs TypeScript directly).
- A reachable Linux host or container platform.
- A TLS certificate/key pair — self-signed is fine, because clients pin the CA fingerprint.
- A data directory that persists across restarts.
Run with Docker
Unified releases publish versioned Relay images to GitHub Container Registry. The published image targets Linux x86-64.
docker run -d \
--name sora-relay \
--restart unless-stopped \
-p 8443:8443 \
-v sora-relay-data:/data \
ghcr.io/sadami3066/sora-relay:latestOn first start the container creates the account and prints a one-time login secret:
docker logs sora-relaySave that secret — it is only shown once and authorizes the first device. The container already runs as a non-root user with /data as its data directory, so the volume above is all you need to back up.
To add TLS, mount certificate files into the container and set SORA_CERT, SORA_KEY, and SORA_CA. For internet-facing deployments you can also terminate TLS in front of the Relay with a reverse proxy (Caddy, Nginx) and forward to port 8443.
Run from source
git clone https://github.com/Sadami3066/Sora.git
cd Sora
pnpm install
# Generates self-signed TLS certificates, starts the relay, prints the pairing link
./apps/relay/scripts/dev-relay.shdev-relay.sh detects your LAN address, creates certs/ if needed, prints the pairing URL and CA fingerprint, and then starts the server. It is the fastest way to try multi-device sync on a home network.
To run the server directly:
SORA_HOST=0.0.0.0 \
SORA_PORT=8443 \
SORA_DATA_DIR=/opt/sora-relay/data \
SORA_CERT=/opt/sora-relay/certs/server.crt \
SORA_KEY=/opt/sora-relay/certs/server.key \
SORA_CA=/opt/sora-relay/certs/ca.crt \
pnpm --filter @sora/relay startTLS certificates and CA pinning
Generate a self-signed CA and a server certificate for your addresses:
SORA_CERT_IPS="192.168.1.50" ./apps/relay/scripts/gen-cert.sh ./certsThe script writes:
| File | Purpose |
|---|---|
ca.crt | CA certificate returned by GET /v1/ca and pinned by clients. |
server.crt, server.key | Server certificate and private key. |
fingerprint.txt | SHA-256 CA fingerprint used in pairing links (#fp=…). |
Certificates include 127.0.0.1, localhost, and any IPs passed in SORA_CERT_IPS. Set SORA_CERT_DAYS to change the validity period.
Pairing links carry the fingerprint as a URL fragment: https://<host>:8443/#fp=<sha256>. A Sora client refuses the connection when the server presents a different CA, so a compromised DNS entry or a man-in-the-middle proxy cannot silently impersonate the Relay. Because the client validates the CA itself, the certificate does not need to be publicly trusted.
Example systemd unit
[Unit]
Description=Sora Relay Service
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=/opt/sora-relay/apps/relay
Environment=SORA_HOST=0.0.0.0
Environment=SORA_PORT=443
Environment=SORA_DATA_DIR=/opt/sora-relay/data
Environment=SORA_CERT=/opt/sora-relay/certs/server.crt
Environment=SORA_KEY=/opt/sora-relay/certs/server.key
Environment=SORA_CA=/opt/sora-relay/certs/ca.crt
ExecStart=/usr/bin/node src/server/index.ts
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now sora-relay
sudo journalctl -u sora-relay -fLogs are the only place the one-time login secret is printed; if it is lost before the first device pairs, remove the data directory and start over.
Environment variables
| Variable | Default | Purpose |
|---|---|---|
SORA_HOST | 0.0.0.0 | Listen address. |
SORA_PORT | 8443 | Listen port (0 picks an ephemeral port for testing). |
SORA_DATA_DIR | apps/relay/data | SQLite (relay.db) storage directory. |
SORA_CERT | unset | Server TLS certificate PEM path. |
SORA_KEY | unset | Server TLS private key PEM path; requires SORA_CERT. |
SORA_CA | unset | CA certificate PEM returned at GET /v1/ca for fingerprint pinning. |
SORA_PUBLIC_ORIGIN | unset | Public https://… origin advertised in pairing links. |
SORA_LAN_ORIGIN | unset | LAN https://… origin advertised in pairing links. |
If no certificate pair is configured the server logs a warning and listens over plain HTTP — use that only on a trusted LAN or behind a TLS-terminating proxy.
Health and API surface
| Endpoint | Method | Purpose |
|---|---|---|
/v1/health | GET | Version, protocol version, CA fingerprint, and capabilities. |
/v1/ca | GET | CA certificate PEM for pinning. |
/v1/pair/enroll | POST | Enroll a device with the login secret or a pairing code. |
/v1/pair/code | POST | Create a short-lived pairing code (authenticated). |
/v1/profile | GET / PUT | Account profile shared by devices. |
/v1/devices | GET | List paired devices, presence, and bots. |
/v1/devices/<id> | PATCH / DELETE | Rename or revoke a device. |
/v1/super/host | GET / PUT | Read or switch the active Orch host. |
/v1/super/snapshot | POST / GET | Upload or fetch an Orch host snapshot. |
/v3/memory/push | POST | Push incremental Memory v3 changes. |
/v3/memory/pull | GET | Pull Memory v3 changes since a sequence number. |
/v3/memory/consolidation-lease | POST / DELETE | Acquire or release the memory consolidation lease. |
WebSocket traffic uses the same origin for presence, bot and worker routing, and live sync.
Limits
| Limit | Value |
|---|---|
| WebSocket frame | 8 MiB |
| Single routed result | 4 MiB (returns payload_too_large without dropping the socket) |
| HTTP JSON body | 64 KiB (4 MiB for Memory v3 push), 30 s body timeout |
| Pairing code lifetime | Short-lived; generated per device |
Pairing devices
- Start the Relay and copy the login secret from its logs.
- On the first device, open Settings → Connect devices, paste the pairing link (
https://<host>:8443/#fp=…), and enter the login secret. - On the account screen, generate a pairing code or QR link for each additional device. Pairing codes expire and never expose the master secret.
- Verify the new device appears in the device list before relying on it.
If a phone goes offline while hosting remote bots, exempt Sora from battery optimization so the WebSocket can reconnect in the background.
Backup, upgrade, and security
- Back up the data directory (the
/datavolume in Docker) to preserve the account, devices, and shared memory. The SQLite database runs in WAL mode. - Upgrade by pulling a newer image and restarting the container; back up first, since schema migrations run on startup.
- Keep the login secret private. Anyone who has both the pairing link and the secret can enroll a device.
- Expose only the port you need and keep the host patched; the Relay does not need root.
- Revoke a lost device from another paired device or by deleting it through the API.
- Standard
SORA_*settings are read from environment variables only; do not commit certificates or secrets to a repository.
Related
- Getting Started — pairing your first two devices.
- Orch orchestration — using paired devices as workers.
- Memory v3 — what syncs between devices.
