> ## 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.

# Send a text message

> Send text over WhatsApp with POST /v1/messages, use idempotency and metadata and handle the responses.

`POST /v1/messages` sends a message through a channel. This guide covers sending text. For templates, see [Send a template](https://docs.routa.chat/en/guides/send-template-message.md).

> [!NOTE]
>
> Required scope: `messages:write`.

## Request

```bash cURL theme={null}
curl https://api.routa.chat/v1/messages \
  -H "Authorization: Bearer $ROUTA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 6f0a9d9e-3c1f-4e56-9a64-2b7f6a5c1d10" \
  -d '{
    "channel": "chan_01J8...",
    "to": "+5581999999999",
    "text": "Hi! Your order is confirmed.",
    "metadata": { "order_id": "1234" }
  }'
```

```ts Node.js 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_01J8...',
  to: '+5581999999999',
  text: 'Hi! Your order is confirmed.',
  metadata: { order_id: '1234' },
})
```

| Field | Required | Description |
| - | - | - |
| `channel` | Yes | Channel ID (`chan_...`). |
| `to` | Yes | Recipient in E.164, for example `+5581999999999`. The leading `+` is optional: `5581999999999` also works. |
| `text` | One of `text` and `template` | Message body, up to 4096 characters. |
| `template` | One of `text` and `template` | See [Send a template](https://docs.routa.chat/en/guides/send-template-message.md). |
| `metadata` | No | Up to 20 text key-value pairs, returned when you retrieve the message and in its events. |

Provide **one** of `text` and `template`. With neither, the API returns `422 content_rejected`.

> [!WARNING]
>
> Do not send both together. The API does not refuse the request: it sends the template and ignores `text`.

## Response

The API responds `202 Accepted` with the message in the `accepted` state:

```json theme={null}
{
  "id": "msg_01J8ZK9M3Q7X...",
  "channel": "chan_01J8...",
  "direction": "outbound",
  "origin": "api",
  "from": "+5581988888888",
  "to": "+5581999999999",
  "content": { "type": "text", "body": "Hi! Your order is confirmed." },
  "content_redacted_at": null,
  "status": "accepted",
  "failure_code": null,
  "metadata": { "order_id": "1234" },
  "accepted_at": "2026-09-04T13:22:40.812Z",
  "sent_at": null,
  "delivered_at": null,
  "read_at": null,
  "failed_at": null
}
```

Store the `id`. It is the key to retrieve the message and to correlate delivery events. Every response also carries the `Routa-Request-Id` header; quote it when you contact support.

## Avoid duplicates

If the network fails after you send the request, you do not know whether it arrived. Resending carelessly could create two messages. To avoid that, send a unique `Idempotency-Key` per logical message:

* Use a UUID v4 and generate it **once**, before the first attempt. Reuse the same key on every retry.
* A second request with the same key and the same body returns the original response, with the `Idempotent-Replay: true` header.
* Reusing the key with a different body returns `409 idempotency_key_reuse`.

The SDK generates and reuses the key automatically. Details in [Idempotency](https://docs.routa.chat/en/reliability/idempotency.md).

## Common errors

| Status | Code | What to do |
| - | - | - |
| `401` | `api_key_invalid` | Check the key. See [Authentication](https://docs.routa.chat/en/authentication.md). |
| `402` | `message_quota_exceeded` | The allowance for the period is used up. See [Plans and allowance](https://docs.routa.chat/en/billing/plans-and-quota.md). |
| `403` | `insufficient_scope` | The key lacks `messages:write`. |
| `404` | `channel_not_found` | The channel does not exist in this project. |
| `409` | `idempotency_in_progress` | An identical request is in progress. Try again after `Retry-After`. |
| `422` | `channel_inactive` | The channel is not `active`. |
| `422` | `request_invalid` | A field is missing or has the wrong format. `error.param` says which one. |
| `422` | `invalid_recipient` | The number does not exist in its country. |
| `422` | `content_rejected` | Invalid content, such as an empty `text` or neither `text` nor `template`. |
| `429` | `rate_limit_exceeded` | Rate limit. Wait for `Retry-After`. |
| `429` | `channel_backlog_exceeded` | The channel has a send queue above its capacity. Try again in a moment. |

See [Errors](https://docs.routa.chat/en/errors/overview.md) for the full format.

## Next step

The message was **accepted**, not delivered. [Track delivery](https://docs.routa.chat/en/guides/track-delivery.md) with webhooks.


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