# Bytesms documentation (full) > Every page of https://bytesms.com/docs as markdown, in navigation order. Index: https://bytesms.com/llms.txt. OpenAPI 3.1: https://bytesms.com/openapi.json. Bytesms (bytesms.com) is an email API for developers in Thailand and Southeast Asia — transactional email, marketing broadcasts and WhatsApp OTP. It is not an SMS provider. API base URL: https://api.bytesms.com/api; auth header `Authorization: Bearer tp_live_…`. --- # Introduction - Page: https://bytesms.com/docs (markdown: https://bytesms.com/docs.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 Bytesms is an email API for developers. Send transactional email from your code, send marketing broadcasts to audiences, and track every message with delivery events and webhooks — over a REST API, SMTP or an MCP server for AI agents. ## Base URL Every REST endpoint lives under the `/api` prefix of the API host. The public, API-key authenticated resources are under `/api/v1`: **cURL** ```bash # All requests go to curl -X GET 'https://api.bytesms.com/api/v1/domains' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' ``` **Node.js** ```js // All requests go to const res = await fetch("https://api.bytesms.com/api/v1/domains", { method: "GET", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", }, }); console.log(await res.json()); ``` **Python** ```python import requests # All requests go to res = requests.get( "https://api.bytesms.com/api/v1/domains", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, ) print(res.json()) ``` The base URL is `https://api.bytesms.com/api`. Requests and responses are JSON (`Content-Type: application/json`); timestamps are ISO 8601 strings in UTC. The API is Resend-style — field names are snake_case, list responses are `{ object: "list", has_more, data }` and the Node.js and Python Resend SDKs can send through it (see [Quickstart](https://bytesms.com/docs/quickstart#resend-sdk)) — but only the parameters documented here are accepted. ## What you can do - [Quickstart](https://bytesms.com/docs/quickstart): API key → verified domain → first email. - [Emails](https://bytesms.com/docs/emails): Send, batch, schedule, retrieve and cancel. - [Domains](https://bytesms.com/docs/domains): DKIM, return path, SPF and DMARC setup. - [Webhooks](https://bytesms.com/docs/webhooks): Delivery events with signed payloads. - [Templates](https://bytesms.com/docs/templates): Reusable content with variables. - [Broadcasts](https://bytesms.com/docs/broadcasts): Marketing email to an audience. - [WhatsApp](https://bytesms.com/docs/whatsapp): OTP verification and template messages. - [SMTP](https://bytesms.com/docs/smtp): Send from any SMTP-capable app or library. - [MCP server](https://bytesms.com/docs/mcp): Let AI agents send and manage domains. - [AI assistants](https://bytesms.com/docs/ai): Copy-paste prompt, markdown docs, MCP setup. ## Key concepts - **Workspace** — everything (API keys, domains, emails, audiences, billing) belongs to a workspace. An API key always acts on the workspace that created it. - **Domain** — you send from addresses on a domain you have verified in the workspace. Until then you can send from `onboarding@mail.bytesms.com` to your own account email only. - **Email** — one message with up to 50 recipients across `to`, `cc` and `bcc`. Quotas count recipients, not API calls. - **Events** — each email moves through `email.sent`, `email.delivered`, `email.bounced`, … which you can poll or receive by [webhook](https://bytesms.com/docs/webhooks). ## Machine-readable docs - [OpenAPI 3.1 spec](https://bytesms.com/openapi.json) of the public `/v1` API, including webhook payload schemas. - [llms.txt](https://bytesms.com/llms.txt): a short index of these docs for AI agents. - [llms-full.txt](https://bytesms.com/llms-full.txt): every page as one markdown file. Each page is also available on its own at `/docs/.md`, e.g. [/docs/emails.md](https://bytesms.com/docs/emails.md). - Using ChatGPT, Claude or Cursor? See [AI assistants](https://bytesms.com/docs/ai) for a copy-paste prompt and MCP setup. > **Note: Testing without a domain** > > Send to `delivered@test.bytesms.com`, `bounced@test.bytesms.com`, `complained@test.bytesms.com` or `suppressed@test.bytesms.com` (a `+label` is allowed) to simulate each outcome. Test addresses are always allowed as recipients, never reach a real mailbox, and still fire the matching events and webhooks. --- # Quickstart - Page: https://bytesms.com/docs/quickstart (markdown: https://bytesms.com/docs/quickstart.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 Create a Bytesms API key, send a test email, verify a domain and send your first real email — with cURL, Node.js, Python, PHP, Go and SMTP examples. ## 1. Create an API key [Sign up](https://bytesms.com/signup), open **Dashboard → API Keys** and create a key. Keys start with `tp_live_` and are shown once — store it in a secret manager or an environment variable such as `BYTESMS_API_KEY`. See [Authentication](https://bytesms.com/docs/authentication) for the permission levels. ## 2. Send a test email right away Before you verify a domain you can already send from `onboarding@mail.bytesms.com` but only to your own account email and to the `@test.bytesms.com` test addresses: **cURL** ```bash # Send a test email curl -X POST 'https://api.bytesms.com/api/v1/emails' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d '{"from":"Bytesms ","to":["delivered@test.bytesms.com"],"subject":"Hello from Bytesms","html":"

It works!

"}' ``` **Node.js** ```js // Send a test email const res = await fetch("https://api.bytesms.com/api/v1/emails", { method: "POST", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", "Content-Type": "application/json", }, body: JSON.stringify({ "from": "Bytesms ", "to": [ "delivered@test.bytesms.com" ], "subject": "Hello from Bytesms", "html": "

It works!

" }), }); console.log(await res.json()); ``` **Python** ```python import requests # Send a test email res = requests.post( "https://api.bytesms.com/api/v1/emails", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, json={ "from": "Bytesms ", "to": [ "delivered@test.bytesms.com" ], "subject": "Hello from Bytesms", "html": "

It works!

" }, ) print(res.json()) ``` **PHP** ```php "POST", CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ["Authorization: Bearer tp_live_xxxxxxxxx", "Content-Type: application/json"], CURLOPT_POSTFIELDS => json_encode([ 'from' => 'Bytesms ', 'to' => [ 'delivered@test.bytesms.com', ], 'subject' => 'Hello from Bytesms', 'html' => '

It works!

', ]), ]); $response = curl_exec($ch); echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $response, PHP_EOL; ``` **Go** ```go package main import ( "bytes" "fmt" "io" "net/http" ) func main() { // Send a test email body := []byte(`{"from":"Bytesms ","to":["delivered@test.bytesms.com"],"subject":"Hello from Bytesms","html":"

