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

# Node.js SDK

> The official Routa client for TypeScript and JavaScript: installation, first send, requirements and what is not supported yet.

`@routa-chat/sdk` is the official Routa SDK for Node.js. It gives you a typed client to send WhatsApp messages, create templates and receive delivery events, with retries, idempotency and webhook verification included. The current version is **0.5.0**. If you come from an earlier version, see [Upgrade the SDK](https://docs.routa.chat/en/sdk/upgrading.md).

> [card] Strict types
>
> Types for every request and response, with *branded* IDs that keep you from swapping a channel for a message.

> [card] Safe retries
>
> Exponential backoff with jitter, respect for `Retry-After` and an automatic `Idempotency-Key`.

> [card] No dependencies
>
> Uses the platform's `fetch` and Web Crypto. ESM and CommonJS, with type declarations.

## Requirements

Node.js **22 or later** (`engines.node` is `>=22`). The package ships ESM and CommonJS builds, so it works with `import` and with `require`.

## Installation

```bash npm theme={null}
npm install @routa-chat/sdk
```

```bash pnpm theme={null}
pnpm add @routa-chat/sdk
```

```bash yarn theme={null}
yarn add @routa-chat/sdk
```

## First send

```ts theme={null}
import { Routa } from '@routa-chat/sdk'

const routa = new Routa({ apiKey: process.env['ROUTA_API_KEY']! })

const message = await routa.messages.send({
  channel: 'chan_...', // a channel connected in the Routa dashboard
  to: '+5581999999999', // recipient in E.164; the leading + is optional
  text: 'Hi! Your order is confirmed.',
})

console.log(message.id, message.status) // "msg_...", "accepted"
```

`status: 'accepted'` means Routa received the message, **not** that it reached the recipient. Delivery is asynchronous: the message moves on to `sent`, `delivered` and `read` (or `failed`), and you follow each step through [webhooks](https://docs.routa.chat/en/sdk/webhooks.md) or `routa.events.list()`.

To send an approved template instead of free-form text, pass `template` instead of `text`:

```ts theme={null}
await routa.messages.send({
  channel: 'chan_...',
  to: '+5581999999999',
  template: { id: 'tmpl_...', bodyParameters: ['Ana', '1234'] },
})
```

`text` and `template` are mutually exclusive: passing both is a compile error. A template with a variable in the header or in a button, or with a media header, [asks for more than `bodyParameters`](https://docs.routa.chat/en/sdk/messages#send-a-template).

## Authentication

The client sends the key as `Authorization: Bearer <key>`. Create keys in the dashboard, on the **API keys** page, in the **Developer** group of the sidebar. The SDK **does not read environment variables on its own**: pass the value explicitly.

```ts theme={null}
import { Routa } from '@routa-chat/sdk'

const apiKey = process.env['ROUTA_API_KEY']
if (!apiKey) {
  throw new Error('ROUTA_API_KEY is not set')
}

const routa = new Routa({ apiKey })
```

`new Routa('rt_live_...')` is a shortcut for `new Routa({ apiKey: 'rt_live_...' })`. An empty key throws right away, on construction, not on the first request. A partner key (`rt_partner_...`) is also refused on construction: use [`RoutaPartner`](https://docs.routa.chat/en/sdk/partner) with it.

To check a key with no side effects, call `routa.whoami()`:

```ts theme={null}
const { organizationId, projectId, scopes } = await routa.whoami()
```

See more in [API keys](https://docs.routa.chat/en/authentication.md).

## Client resources

| Namespace | Operations |
| - | - |
| `routa.messages` | `send`, `retrieve`, `list`, `markRead`. See [Messages](https://docs.routa.chat/en/sdk/messages.md). |
| `routa.webhooks` | `create`, `list`, `retrieve`, `update`, `enable`, `disable`, `rotateSecret`, `constructEvent` and `deliveries`. See [Webhooks](https://docs.routa.chat/en/sdk/webhooks.md). |
| `routa.events` | `list`. See [Events, templates, media and usage](https://docs.routa.chat/en/sdk/resources.md). |
| `routa.templates` | `submit`, `uploadMedia`, `retrieve`, `list`. See [Templates](https://docs.routa.chat/en/sdk/templates.md). |
| `routa.media` | `upload`, `retrieve`. See [Media](https://docs.routa.chat/en/sdk/media.md). |
| `routa.usage` | `retrieve`. |
| `routa.whoami()` | Identity of the key. |

The [Partner API](https://docs.routa.chat/en/partners/overview.md) has a separate client, `RoutaPartner`, in `@routa-chat/sdk/partner`. It is **experimental**. See [Partners](https://docs.routa.chat/en/sdk/partner.md).

## Not supported yet

Know these gaps before you build on the SDK:

* **Sending media, location or reactions.** `messages.send()` accepts only `text` and `template`. A [file uploaded with `media.upload()`](https://docs.routa.chat/en/sdk/media) can be the media header of a template, but not a media message. Inbound and historical messages of these types can be read, but not sent.
* **Editing, deleting or syncing templates.** The SDK creates, retrieves and lists templates. Changing or removing a template is only possible in the dashboard: the API does not offer these operations to an API key.
* **Channels.** There is no `routa.channels` namespace. Connect and manage channels in the dashboard and pass the channel ID to `send()`. If you use the [Partner API](https://docs.routa.chat/en/sdk/partner.md), you list and delete disabled channels with `partner.channels`.

## Contributing

Issues and pull requests are welcome on [GitHub](https://github.com/routa-chat/routa-nodejs-sdk/issues). The SDK is distributed under the MIT license.


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