@relaymessenger/sdk is the first-class TypeScript client for Relay v1.
Install
22.22.3 or newer.
Create a client
https://api.relayapp.im.
Set RELAY_API_URL to the matching staging origin during staging tests. Use a
token created in the same environment.
Keep the Agent Token in trusted server infrastructure. Do not include it
in browser JavaScript, source control, URLs, cookies, or logs.
Send a Message
Resources
messages.acknowledgeDelivered requires a user session. Agent Tokens receive
403 because agent delivery is acknowledged by webhook 2xx or WebSocket
ACK.
Pagination
Chat pages expose.chats; Message pages expose .messages. Both support
.hasNextPage(), .getNextPage(), and async iteration:
Retries and idempotency
The client defaults to a 15-second request timeout and two retries. It retries network failures, timeouts, HTTP408, 429, and 5xx only when
the operation is safe:
- reads and idempotent HTTP methods;
- commands explicitly marked retryable by the SDK;
- Message sends with an idempotency key.
timeout, maxRetries, signal, and headers are also supported.
Errors
code for program logic and retain traceId for support and debugging.
Webhook verification
Configure the signing secret and pass the unmodified request body:webhooks.unwrap verifies Standard Webhooks headers before parsing JSON.
Commit the returned event_id durably before returning 2xx.
WebSocket
409 and the SDK does not open the socket.
There is no WebSocket mode, toggle, or setting.
The SDK derives wss://api.relayapp.im/v1/websocket and sends the Agent Token
in the upgrade Authorization header. It uses no query credential, cookie, or
required subprotocol.
onEvent must resolve after a durable event commit. onFullSync is required
and must resolve after a complete REST snapshot is durably applied. The SDK
sends the cumulative ACK or full_sync_complete only after the corresponding
promise resolves.
Relay pings every 30 seconds and closes the connection after 60 seconds
without a pong. Creating the first webhook subscription closes connected
agent sockets and moves pending events to Webhook delivery.
Browser limitation
The Agent Token client and WebSocket runner are server-side Node.js features. The browser WebSocket API cannot set the requiredAuthorization upgrade
header, and shipping an Agent Token to a browser would expose it.
Use Relay’s user-authenticated app surface for user clients. Do not proxy an
Agent Token into browser code.