It works!

"}`) req, err := http.NewRequest("POST", "https://api.bytesms.com/api/v1/emails", bytes.NewReader(body)) if err != nil { panic(err) } req.Header.Set("Authorization", "Bearer tp_live_xxxxxxxxx") req.Header.Set("Content-Type", "application/json") res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() out, _ := io.ReadAll(res.Body) fmt.Println(res.Status, string(out)) } ``` **Response** ```json { "id": "cmg4k2x7a0001l8v9h3q2d5rt" } ``` ## 3. Add and verify your domain To send to anyone else, add a domain you own. Use a subdomain such as `mail.example.com` if you want to keep sending reputation separate from your root domain. **cURL** ```bash # Add a domain curl -X POST 'https://api.bytesms.com/api/v1/domains' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d '{"name":"example.com"}' ``` **Node.js** ```js // Add a domain const res = await fetch("https://api.bytesms.com/api/v1/domains", { method: "POST", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", "Content-Type": "application/json", }, body: JSON.stringify({ "name": "example.com" }), }); console.log(await res.json()); ``` **Python** ```python import requests # Add a domain res = requests.post( "https://api.bytesms.com/api/v1/domains", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, json={ "name": "example.com" }, ) print(res.json()) ``` The response lists the DNS records to publish at your DNS provider — a DKIM `TXT` record and a return-path `CNAME` (plus recommended SPF and DMARC records). After publishing them, trigger a check: **cURL** ```bash # Verify the domain curl -X POST 'https://api.bytesms.com/api/v1/domains/{domain_id}/verify' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' ``` **Node.js** ```js // Verify the domain const res = await fetch("https://api.bytesms.com/api/v1/domains/{domain_id}/verify", { method: "POST", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", }, }); console.log(await res.json()); ``` **Python** ```python import requests # Verify the domain res = requests.post( "https://api.bytesms.com/api/v1/domains/{domain_id}/verify", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, ) print(res.json()) ``` Verification is also re-checked automatically every few minutes; the domain moves from `pending` to `verified` once the DKIM record and the return path (or SPF) resolve. Details: [Domains](https://bytesms.com/docs/domains). ## 4. Send your first real email **cURL** ```bash # Send an email curl -X POST 'https://api.bytesms.com/api/v1/emails' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d '{"from":"Acme ","to":["customer@gmail.com"],"subject":"Welcome to Acme","html":"

Welcome!

Thanks for signing up.

"}' ``` **Node.js** ```js // Send an email const res = await fetch("https://api.bytesms.com/api/v1/emails", { method: "POST", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", "Content-Type": "application/json", }, body: JSON.stringify({ "from": "Acme ", "to": [ "customer@gmail.com" ], "subject": "Welcome to Acme", "html": "

Welcome!

Thanks for signing up.

" }), }); console.log(await res.json()); ``` **Python** ```python import requests # Send an email res = requests.post( "https://api.bytesms.com/api/v1/emails", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, json={ "from": "Acme ", "to": [ "customer@gmail.com" ], "subject": "Welcome to Acme", "html": "

Welcome!

Thanks for signing up.

" }, ) print(res.json()) ``` ## 5. Track what happens 1. Poll `GET /api/v1/emails/{id}` — its `last_event` becomes `sent`, then `delivered` (or `bounced`). 2. Or add a [webhook endpoint](https://bytesms.com/docs/webhooks) and receive `email.delivered`, `email.bounced` and the other events as they happen. ## Other ways to send ### Bytesms SDK for TypeScript and JavaScript The official [@bytesms/sdk](https://www.npmjs.com/package/@bytesms/sdk) package wraps the REST API with types, `{ data, error }` results, idempotency keys, automatic retries and webhook verification. It runs on Node.js 18+, Bun, Deno and edge runtimes. Details: [TypeScript SDK](https://bytesms.com/docs/sdk). **Bytesms SDK (Node.js)** ```ts // npm install @bytesms/sdk import { Bytesms } from "@bytesms/sdk"; const bytesms = new Bytesms(process.env.BYTESMS_API_KEY); const { data, error } = await bytesms.emails.send( { from: "Acme ", to: "delivered@test.bytesms.com", subject: "Hello from Bytesms", html: "

It works!

", }, { idempotencyKey: "hello-1" }, ); console.log(data ?? error); ``` ### SMTP Any SMTP client works: host `smtp.bytesms.com`, port `465` (TLS) or `587` (STARTTLS), username `bytesms`, password = your API key. The same sending rules and quotas apply; attachments are rejected. Details: [SMTP](https://bytesms.com/docs/smtp). **Nodemailer (SMTP)** ```js import nodemailer from "nodemailer"; const transporter = nodemailer.createTransport({ host: "smtp.bytesms.com", port: 465, secure: true, // implicit TLS; use port 587 with secure: false for STARTTLS auth: { user: "bytesms", pass: process.env.BYTESMS_API_KEY }, }); const info = await transporter.sendMail({ from: "Acme ", to: "delivered@test.bytesms.com", subject: "Hello from Bytesms", html: "

It works!

", }); console.log(info.messageId); ``` **Laravel .env** ```ini MAIL_MAILER=smtp MAIL_HOST=smtp.bytesms.com MAIL_PORT=587 MAIL_USERNAME=bytesms MAIL_PASSWORD=tp_live_xxxxxxxxx # Laravel 10 and older; Laravel 11+ negotiates STARTTLS on 587 by itself MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=hello@example.com MAIL_FROM_NAME="${APP_NAME}" ``` ### Resend SDKs The REST API is Resend-style, so the official `resend` SDKs for Node.js and Python can send through Bytesms when you point them at `https://api.bytesms.com/api/v1`. We tested sending, batch sending, retrieving an email, listing domains and error handling. Only the parameters documented here are accepted, and attachments are not supported. Other Resend SDKs and Resend endpoints that aren't in these docs are untested, so for other languages call the REST API directly (the PHP and Go tabs above). **Resend SDK (Node.js)** ```js import { Resend } from "resend"; // resend >= 6: pass baseUrl. Any version: set RESEND_BASE_URL=https://api.bytesms.com/api/v1 instead. const resend = new Resend(process.env.BYTESMS_API_KEY, { baseUrl: "https://api.bytesms.com/api/v1" }); const { data, error } = await resend.emails.send({ from: "Acme ", to: ["delivered@test.bytesms.com"], subject: "Hello from Bytesms", html: "

