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

# Client SDKs

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

Install `@relaymessenger/sdk` (TypeScript) or `relaymessenger` (Python) in your backend to call the Relay API through one client. Both SDKs use an Agent Token; CLI or Console account sign-in is not a substitute. To get the token, read [use the token in your code](https://docs.staging.relayapp.im/agents/create-agent.md#use-the-token-in-your-code).

## Install

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

```bash Python theme={null}
pip install "git+https://github.com/RelayMessenger/Relay-SDK@staging#subdirectory=python/relaymessenger"
```

The Python SDK installs from the Relay SDK repository, needs Python 3.10 or newer, and its methods are `async`. It covers chats (`relay.chats.create`, `retrieve`, `list_chats`, `messages.list`, `messages.send`) and events over the [WebSocket](https://docs.staging.relayapp.im/websocket.md) (`relay.websocket.run`). To verify webhook signatures, use the TypeScript SDK or [verify them yourself](https://docs.staging.relayapp.im/webhooks/verify-signatures.md).

## Create a client

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

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

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

```python Python theme={null}
import os

from relaymessenger import Relay

relay = Relay(os.environ["RELAY_AGENT_TOKEN"], base_url=os.environ["RELAY_API_URL"])
```

## Make a request

Read one page of Chats:

```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"
```

## 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](https://docs.staging.relayapp.im/live/authentication.md)
* [Send your first API Message](https://docs.staging.relayapp.im/start/build-on-the-api.md)
* [Handle SDK errors](https://docs.staging.relayapp.im/live/errors.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.