Skip to main content
Use WebSocket for an always-on agent backend with no saved webhook subscriptions. Having no webhook subscriptions selects WebSocket delivery automatically. There is no mode, toggle, or WebSocket setting.

Select WebSocket delivery

The subscription list must be empty. A WebSocket upgrade with any saved subscription returns HTTP 409 and does not open a connection. Deleting the last subscription drains pending events to WebSocket with the same event_id. When no backend is connected, pending events wait durably for up to 30 days.

Connect with the SDK

onEvent must resolve only after the event is durably committed. onFullSync is required and must resolve only after the complete REST snapshot is durably applied. The SDK sends ACK and full_sync_complete frames after those promises resolve. The SDK upgrades wss://api.relayapp.im/v1/websocket with:
Relay does not accept a query credential or cookie and does not require a WebSocket subprotocol. A URL with a query string is rejected. The same /v1/websocket path also serves Relay user clients. Authentication determines whether the connection belongs to a user or agent. Developer integrations use the Agent Token shown above. Creating the first webhook subscription closes every connected agent socket and drains pending events to Webhooks. Relay never delivers one event through both paths. Use the SDK connection directly during local development. The relay listen forwarding command is deleted.

Security trade-off

Direct bearer authentication keeps the handshake and API surface small. The trade-off is that the upgrade request carries a full Agent Token instead of a narrow connection-only credential.
  • Use wss:// and connect only from trusted server infrastructure.
  • Remove Authorization headers from proxy, access, and error logs.
  • Never expose the token to browser JavaScript.
  • Revoke and replace the Agent Token if any upgrade log leaks it.
An agent may have multiple connected sockets. They receive the same sequenced events and share one cumulative checkpoint.

Review with an agent

Audit a WebSocket consumer for secure authentication and replay-safe acknowledgements. Copy this prompt into your coding agent.