It works!

", }); console.log(data ?? error); ``` **Resend SDK (Python)** ```python import os import resend resend.api_key = os.environ["BYTESMS_API_KEY"] resend.api_url = "https://api.bytesms.com/api/v1" # or set RESEND_API_URL email = resend.Emails.send({ "from": "Acme ", "to": ["delivered@test.bytesms.com"], "subject": "Hello from Bytesms", "html": "

It works!

", }) print(email["id"]) ``` > **Warning: Keep keys on the server** > > Never ship an API key in browser or mobile code. For a key that can only send (and only from one domain), create a [sending-access key](https://bytesms.com/docs/authentication#permissions). --- # AI assistants - Page: https://bytesms.com/docs/ai (markdown: https://bytesms.com/docs/ai.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 Use Bytesms from ChatGPT, Claude, Cursor or any coding assistant: a copy-paste integration prompt, markdown docs, llms-full.txt and the MCP server. AI coding assistants often don't know Bytesms yet, and a web search for the name can turn up unrelated SMS providers. Give your assistant the facts directly, either by pasting the prompt below or by connecting the Bytesms [MCP server](https://bytesms.com/docs/mcp), and it can write a correct integration on the first try. ## Copy-paste prompt Paste this into ChatGPT, Claude, Cursor, Copilot, Gemini or any other assistant, then replace the last line with your task. It covers the base URL, the auth header, a working `POST /v1/emails` body, the test addresses and where the full docs live. **Prompt for your AI assistant** ``` I want to send email with Bytesms (https://bytesms.com). Bytesms is an email API for developers (transactional + marketing email, plus WhatsApp OTP) — it is NOT an SMS provider. Facts you need: - Base URL: https://api.bytesms.com/api (public endpoints are under /api/v1) - Auth header: Authorization: Bearer . Keys start with tp_live_. Read the key from the environment variable BYTESMS_API_KEY and only use it server-side (never in browser or mobile code). - Send an email: POST https://api.bytesms.com/api/v1/emails with a JSON body such as {"from": "Acme ", "to": ["user@example.com"], "subject": "Hello", "html": "

It works!

