# Authentication

- Page: https://bytesms.com/docs/authentication (markdown: https://bytesms.com/docs/authentication.md)
- API base URL: https://api.bytesms.com/api (public resources under /api/v1)
- Auth: `Authorization: Bearer tp_live_…` — an API key from Dashboard → API Keys; keep it server-side (e.g. `BYTESMS_API_KEY`)
- All docs in one file: https://bytesms.com/llms-full.txt · OpenAPI 3.1: https://bytesms.com/openapi.json

Authenticate Bytesms API requests with Bearer API keys: full access, sending access and domain-scoped keys.

## Bearer API keys

Authenticate every `/api/v1` request with an API key in the `Authorization` header. Keys start with `tp_live_`; the header must be exactly `Bearer tp_live_…`.

**Header**

```
Authorization: Bearer tp_live_xxxxxxxxxxxxxxxxxxxxxxxx
```

Create keys in **Dashboard → API Keys** or with [POST /v1/api-keys](https://bytesms.com/docs/api-keys). The full key is shown only once; Bytesms stores a hash, and the dashboard shows only the prefix. A key always acts on the workspace it was created in.

A missing, malformed, unknown or expired key is rejected with 401:

**Response**

```json
{
  "statusCode": 401,
  "message": "Invalid API key",
  "name": "unauthorized"
}
```

## Permissions

| Permission | Can call | Typical use |
| --- | --- | --- |
| `full_access` | Every /v1 endpoint: emails, domains, API keys, templates, audiences, contacts, broadcasts, WhatsApp. | Back-office scripts, infrastructure automation. |
| `sending_access` | Only the send endpoints: `POST /v1/emails`, `POST /v1/emails/batch` (and the legacy `POST /v1/emails/send`), plus every [WhatsApp](https://bytesms.com/docs/whatsapp) endpoint (`/v1/whatsapp/*`) — unless the key is domain-scoped (below). | Application servers that only send mail or WhatsApp messages. |

A `sending_access` key calling any other endpoint (for example `GET /v1/emails/:id` or `GET /v1/domains`) gets `401 restricted_api_key`:

**Response**

```json
{
  "statusCode": 401,
  "message": "This API key is restricted to only send emails.",
  "name": "restricted_api_key"
}
```

## Domain-scoped keys

A `sending_access` key can additionally be restricted to one domain (`domain_id` when creating it). It may then only send from addresses on that domain; anything else is `403 restricted_api_key`. A key created with a `domain_id` and no permission defaults to `sending_access`; `full_access` together with a domain is refused. If the domain is later deleted, the key stops working for sending (fail-closed) — create a new one.

A domain-scoped key is an email-only credential (it is the one to hand to an SMTP client): it can't spend the workspace's prepaid credit on WhatsApp. Every `/v1/whatsapp/*` request with it is refused with `403 restricted_api_key`:

**Response**

```json
{
  "statusCode": 403,
  "name": "restricted_api_key",
  "message": "This API key is restricted to a single sending domain and cannot use the WhatsApp API. Use an API key without a domain restriction."
}
```

## Suspended keys

A key can be suspended by the Bytesms team (for example after abuse reports). Every request with it is refused with `403 suspended_api_key` and a reason in `message`.

## Other surfaces

- [SMTP](https://bytesms.com/docs/smtp) — username `bytesms`, password = an API key (its permission and domain scope apply).
- [MCP server](https://bytesms.com/docs/mcp) — an API key as Bearer token, or OAuth 2.1 (scopes `full` / `sending`).

> **Warning: Treat keys like passwords**
>
> Keep keys server-side, rotate them by creating a new key and deleting the old one, and prefer a domain-scoped `sending_access` key for application servers.
