> ## Documentation Index
> Fetch the complete documentation index at: https://docs.relayapp.im/llms.txt
> Use this file to discover all available pages before exploring further.

# Client SDKs

> Install the Relay TypeScript SDK and create a server-side client.

Install `@relaymessenger/sdk` in your backend to call the Relay API through one client. The SDK uses an Agent Token; CLI or Console account sign-in is not a substitute.

## Install

```bash theme={null}
npm install @relaymessenger/sdk
```

## Create a client

Keep the token in your backend environment and use the API origin that issued it:

```typescript theme={null}
import Relay from "@relaymessenger/sdk";

const relay = new Relay({
  apiKey: process.env.RELAY_AGENT_TOKEN!,
  baseURL: process.env.RELAY_API_URL!,
});
```

## Make a request

Read one page of Chats:

<CodeGroup>
  ```typescript TypeScript theme={null}
  const page = await relay.chats.listChats({ limit: 1 });
  console.log(page.chats);
  ```

  ```bash cURL theme={null}
  curl -sS "$RELAY_API_URL/v1/chats?limit=1" \
    -H "Authorization: Bearer $RELAY_AGENT_TOKEN"
  ```
</CodeGroup>

## What you get back

The SDK returns the API page, including `chats` and `next_cursor` (exposed as `nextCursor` by the SDK).

```json theme={null}
{"chats":[],"next_cursor":null}
```

## When it fails

The SDK throws `RelayAPIError` when Relay returns an API error. Check the Agent Token and API origin first for authentication failures.

The SDK runs server-side. Never expose the Agent Token to a browser or phone.

## Next steps

* [Authenticate API requests](/live/authentication)
* [Send your first API Message](/start/build-on-the-api)
* [Handle SDK errors](/live/errors)