"} The response is 200 {"id": "..."}. Optional fields: text, cc, bcc (max 50 recipients in total), reply_to, headers, tags, scheduled_at, template {id, variables}. Send an Idempotency-Key header to make retries safe. Attachments are not supported. - "from" must be on a domain verified in the Bytesms workspace. Before that, use onboarding@mail.bytesms.com, which can only send to your own account email and test addresses. - Test recipients (no real mailbox, real events and webhooks): delivered@test.bytesms.com, bounced@test.bytesms.com, complained@test.bytesms.com, suppressed@test.bytesms.com - Errors are JSON {"statusCode", "message", "name"}; 429 means a rate limit (10 requests/second per workspace by default) or a quota. - SMTP is also available: smtp.bytesms.com, port 465 (TLS) or 587 (STARTTLS), username "bytesms", password = the API key. Full documentation as markdown: https://bytesms.com/llms-full.txt (index: https://bytesms.com/llms.txt, OpenAPI 3.1: https://bytesms.com/openapi.json, any single page: https://bytesms.com/docs/.md). Read it before writing code, and use only the fields documented there. Task: ``` ## Docs in markdown Every docs page has a markdown version, generated from the same source as the HTML page, so the two always match: - [/llms-full.txt](https://bytesms.com/llms-full.txt): all docs in one markdown file. Give an assistant this URL (or its contents) for a complete reference. - [/llms.txt](https://bytesms.com/llms.txt): a short index in the [llms.txt](https://llmstxt.org)format, with a link to each page's markdown. - `/docs/.md`: one page, e.g. [/docs/emails.md](https://bytesms.com/docs/emails.md). Every page also has **Copy for LLM**, **View as Markdown** and **Open in ChatGPT / Claude** buttons under its title. - [/openapi.json](https://bytesms.com/openapi.json): the OpenAPI 3.1 spec of the public `/v1` API, for tools that generate clients. ## Store the API key Create a key in **Dashboard → API Keys** and keep it in an environment variable. We suggest the name `BYTESMS_API_KEY`, which is the name the prompt above tells the assistant to read. For an agent that only needs to send, create a [sending-access key](https://bytesms.com/docs/authentication#permissions), optionally limited to one domain. **.env** ``` BYTESMS_API_KEY=tp_live_xxxxxxxxx ``` ## Connect the MCP server With the MCP server connected, the assistant calls Bytesms itself: it can send email, check delivery and manage domains and API keys, so you don't have to paste anything. The server is `https://api.bytesms.com/api/mcp`. It uses Streamable HTTP and signs you in with OAuth (the client opens a Bytesms consent screen where you pick the workspace and access level). Clients that can send custom headers can use an API key instead. The [MCP server](https://bytesms.com/docs/mcp) page has the tool list, scopes, more clients and the protocol details. ### With OAuth (recommended) **Claude Code** ```bash claude mcp add --transport http bytesms https://api.bytesms.com/api/mcp # then run /mcp inside Claude Code and sign in ``` **Claude Desktop** ``` Settings → Connectors → Add custom connector Name: Bytesms URL: https://api.bytesms.com/api/mcp Then click Connect and approve access on the Bytesms consent screen. ``` **Cursor** ```jsonc // ~/.cursor/mcp.json (or .cursor/mcp.json in the project) { "mcpServers": { "bytesms": { "url": "https://api.bytesms.com/api/mcp" } } } ``` **VS Code** ```jsonc // .vscode/mcp.json { "servers": { "bytesms": { "type": "http", "url": "https://api.bytesms.com/api/mcp" } } } ``` ### With an API key **Claude Code** ```bash claude mcp add --transport http bytesms https://api.bytesms.com/api/mcp \ --header "Authorization: Bearer $BYTESMS_API_KEY" ``` **Cursor** ```jsonc { "mcpServers": { "bytesms": { "url": "https://api.bytesms.com/api/mcp", "headers": { "Authorization": "Bearer ${env:BYTESMS_API_KEY}" } } } } ``` **VS Code** ```jsonc { "inputs": [ { "type": "promptString", "id": "bytesms-key", "description": "Bytesms API key", "password": true } ], "servers": { "bytesms": { "type": "http", "url": "https://api.bytesms.com/api/mcp", "headers": { "Authorization": "Bearer ${input:bytesms-key}" } } } } ``` Claude Desktop custom connectors sign in with OAuth only, so use the OAuth flow there. > **Warning: Agents act with your permissions** > > An agent with a full-access key or the `full` scope can create API keys and delete domains. Give it the `sending` scope or a sending-access key unless it really needs more, and test against `delivered@test.bytesms.com` first. --- # 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. --- # Errors - Page: https://bytesms.com/docs/errors (markdown: https://bytesms.com/docs/errors.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 The Bytesms error envelope ({ statusCode, message, name }) and every error name the API returns, with HTTP status codes. ## Error shape Every `/api/v1` error is JSON with the HTTP status, a human-readable `message` and a machine-readable `name`. Branch on `name` (and the status), never on `message`. **422 Unprocessable Entity** ```json { "statusCode": 422, "message": "`to` must contain at least one recipient.", "name": "validation_error" } ``` Some errors add fields. Quota errors (`daily_quota_exceeded`, `monthly_quota_exceeded`) and plan-limit errors (`plan_limit_exceeded`) carry the specific `code` plus `limit` and `current`. Other errors may include a `code` when one is available. `402 insufficient_credits` adds `neededThb` and `availableThb`. Treat every extra field as optional: **429 Too Many Requests** ```json { "statusCode": 429, "message": "Daily email limit reached (100/100). Try again tomorrow or upgrade your plan.", "name": "daily_quota_exceeded", "code": "daily_limit_reached", "limit": 100, "current": 100 } ``` **402 Payment Required** ```json { "statusCode": 402, "message": "Not enough prepaid credit. Top up (or turn on auto-recharge) in the dashboard under Settings → Billing.", "name": "insufficient_credits", "neededThb": 0.155, "availableThb": 0.04 } ``` Request-body validation failures (wrong types, invalid email addresses, unknown enum values) are returned as `422 validation_error` with the individual problems joined into `message`. ## Error names | Status | name | When | | --- | --- | --- | | 401 | `unauthorized` | Missing, malformed, unknown or expired API key. | | 401 | `restricted_api_key` | A sending_access key called an endpoint other than the email send and WhatsApp endpoints. | | 402 | `insufficient_credits` | The over-quota recipients (or a WhatsApp message) cost more than the workspace's prepaid credit, after auto-recharge. Body adds `neededThb` / `availableThb` — see [Credits & billing](https://bytesms.com/docs/credits). | | 403 | `restricted_api_key` | A domain-scoped key sent from another domain (or its domain was deleted), or called a /v1/whatsapp endpoint. | | 403 | `suspended_api_key` | The API key was suspended. | | 403 | `invalid_from_address` | The from domain is not a verified domain of this workspace (the workspace has other verified domains). | | 403 | `validation_error` | No verified domain yet, or `onboarding@mail.bytesms.com`used to send to anyone other than your own account email or a test address. Also returned when a domain's warm-up daily volume is used up. | | 403 | `sending_paused` | Sending is paused for the workspace (e.g. high bounce/complaint rate). | | 403 | `account_under_review` | The workspace is under review. | | 403 | `account_suspended` | The workspace is suspended. | | 403 | `subscription_past_due_expired`, `subscription_unpaid`, `subscription_incomplete`, `subscription_paused`, `subscription_canceled` | The paid subscription is not in good standing (past the payment grace period, unpaid, …). | | 403 | `plan_limit_exceeded` | A plan cap was hit; `code` says which: `api_key_limit_reached`, `domain_limit_reached`, `segment_limit_reached`, `contact_limit_reached`, `contact_limit_exceeded`, `webhook_limit_reached`, `member_limit_reached`. The body also carries `limit` (the plan cap) and `current` (the count when the request was made). | | 404 | `not_found` | The resource does not exist in this workspace (ids of other workspaces are 404 too). | | 409 | `idempotency_key_conflict` | The Idempotency-Key was already used with a different request body. | | 409 | `domain_in_use`, `domain_pending_elsewhere` | The domain is verified in another workspace, or claimed there within the last 72 hours. | | 409 | `validation_error` | Duplicate: a contact with this email already exists in the audience, a template alias is taken, a broadcast was already sent. | | 422 | `validation_error` | The request is invalid (see message). | | 422 | `invalid_idempotency_key` | The Idempotency-Key header is empty or longer than 256 characters. | | 422 | `attachments_not_supported` | The request contained attachments (not supported yet). | | 422 | `invalid_domain`, `reserved_domain` | Not a valid fully-qualified domain name, or a platform / consumer-mailbox domain that can't be added. | | 429 | `rate_limit_exceeded` | Too many requests per second — see [Rate limits](https://bytesms.com/docs/rate-limits). | | 429 | `daily_quota_exceeded` | The plan's daily email limit (recipients per UTC day) is used up. | | 429 | `monthly_quota_exceeded` | The plan's monthly quota is used up on a plan without overage (Free). Paid plans continue from prepaid credit. | | 5xx | `application_error` | Something went wrong on our side, or a sending server was unreachable. Retry with backoff. | ## Retrying Retry `429 rate_limit_exceeded` after the `retry-after` header and `5xx` errors with exponential backoff. Retry `402 insufficient_credits` once the workspace has topped up. When you retry a send, use an [Idempotency-Key](https://bytesms.com/docs/idempotency)so a request that actually succeeded is not sent twice. Don't retry other 4xx errors unchanged — they fail the same way. > **Note: Legacy endpoint** > > The legacy `POST /api/v1/emails/send` is not wrapped in this envelope: request-validation failures come back as `400` with `{ statusCode, message: string[], error }`, and it returns the full internal message row on success. New integrations should use `POST /api/v1/emails`. --- # Rate limits & quotas - Page: https://bytesms.com/docs/rate-limits (markdown: https://bytesms.com/docs/rate-limits.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 Bytesms per-workspace request rate limits, daily and monthly email quotas, and what happens over the quota (prepaid credit, 402 insufficient_credits). ## Request rate limit The public API allows **10 requests per second per workspace** by default. All API keys of a workspace share the same budget, and it covers every `/api/v1` endpoint, MCP `tools/call` requests and SMTP messages. Every `/api/v1` response carries the current state: **Response headers** ``` ratelimit-limit: 10 ratelimit-remaining: 7 ratelimit-reset: 1 ``` `ratelimit-reset` is the number of seconds until the window resets. Over the limit, the API answers `429 rate_limit_exceeded` with a `retry-after` header (seconds). Need more throughput? Use [batch sends](https://bytesms.com/docs/emails#batch) (up to 100 emails per request) or contact support. ## Email quotas Quotas count **recipients**, not API calls: an email to 3 addresses in `to` plus 2 in `cc` uses 5. Every accepted transactional email counts from the moment it is accepted (queued, scheduled, sent, delivered, bounced, …); only emails that end `failed` or `canceled`give their quota back. The check and the insert are atomic, so parallel requests can't overshoot. | Limit | Window | Error when exceeded | | --- | --- | --- | | Daily limit (e.g. 100/day on Free) | UTC calendar day | `429 daily_quota_exceeded` | | Monthly quota (e.g. 3,000 on Free) | Free: UTC calendar month. Paid: your billing period. | `429 monthly_quota_exceeded` | | Over-quota recipients on a paid plan, when the prepaid credit can't cover them | Per request | `402 insufficient_credits` | Plan limits are listed on the [pricing page](https://bytesms.com/pricing). Broadcast emails don't count toward the transactional quota — Marketing plans limit contacts instead (see [Broadcasts](https://bytesms.com/docs/broadcasts)). ### Over the monthly quota On Free, sending stops at the quota (`429 monthly_quota_exceeded`). On a paid plan, sending continues past the quota and every over-quota recipient is paid from the workspace's prepaid credit at the plan's per-recipient price — no bucket rounding (see [Credits & billing](https://bytesms.com/docs/credits)). When the credit can't cover a request (after auto-recharge, if it is on), the request is refused with `402 insufficient_credits`: **Response** ```json { "statusCode": 402, "message": "Not enough prepaid credit. Top up (or turn on auto-recharge) in the dashboard under Settings → Billing.", "name": "insufficient_credits", "neededThb": 0.155, "availableThb": 0.04 } ``` `neededThb` is what this request would cost, `availableThb` the balance left. Nothing is sent and nothing is charged; retry after a top-up. Over [SMTP](https://bytesms.com/docs/smtp) the same condition is a temporary `452 4.3.1` reply, so mail servers queue and retry. ### Scheduled and batch sends - A scheduled email counts toward the period it is scheduled to be sent in, and is checked again when it goes out. - A batch is all-or-nothing: if the batch's recipients don't fit (quota or prepaid credit), no email in it is accepted. ## Other limits | Limit | Value | | --- | --- | | Recipients per email (to + cc + bcc) | 50 | | Emails per batch request | 100 | | How far ahead `scheduled_at` may be | 30 days | | Tags per email | 50 | | Idempotency-Key length / retention | 256 characters / 24 hours | | Request body size | 8 MiB | | SMTP message size | 10 MB | > **Note: Warm-up and automatic pauses** > > New domains may be subject to a daily warm-up ramp that raises their volume day by day. Workspaces with high bounce or complaint rates are paused automatically (`403 sending_paused`) to protect deliverability for everyone. --- # Credits & billing - Page: https://bytesms.com/docs/credits (markdown: https://bytesms.com/docs/credits.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 Bytesms plans, monthly email quotas and included credit, per-recipient overage and WhatsApp paid from one prepaid THB wallet, top-ups by card or PromptPay, auto-recharge, credit expiry and receipts. ## How billing works - Every plan includes a **monthly email quota** (counted in recipients) and, on paid plans, an **included credit** amount every month. - Each workspace has one **prepaid credit wallet in THB**. It pays for email sent beyond the monthly quota and for [WhatsApp](https://bytesms.com/docs/whatsapp) messages. - You add to the wallet with a **top-up** (card or PromptPay) or let **auto-recharge** do it from a saved card. - Every payment gets a receipt automatically, in **Settings → Documents**. ## Quota, included credit and overage per plan | Plan | Monthly email quota | Included credit / month | Over-quota email, per recipient | Credit lifetime | | --- | --- | --- | --- | --- | | Free | 3,000 (and 100 per day) | — | No overage: sending stops at the quota | 1 month | | Starter | 10,000 | ฿60 | ฿0.031 | 3 months | | Pro | 50,000 or 100,000 | ฿300 | ฿0.025 | 6 months | | Max | 100,000 – 2,500,000 | ฿1,800 | ฿0.020 | 12 months | | Enterprise | Custom | ฿1,800 | ฿0.020 | 24 months | Plan prices are on the [pricing page](https://bytesms.com/pricing). The quota window is the UTC calendar month on Free and your billing period on a paid plan; see [Rate limits & quotas](https://bytesms.com/docs/rate-limits#quotas) for what counts. ## Email over the quota On a paid plan, sending doesn't stop at the quota. Each recipient over it (`to` + `cc` + `bcc`) is debited from the wallet at your plan's per-recipient price when the email is accepted — no rounding to buckets. For example, on Pro an email to 4 recipients after the quota is used up costs 4 × ฿0.025 = ฿0.10. An email that later ends `failed` or `canceled` gets its debit back. If the wallet can't cover a request (and auto-recharge is off or didn't succeed), nothing is sent and the API returns `402 insufficient_credits`. A batch is all-or-nothing. Over SMTP the same condition is a temporary `452 4.3.1` reply, so your mail server retries. **402 Payment Required** ```json { "statusCode": 402, "message": "Not enough prepaid credit. Top up (or turn on auto-recharge) in the dashboard under Settings → Billing.", "name": "insufficient_credits", "neededThb": 0.155, "availableThb": 0.04 } ``` Broadcast (marketing) emails never use the transactional quota or the wallet — Marketing plans are priced by contacts. ## WhatsApp WhatsApp messages are paid from the same wallet. The price depends on the plan, the template category and the destination country; see [WhatsApp pricing](https://bytesms.com/docs/whatsapp#pricing). Every WhatsApp response includes `priceThb`, and a failed message is refunded. ## Which credit is spent first - **Included credit**is spent first. It is granted every UTC calendar month, replaced (not added to) at the start of the next month, and never rolls over. Upgrading mid-month grants the difference to the new plan's amount. - **Top-up credit** is spent next, oldest-expiring first (FIFO by expiry). ## Credit lifetime Each top-up is a separate lot that expires a fixed number of months after it was bought, depending on the plan the workspace was on: 1 month on Free, 3 on Starter, 6 on Pro, 12 on Max and 24 on Enterprise. Upgrading to a plan with a longer lifetime extends your remaining lots to now + the new lifetime; it never shortens them. Owners get an email 30 and 7 days before credit expires. Expired credit can't be used. > **Warning: Top-up credit is non-refundable** > > Credit you buy can't be refunded or exchanged for cash, and can't be used after it expires. ## Top-ups - Workspace owners and admins top up in **Settings → Billing** (or **Dashboard → WhatsApp**). - Pay by **card** or **PromptPay**, in THB. Amounts from ฿500 to ฿200,000 per top-up. - The credit is added as soon as the payment succeeds. Any tax is shown at checkout before you pay; the credit you get is the amount before tax. ### Auto-recharge Save a card in **Settings → Billing → Auto-recharge** and choose: - a **threshold**— when the balance drops below it (or a send can't be paid at all), the card is charged; - a **recharge amount** (at least ฿500); - a **monthly cap** on the total auto-recharged in a UTC month (at least one recharge amount). Each trigger charges at most once. After 3 declined charges in a row, auto-recharge turns itself off and the owner is emailed. Auto-recharged credit follows the same lifetime and non-refundable rules as a top-up. ### Low-balance alert Owners get an email when the balance falls below the alert threshold (฿100 unless you set your own in Settings → Billing). ## Receipts Every payment — subscription invoices, top-ups and auto-recharges — gets a receipt automatically, with its own running number and your billing profile details. Find and download them (PDF) in **Settings → Documents**. Keep your billing profile (company name, address, tax ID) up to date before paying: documents are issued with the details at the time of payment. --- # Idempotency - Page: https://bytesms.com/docs/idempotency (markdown: https://bytesms.com/docs/idempotency.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 Retry Bytesms email sends safely with the Idempotency-Key header (24-hour window). ## How it works Network errors and timeouts leave you not knowing whether an email was accepted. Send an `Idempotency-Key` header with `POST /api/v1/emails` or `POST /api/v1/emails/batch` and retry with the same key: Bytesms accepts the email once and returns the original response to every retry. **cURL** ```bash # Send with an idempotency key curl -X POST 'https://api.bytesms.com/api/v1/emails' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' \ -H 'Idempotency-Key: welcome-user-123' \ -H 'Content-Type: application/json' \ -d '{"from":"Acme ","to":["customer@example.com"],"subject":"Welcome","html":"

