# Agent Quickstart

> The short version of the Sendable API for AI agents and LLM tools.

Source: https://wav1.recrav.com/docs/agents

Everything an agent needs to send and read WhatsApp messages through Sendable. Machine-readable sources:

* OpenAPI: `https://api.sendable.dev/openapi/json`. Every operation has a stable `operationId` (for example `sendMessage`, `listChatMessages`).
* MCP server: `https://api.sendable.dev/mcp` (hosted, streamable HTTP) or `npx -y @sendable-dev/mcp` (stdio). See [MCP Server](/docs/mcp).
* Docs index: [`/llms.txt`](/llms.txt). All docs in one file: [`/llms-full.txt`](/llms-full.txt). Any docs page as Markdown: add `.md` to its URL (this page is `/docs/agents.md`).

## 1. Get a key [#1-get-a-key]

Create a **session API key** in the dashboard (Session > API Keys). It acts on one linked WhatsApp number. Send it on every request:

```http
x-api-key: <your session key>
```

`401` means the key is missing, invalid, disabled, or expired. Do not retry a `401`. Give agent keys only the [permissions](/docs/learn/api-keys#permissions) they need, for example the Send only set (`message:write`, `media:write`, `chats:read`, `contacts:read`); a missing permission returns `403` with `"error": "insufficient_scope"` and the `required` permission.

## 2. Send a message [#2-send-a-message]

```bash
curl https://api.sendable.dev/v1/message/send \
  -H "x-api-key: $SENDABLE_API_KEY" \
  -H "content-type: application/json" \
  -H "Idempotency-Key: order-123-notify" \
  -d '{ "chatId": "6281234567890@s.whatsapp.net", "text": { "content": "Your order has shipped" } }'
```

* `chatId` is a full jid: `<phone>@s.whatsapp.net` for people, `<id>@g.us` for groups.
* The response has `messageId`. With `"async": true` the send is queued and the `202` response has a `runId` for `GET /v1/message/delivery-status/{runId}`.
* Always send an `Idempotency-Key` (1-128 printable characters, unique per logical message). Retrying with the same key and body returns the first response with `Idempotent-Replayed: true` and never sends twice. The same key with a different body returns `422`; a retry while the first request still runs returns `409`.

## 3. Read messages [#3-read-messages]

```bash
curl "https://api.sendable.dev/v1/chats?limit=20" -H "x-api-key: $SENDABLE_API_KEY"
curl "https://api.sendable.dev/v1/chats/6281234567890%40s.whatsapp.net/messages?limit=20" \
  -H "x-api-key: $SENDABLE_API_KEY"
```

Lists return `{ data, nextCursor }`; pass `nextCursor` back as `cursor`. URL-encode jids in paths.

## 4. Get new events [#4-get-new-events]

* **Webhooks** (push): register a URL with `POST /webhooks` and verify signatures. See [Webhooks](/docs/webhooks).
* **Polling** (pull): `GET /v1/events?type=message.created&limit=50` returns events newest first (incoming and outgoing messages). Poll the first page and stop at the last event `id` you processed.

## 5. Limits and errors [#5-limits-and-errors]

* Each key may make 500 requests per hour. Responses carry `RateLimit-Limit`, `RateLimit-Remaining`, and `RateLimit-Reset`.
* On `429`, wait `Retry-After` seconds, then retry. Sends are also paced per number (a gap of a few seconds, optional daily cap and quiet hours). See [Rate Limits](/docs/rate-limits).
* JSON errors look like `{ "error": "<code>", "message": "..." }`; some errors are plain text. Retry `429`, `502`, `503`, and `5xx` with backoff; fix the request on other `4xx`. See [Errors](/docs/errors).

## SDK [#sdk]

```typescript
import { Sendable } from '@sendable-dev/sdk'

const sendable = new Sendable({ apiKey: process.env.SENDABLE_API_KEY!, apiKeyScope: 'session' })
await sendable.messages.send(
  { chatId: '6281234567890@s.whatsapp.net', text: { content: 'Hello' } },
  { idempotencyKey: 'hello-1' },
)
```
