***

title: RelayClient
slug: /reference/typescript/relay/client
description: WebSocket client for real-time call and message control.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[call]: /docs/server-sdks/reference/typescript/relay/call

[message]: /docs/server-sdks/reference/typescript/relay/message

[connect]: /docs/server-sdks/reference/typescript/relay/client/connect

[disconnect]: /docs/server-sdks/reference/typescript/relay/client/disconnect

[run]: /docs/server-sdks/reference/typescript/relay/client/run

[dial]: /docs/server-sdks/reference/typescript/relay/client/dial

[sendmessage]: /docs/server-sdks/reference/typescript/relay/client/send-message

[receive]: /docs/server-sdks/reference/typescript/relay/client/receive

[unreceive]: /docs/server-sdks/reference/typescript/relay/client/unreceive

[execute]: /docs/server-sdks/reference/typescript/relay/client/execute

`RelayClient` manages a persistent WebSocket connection to SignalWire's RELAY
service. It handles authentication, automatic reconnection with exponential
backoff, inbound event dispatch, outbound dialing, and SMS/MMS messaging.
Use it when you need imperative, event-driven control over calls rather than
the declarative AI agent approach.

The client supports two authentication modes: project ID + API token, or JWT
token. Credentials can be passed directly or read from environment variables.

## **Properties**

<ParamField path="project" type="string" toc={true}>
  SignalWire project ID. Set via constructor or `SIGNALWIRE_PROJECT_ID` environment variable.
</ParamField>

<ParamField path="token" type="string" toc={true}>
  API token for authentication. Set via constructor or `SIGNALWIRE_TOKEN` environment variable.
</ParamField>

<ParamField path="jwtToken" type="string" toc={true}>
  JWT token for alternative authentication. Read from the `SIGNALWIRE_JWT_TOKEN` environment variable.
  When provided, `project` and `token` are not required.
</ParamField>

<ParamField path="host" type="string" toc={true}>
  SignalWire space hostname (e.g., `your-space.signalwire.com`). Set via constructor or `SIGNALWIRE_SPACE`
  environment variable. Defaults to `relay.signalwire.com`.
</ParamField>

<ParamField path="contexts" type="string[]" toc={true}>
  List of contexts to subscribe to for inbound call and message events.
</ParamField>

<ParamField path="relayProtocol" type="string" toc={true}>
  Server-assigned protocol string from the connect response. Read-only. Used internally
  for session resumption on reconnect.
</ParamField>

## **Methods**

<CardGroup cols={3}>
  <Card title="onCall" href="/docs/server-sdks/reference/typescript/relay/client/on-call">
    Register an inbound call handler.
  </Card>

  <Card title="onMessage" href="/docs/server-sdks/reference/typescript/relay/client/on-message">
    Register an inbound message handler.
  </Card>

  <Card title="connect" href="/docs/server-sdks/reference/typescript/relay/client/connect">
    Establish the WebSocket connection and authenticate.
  </Card>

  <Card title="disconnect" href="/docs/server-sdks/reference/typescript/relay/client/disconnect">
    Close the WebSocket connection cleanly.
  </Card>

  <Card title="run" href="/docs/server-sdks/reference/typescript/relay/client/run">
    Start the client with automatic reconnection.
  </Card>

  <Card title="dial" href="/docs/server-sdks/reference/typescript/relay/client/dial">
    Initiate an outbound call.
  </Card>

  <Card title="sendMessage" href="/docs/server-sdks/reference/typescript/relay/client/send-message">
    Send an outbound SMS or MMS message.
  </Card>

  <Card title="receive" href="/docs/server-sdks/reference/typescript/relay/client/receive">
    Subscribe to additional contexts for inbound events.
  </Card>

  <Card title="unreceive" href="/docs/server-sdks/reference/typescript/relay/client/unreceive">
    Unsubscribe from inbound event contexts.
  </Card>

  <Card title="execute" href="/docs/server-sdks/reference/typescript/relay/client/execute">
    Send a raw JSON-RPC request to RELAY.
  </Card>
</CardGroup>

## **Example**

```typescript {3}
import { RelayClient } from '@signalwire/sdk';

const client = new RelayClient({
  project: process.env.SIGNALWIRE_PROJECT_ID!,
  token: process.env.SIGNALWIRE_TOKEN!,
  contexts: ['default']
});

client.onCall(async (call) => {
  await call.answer();
  const action = await call.play([{ type: 'tts', text: 'Hello from RELAY!' }]);
  await action.wait();
  await call.hangup();
});

client.onMessage(async (message) => {
  console.log(`SMS from ${message.fromNumber}: ${message.body}`);
});

await client.run();
```