Welcome aboard.

"}' ``` **Node.js** ```js // Send with an idempotency key const res = await fetch("https://api.bytesms.com/api/v1/emails", { method: "POST", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", "Idempotency-Key": "welcome-user-123", "Content-Type": "application/json", }, body: JSON.stringify({ "from": "Acme ", "to": [ "customer@example.com" ], "subject": "Welcome", "html": "

Welcome aboard.

" }), }); console.log(await res.json()); ``` **Python** ```python import requests # Send with an idempotency key res = requests.post( "https://api.bytesms.com/api/v1/emails", headers={"Authorization": "Bearer tp_live_xxxxxxxxx", "Idempotency-Key": "welcome-user-123"}, json={ "from": "Acme ", "to": [ "customer@example.com" ], "subject": "Welcome", "html": "

Welcome aboard.

" }, ) print(res.json()) ``` ## Rules - A key is 1–256 characters; anything else is `422 invalid_idempotency_key`. - Keys are scoped to the workspace and remembered for 24 hours. - Same key + same body → the stored response (for example the same `{ id }`), no second email. - Same key + a different body → `409 idempotency_key_conflict`. Bodies are compared after sorting JSON keys, so key order doesn't matter. - Two concurrent requests with the same key still create only one email. - Single sends and batch sends keep separate key spaces. **409 Conflict** ```json { "statusCode": 409, "message": "This Idempotency-Key was already used with a different request body. Use a new key for a different email.", "name": "idempotency_key_conflict" } ``` > **Note: Choosing keys** > > Derive the key from what makes the email unique in your system — e.g. `order-4711-receipt` or a UUID stored with the job that sends it — rather than generating a new random key on each retry. --- # Emails - Page: https://bytesms.com/docs/emails (markdown: https://bytesms.com/docs/emails.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 Send, batch send, schedule, retrieve, reschedule and cancel emails with the Bytesms REST API (POST /v1/emails). ## Send an email `POST https://api.bytesms.com/api/v1/emails` Accepts one email and returns its id. The email is queued and handed to the sending server for your domain's region; follow its progress with [retrieve](https://bytesms.com/docs/emails#retrieve), [events](https://bytesms.com/docs/emails#events) or [webhooks](https://bytesms.com/docs/webhooks). Works with `full_access` and `sending_access` keys. **Body** - `from` (string, required): Sender address, optionally with a display name: `Acme `. Must be on a verified domain of the workspace (or `onboarding@mail.bytesms.com` for tests to your own account email). Optional when a `template` defines it. - `to` (string | string[], required): Recipient address(es). At least one; at most 50 recipients across `to`, `cc` and `bcc`. - `subject` (string, required): Subject line (no line breaks). Optional when a `template` defines it. - `html` (string, optional): HTML body. Provide `html`, `text` or both (or a `template`). When only `html` is given, a plain-text part is generated from it. - `text` (string, optional): Plain-text body. - `cc` (string | string[], optional): Cc recipients. - `bcc` (string | string[], optional): Bcc recipients (not shown in the message headers). - `reply_to` (string | string[], optional): Reply-To address(es), up to 10, each `email@example.com` or `Name `. Multiple addresses are joined into one `Reply-To` header; an invalid one is a `422`. - `replyTo` (string, optional): Legacy camelCase form of `reply_to`: one string (several addresses separated by commas), same validation. When both are sent, `replyTo` wins. Prefer `reply_to` in new code. - `scheduled_at` (string (ISO 8601), optional): Send later, e.g. `2026-10-01T09:00:00Z`. Must be in the future and at most 30 days ahead. The email is stored with `last_event: "scheduled"` until then and can be [rescheduled](https://bytesms.com/docs/emails#update) or [canceled](https://bytesms.com/docs/emails#cancel). - `tags` ({ name, value }[], optional): Up to 50 tags for your own bookkeeping, echoed in webhook payloads. Names and values: ASCII letters, digits, `_` and `-`, at most 256 characters. An object `{ name: value }` is accepted too. - `headers` (object, optional): Custom headers. Only `List-Unsubscribe`, `List-Unsubscribe-Post` (value `List-Unsubscribe=One-Click`, and only with an https `List-Unsubscribe` URL) and `X-Entity-Ref-ID` are passed through to the message (values up to 900 characters, no line breaks); other headers are not added to the email. - `metadata` (object, optional): Free-form JSON object stored with the email for your own reference. It is shown on the email's page in the dashboard but is not returned by [retrieve](https://bytesms.com/docs/emails#retrieve) and is not sent to the recipient. Avoid the keys `tags` and `headers`: they are read as the email's tags and custom headers, and the top-level `tags` / `headers` fields replace them when set. - `template` ({ id, variables } | { alias, variables }, optional): Render a published [template](https://bytesms.com/docs/templates) instead of `html`/`text`. Identify it with `id` (the template id or its alias) or `alias`; when both are set, `id` is used. `variables` is an object of values. See [Sending with a template](https://bytesms.com/docs/emails#template-send). - `attachments` (—, optional): Not supported yet: any non-empty value is rejected with `422 attachments_not_supported`. **Headers** - `Idempotency-Key` (string, optional): Optional, 1–256 characters. Retries with the same key return the first response. See [Idempotency](https://bytesms.com/docs/idempotency). **cURL** ```bash # Send an email curl -X POST 'https://api.bytesms.com/api/v1/emails' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d '{"from":"Acme ","to":["customer@example.com"],"subject":"Your order has shipped","html":"

