Relay API

WebSocket relay server for Position-Independent-Agent and Command Center. Pairs agents with relays 1:1 for transparent bidirectional message forwarding.

Authentication

All endpoints except GET / and /agent require a token. Currently accepted but not validated — any non-empty value works.

HTTP
Authorization: Bearer <token>
WebSocket
Sec-WebSocket-Protocol: access_token, <token>
401{ "error": "unauthorized", "message": "Missing or invalid token" }

Endpoints

GET /
API documentation (this page).
https://relay.nostdlib.workers.dev/
GET /status AUTH
Live status of all connected agents, relays, and event listeners. Returns StatusResponse.
https://relay.nostdlib.workers.dev/status
POST /disconnect-all-agents AUTH
Disconnect all connected agents and their paired relays. Returns the count and IDs of disconnected agents.
https://relay.nostdlib.workers.dev/disconnect-all-agents
returns
{ "disconnected": number, "agentIds": string[] }
WS /agent
Agent WebSocket connection. Server assigns a unique ID and broadcasts agent_connected to all event listeners.
wss://relay.nostdlib.workers.dev/agent
send
any — forwarded to paired relay
receive
any — forwarded from paired relay
WS /relay/:agentId AUTH
Relay WebSocket with exclusive 1:1 pairing to the specified agent.
wss://relay.nostdlib.workers.dev/relay/{agentId}
send
any — forwarded to paired agent
receive
any — forwarded from paired agent
404{ "error": "agent_not_found", "agentId": "..." }
409{ "error": "agent_already_paired", "agentId": "...", "pairedRelayId": "..." }
WS /events AUTH
Live event feed. Sends a snapshot of all agents on connect, then real-time events.
wss://relay.nostdlib.workers.dev/events

On connect: { "type": "agents", "agents": AgentStatus[] }

  • agent_connected{ agent: AgentStatus }
  • agent_disconnected{ agentId: string }
  • agent_paired{ agentId: string, relayId: string }
  • agent_unpaired{ agentId: string, relayId: string }

Types

AgentMetadata
Connection metadata collected from the Cloudflare request.
FieldTypeDescription
ipstringClient IP address
countrystringISO country code
citystringCity name
regionstringRegion / state
continentstringContinent code (NA, EU, ...)
timezonestringIANA timezone
postalCodestringPostal / ZIP code
latitudestringGeographic latitude
longitudestringGeographic longitude
asnnumberAutonomous System Number
asOrganizationstringAS organization name
userAgentstringClient User-Agent header
requestPrioritystringRequest priority hint
tlsVersionstringTLS version (e.g. TLSv1.3)
httpVersionstringHTTP protocol (e.g. h2)
AgentStatus
Agent connection state. Extends AgentMetadata. Returned in /status and /events.
FieldTypeDescription
idstringUnique agent identifier
connectedAtnumberConnection timestamp (Unix ms)
pairedbooleanWhether a relay is currently paired
pairedRelayIdstring | nullPaired relay ID
messagesForwardednumberTotal messages forwarded
lastActiveAtnumberLast activity timestamp (Unix ms)
...plus all AgentMetadata fields
RelayStatus
Relay connection state. Returned in /status.
FieldTypeDescription
idstringUnique relay identifier
connectedAtnumberConnection timestamp (Unix ms)
pairedAgentIdstringID of the paired agent
EventListenerStatus
Event listener connection state. Returned in /status.
FieldTypeDescription
idstringUnique listener identifier
connectedAtnumberConnection timestamp (Unix ms)
ipstringClient IP address
countrystringISO country code
citystringCity name
regionstringRegion / state
continentstringContinent code
timezonestringIANA timezone
asnnumberAutonomous System Number
asOrganizationstringAS organization name
userAgentstringClient User-Agent header
tlsVersionstringTLS version
httpVersionstringHTTP protocol
StatusResponse
Response from GET /status.
FieldTypeDescription
agents{ count, connections: AgentStatus[] }Connected agents
relays{ count, connections: RelayStatus[] }Connected relays
eventListeners{ count, connections: EventListenerStatus[] }Connected event listeners

Heartbeat

  • Clients send ping text frames; the server auto-responds pong (works during hibernation)
  • Server sends ping every 30s to all connections
  • Clients with no activity for 60s are considered dead and disconnected

Constraints

  • Each agent can have at most one relay at a time
  • Connecting to /relay/:agentId returns 404 if the agent doesn't exist
  • Connecting to /relay/:agentId returns 409 if the agent already has an active relay