Your order #4711 is on its way.

","reply_to":"support@example.com","tags":[{"name":"category","value":"shipping"}]}' ``` **Node.js** ```js // Send an email const res = await fetch("https://api.bytesms.com/api/v1/emails", { method: "POST", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", "Content-Type": "application/json", }, body: JSON.stringify({ "from": "Acme ", "to": [ "customer@example.com" ], "subject": "Your order has shipped", "html": "

Your order #4711 is on its way.

", "reply_to": "support@example.com", "tags": [ { "name": "category", "value": "shipping" } ] }), }); console.log(await res.json()); ``` **Python** ```python import requests # Send an email res = requests.post( "https://api.bytesms.com/api/v1/emails", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, json={ "from": "Acme ", "to": [ "customer@example.com" ], "subject": "Your order has shipped", "html": "

Your order #4711 is on its way.

", "reply_to": "support@example.com", "tags": [ { "name": "category", "value": "shipping" } ] }, ) print(res.json()) ``` **Response** ```json { "id": "cmg4k2x7a0001l8v9h3q2d5rt" } ``` ### Sending with a template With `template`, the published version of the template is rendered server-side. `from`, `subject` and `reply_to` in the request override the template's; `html`/`text`can't be combined with a template. Variable values are HTML-escaped in the HTML body. A variable the template uses without a fallback value must be provided, otherwise the send fails with `422`; an unpublished template is `422` too. **cURL** ```bash # Send with a template curl -X POST 'https://api.bytesms.com/api/v1/emails' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d '{"from":"Acme ","to":"customer@example.com","template":{"id":"order-shipped","variables":{"first_name":"Jane","order_id":4711}}}' ``` **Node.js** ```js // Send with a template const res = await fetch("https://api.bytesms.com/api/v1/emails", { method: "POST", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", "Content-Type": "application/json", }, body: JSON.stringify({ "from": "Acme ", "to": "customer@example.com", "template": { "id": "order-shipped", "variables": { "first_name": "Jane", "order_id": 4711 } } }), }); console.log(await res.json()); ``` **Python** ```python import requests # Send with a template res = requests.post( "https://api.bytesms.com/api/v1/emails", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, json={ "from": "Acme ", "to": "customer@example.com", "template": { "id": "order-shipped", "variables": { "first_name": "Jane", "order_id": 4711 } } }, ) print(res.json()) ``` `template: { alias: "order-shipped" }` works the same way when you prefer to name the alias explicitly. ### Who you can send from and to - `from` must be on a domain with status `verified` in this workspace — otherwise `403 invalid_from_address` (or `403 validation_error` if the workspace has no verified domain yet). - `onboarding@mail.bytesms.com` may only send to your own account email and to `@test.bytesms.com` test addresses. - A domain-scoped API key may only send from its domain (`403 restricted_api_key`). - Recipients on your suppression list (previous hard bounces and complaints) are skipped; if every recipient is suppressed, the email ends `failed`. ## Send a batch `POST https://api.bytesms.com/api/v1/emails/batch` Send up to 100 emails in one request. The body is a JSON **array** of email objects with the same fields as [send](https://bytesms.com/docs/emails#send), except `scheduled_at` (not supported in batches). Validation, sending rules and the quota check are all-or-nothing: either every email is accepted or none is. Supports `Idempotency-Key`. **cURL** ```bash # Send a batch curl -X POST 'https://api.bytesms.com/api/v1/emails/batch' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d '[{"from":"Acme ","to":["a@example.com"],"subject":"Hi A","text":"Hello A"},{"from":"Acme ","to":["b@example.com"],"subject":"Hi B","text":"Hello B"}]' ``` **Node.js** ```js // Send a batch const res = await fetch("https://api.bytesms.com/api/v1/emails/batch", { method: "POST", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", "Content-Type": "application/json", }, body: JSON.stringify([ { "from": "Acme ", "to": [ "a@example.com" ], "subject": "Hi A", "text": "Hello A" }, { "from": "Acme ", "to": [ "b@example.com" ], "subject": "Hi B", "text": "Hello B" } ]), }); console.log(await res.json()); ``` **Python** ```python import requests # Send a batch res = requests.post( "https://api.bytesms.com/api/v1/emails/batch", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, json=[ { "from": "Acme ", "to": [ "a@example.com" ], "subject": "Hi A", "text": "Hello A" }, { "from": "Acme ", "to": [ "b@example.com" ], "subject": "Hi B", "text": "Hello B" } ], ) print(res.json()) ``` **Response** ```json { "data": [ { "id": "cmg4k2x7a0002l8v9w1b8n4qe" }, { "id": "cmg4k2x7a0003l8v9c7m0p2ya" } ] } ``` ## Retrieve an email `GET https://api.bytesms.com/api/v1/emails/{email_id}` Returns the email with its current `last_event` and the full event history. Requires a `full_access` key. **cURL** ```bash # Retrieve an email curl -X GET 'https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' ``` **Node.js** ```js // Retrieve an email const res = await fetch("https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt", { method: "GET", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", }, }); console.log(await res.json()); ``` **Python** ```python import requests # Retrieve an email res = requests.get( "https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, ) print(res.json()) ``` **Response** ```json { "object": "email", "id": "cmg4k2x7a0001l8v9h3q2d5rt", "from": "Acme ", "to": [ "customer@example.com" ], "cc": [], "bcc": [], "reply_to": "support@example.com", "subject": "Your order has shipped", "html": "

Your order #4711 is on its way.

", "text": "Your order #4711 is on its way.", "created_at": "2026-09-28T08:15:02.114Z", "scheduled_at": null, "last_event": "delivered", "events": [ { "type": "email.sent", "created_at": "2026-09-28T08:15:03.020Z", "data": { "email_id": "cmg4k2x7a0001l8v9h3q2d5rt", "from": "Acme ", "to": [ "customer@example.com" ], "subject": "Your order has shipped" } }, { "type": "email.delivered", "created_at": "2026-09-28T08:15:05.480Z", "data": { "email_id": "cmg4k2x7a0001l8v9h3q2d5rt", "recipients": [ "customer@example.com" ], "dsn": "2.0.0" } } ] } ``` | last_event | Meaning | | --- | --- | | `queued` | Accepted, waiting to be handed to the sending server. | | `scheduled` | Waiting for its `scheduled_at`. | | `sent` | Accepted by our sending server for delivery. | | `delivered` | The recipient's mail server accepted it (not necessarily the inbox). | | `bounced` | The recipient's mail server permanently rejected it. | | `complained` | The recipient marked it as spam. | | `failed` | Not sent (e.g. suppressed recipient, sending error). | | `canceled` | A scheduled email that was canceled. | ## List emails `GET https://api.bytesms.com/api/v1/emails` Newest first. Items have the same fields as retrieve, without `html`, `text` and `events`. **Query** - `limit` (integer, optional, default `20`): 1–100. - `after` (string, optional): An email id: return older emails after it (next page). - `before` (string, optional): An email id: return newer emails before it. Don't combine with `after`. **cURL** ```bash # List emails curl -X GET 'https://api.bytesms.com/api/v1/emails?limit=20' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' ``` **Node.js** ```js // List emails const res = await fetch("https://api.bytesms.com/api/v1/emails?limit=20", { method: "GET", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", }, }); console.log(await res.json()); ``` **Python** ```python import requests # List emails res = requests.get( "https://api.bytesms.com/api/v1/emails?limit=20", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, ) print(res.json()) ``` **Response** ```json { "object": "list", "has_more": true, "data": [ { "object": "email", "id": "cmg4k2x7a0001l8v9h3q2d5rt", "...": "..." } ] } ``` ## List an email's events `GET https://api.bytesms.com/api/v1/emails/{email_id}/events` Every recorded event, oldest first: `email.sent`, `email.delivered`, `email.delivery_delayed`, `email.bounced`, `email.complained`, `email.failed`. `data` holds event details such as the bounce reason. **Response** ```json { "data": [ { "type": "email.sent", "created_at": "2026-09-28T08:15:03.020Z", "data": { "email_id": "cmg4k2x7a0001l8v9h3q2d5rt", "from": "Acme ", "to": [ "nobody@example.com" ], "subject": "Hello" } }, { "type": "email.bounced", "created_at": "2026-09-28T08:15:06.901Z", "data": { "email_id": "cmg4k2x7a0001l8v9h3q2d5rt", "bounce": { "type": "Permanent", "subType": "5.1.1", "reason": "550 5.1.1 User unknown" }, "recipients": [ "nobody@example.com" ] } } ] } ``` ## Reschedule an email `PATCH https://api.bytesms.com/api/v1/emails/{email_id}` Change the `scheduled_at` of an email that is still `scheduled`; any other state is `422 validation_error`. **Body** - `scheduled_at` (string (ISO 8601), required): New send time, in the future and at most 30 days after the email was first created. **cURL** ```bash # Reschedule curl -X PATCH 'https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d '{"scheduled_at":"2026-10-01T09:00:00Z"}' ``` **Node.js** ```js // Reschedule const res = await fetch("https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt", { method: "PATCH", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", "Content-Type": "application/json", }, body: JSON.stringify({ "scheduled_at": "2026-10-01T09:00:00Z" }), }); console.log(await res.json()); ``` **Python** ```python import requests # Reschedule res = requests.patch( "https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, json={ "scheduled_at": "2026-10-01T09:00:00Z" }, ) print(res.json()) ``` **Response** ```json { "object": "email", "id": "cmg4k2x7a0001l8v9h3q2d5rt" } ``` ## Cancel a scheduled email `POST https://api.bytesms.com/api/v1/emails/{email_id}/cancel` Cancels an email that is still `scheduled`. Its `last_event` becomes `canceled` and its quota is released. **cURL** ```bash # Cancel curl -X POST 'https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt/cancel' \ -H 'Authorization: Bearer tp_live_xxxxxxxxx' ``` **Node.js** ```js // Cancel const res = await fetch("https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt/cancel", { method: "POST", headers: { Authorization: "Bearer tp_live_xxxxxxxxx", }, }); console.log(await res.json()); ``` **Python** ```python import requests # Cancel res = requests.post( "https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt/cancel", headers={"Authorization": "Bearer tp_live_xxxxxxxxx"}, ) print(res.json()) ``` **Response** ```json { "object": "email", "id": "cmg4k2x7a0001l8v9h3q2d5rt" } ``` > **Note: Legacy endpoint** > > `POST /api/v1/emails/send` accepts the same body but returns the full internal message record and a different error format. It is kept for existing integrations; use `POST /api/v1/emails` for new code. --- # Domains - Page: https://bytesms.com/docs/domains (markdown: https://bytesms.com/docs/domains.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 Add and verify sending domains in Bytesms: DKIM, custom return path, SPF and DMARC DNS records, statuses and regions. You can only send from domains you have verified in your workspace. Verification proves you control the domain and sets up the DNS records receiving servers use to authenticate your mail. All domain endpoints require a `full_access` key. ## Create a domain `POST https://api.bytesms.com/api/v1/domains` **Body** - `name` (string, required): The domain or subdomain, e.g. `example.com` or `mail.example.com`(3–253 characters). IP addresses, names without a TLD, Bytesms' own domains and consumer mailbox domains (gmail.com, …) are refused with `422 invalid_domain` / `reserved_domain`. - `region` (string, optional, default `ap-southeast-7`): Sending region: `ap-southeast-7` (Thailand), `ap-southeast-1` (Singapore) or `eu-central-1` (Frankfurt). See [Regions](https://bytesms.com/docs/regions). A region without an available sending server falls back to the default region — check `region` in the response. - `custom_return_path` (string, optional, default `send`): Label of the return-path subdomain (`