Reference
API reference
Explore Ternwire API v1 endpoints, authentication, email request fields, limits, error responses, and the OpenAPI download.
On this page
The Ternwire public API uses JSON over HTTP under /v1. Authenticate with Authorization: Bearer YOUR_API_KEY. The OpenAPI JSON document defines request and response schemas for the endpoints below.
Base URL
https://ternwire.com/v1The OpenAPI document names https://ternwire.com/v1 as its server, so a client generated from it needs no base URL. It also says which API key scope each operation needs (x-ternwire-scope), and its webhooks section describes the body of every webhook event.
Authentication and request scope
Keep keys on your server and grant only the scopes your integration needs. An em_test_ key sends test-mode email, which is never delivered to a real inbox. Domain administration requires a live key. Webhook and blocked-address administration accept either key mode with sending access. A key belongs to one workspace and can reach only that workspace's domains, messages, templates, and attachments.
A key can also be limited to some of the workspace's sending domains when you create it. Such a key sends only from those domains: a from on any other domain gets 422 with sender_domain_not_allowed. It can't manage domains or receiving addresses (403, api_key_domain_restricted), and it can't have the broadcasts:write or automations:write scopes, because broadcasts and automations send later from their own sender.
curl "https://ternwire.com/v1/domains" \
--header "Authorization: Bearer $TERNWIRE_API_KEY"GET /v1/me works with any key, whatever its scopes. It returns the workspace, the calling key's scopes, mode, domain limit and expiry, the plan, whether live sending is allowed and why not (sending.blockedBy), the recipients left this billing period and, on the free plan, today, and the AI template credits left. Call it first to learn what a key can do before you act with it.
A key with the api_keys:write scope can list, create and revoke keys through /v1/api-keys. It can only create or revoke keys with no more access than its own: only scopes it has, test mode if it is a test key, only its own sending domains if it is limited to some, and an expiry no later than its own. Anything more gets 403 with api_key_privilege_exceeded and names the field. A key can always revoke itself. No preset includes api_keys:write: an owner picks it under Custom on the API keys page. Keys made this way keep working after the key that made them is revoked, so revoke them too when you retire an integration.
Email request fields
POST /v1/emails needs a sender and at least one recipient across to, cc, and bcc, with at most 50 recipients in total. Supply subject and at least one of text or html, or use templateId and values. Use attachmentIds for uploaded, clean attachments. Duplicate recipients are rejected.
| Field | Type | Notes |
|---|---|---|
from | string | An address on a verified sending domain. |
to, cc, bcc | string[] | At least one recipient, and at most 50 across all three. |
subject | string | Required unless you send a template. |
text, html | string | At least one, unless you send a template. |
templateId, values | string, object | Send a saved template instead of a subject and body. values fills in its variables. |
replyTo | string | Optional reply address. |
attachmentIds | string[] | Clean attachments, at most 20. |
tags | object | Your own labels. Keys are up to 64 letters, digits, _ or -, and values up to 256 characters. |
headers | object | Custom headers. Names must start with X-. |
Send an Idempotency-Key header of 1-128 characters. Ternwire remembers the key for 7 days after it accepts the email, and a retry with the same key and body in that time returns the first answer without sending again. A successful acceptance returns 202 with the message ID, the queued state, and the acceptance time. The Emails API has every field and a request you can copy. Start with the complete quickstart.
Limits
| Limit | Value |
|---|---|
| Email requests | 10 a second per workspace. Newsletter emails sent one at a time with purpose: "marketing" have their own 5 a second. See rate limits. |
| Recipients per email | 50 across to, cc and bcc |
| Message size | 40 MB once encoded, attachments included |
| Attachments per email | 20, each up to 15 MB |
| Idempotency keys | Remembered for 7 days |
| Webhook endpoints | 10 per workspace |
| Templates | 500 per workspace |
| Ternwire's test address | 10 recipients in any 24 hours, see sending before your domain is ready |
| Free plan | 100 recipients a day at first, then 500 a day after a clean first week. See pricing for every plan. |
Rate limits
Each workspace can send 100 emails at once through POST /v1/emails, and after that 10 a second. Unused room builds back up at 10 a second until it reaches 100 again. Newsletter emails have their own, separate limit: 50 at once, then 5 a second.
Every response to a send carries three headers, so you can pace a batch before you reach the limit:
| Header | Meaning |
|---|---|
RateLimit-Limit | How many emails can go at once when the limit is full: 100, or 50 for newsletter emails. |
RateLimit-Remaining | How many more emails can go right now. |
RateLimit-Reset | Seconds until the limit is full again. |
A request over the rate limit gets 429 with code: "rate_limited" and a Retry-After header in seconds. Wait that long, then send the same request again with the same idempotency key. To send a large batch, such as a day's receipts, keep each workspace under the per-second rate, for example with a queue that sends one email at a time. Broadcasts and automations are paced for you, so they never use up the rate for app email.
Available endpoints
Each group of endpoints has its own page with parameters, request fields, and request and response examples.
All 94 endpoints
Pagination
Every list returns one page in the same shape:
{
"data": [],
"page": { "nextCursor": "eyJjcmVhdGVkQXQiOi...", "hasMore": true }
}Pass page.nextCursor as the cursor query parameter to get the next page, until page.hasMore is false. limit sets the page size, from 1 to 100, and defaults to 25. A cursor is opaque: pass it back unchanged and do not build one yourself.
Audiences, contacts, contact imports, broadcasts, broadcast recipients, automations and enrollments also repeat hasMore and nextCursor at the top level, where they first returned them. Those two fields are deprecated and will be removed in a later API version, so read page.
Templates, audiences, contacts, broadcasts and automations list newest first. A cursor these lists issued before they were ordered by creation time starts again at the first page.
Errors and retry decisions
Every error has a JSON body with the same fields. Branch on the code, not on the message text, which can change.
{
"status": "invalid_request",
"code": "invalid_request",
"title": "Invalid request",
"message": "Some fields in the request are missing or invalid.",
"fields": { "subject": ["This field is required."] },
"requestId": "req_3f2b1c4e-8a9d-4e1f-b6c7-2d5e8f9a0b1c"
}| Field | Meaning |
|---|---|
code | The error code, such as invalid_request or rate_limited. Branch on this. |
status | The same code, kept for clients written before code was on every error. |
title | A short summary. |
message | What went wrong and what to do, in plain English. |
fields | Only on errors about the request body: each field that needs a change, with what to change. |
requestId | The same value as the X-Request-Id header. |
Some errors add details, such as limit on a plan limit, requiredScope on a missing scope, or actualBytes and limitBytes on a message that is too large. Errors lists every code with what to do.
Each SDK raises one error type for API errors, with the HTTP status and the parsed body:
import { TernwireApiError } from "ternwire";
try {
await client.submitEmail(email, "order-123-receipt");
} catch (error) {
if (!(error instanceof TernwireApiError)) throw error; // a network failure
const { httpStatus, code, message, fields } = error.parsed;
console.error(httpStatus, code, message, fields, error.headers["x-request-id"]);
}Every response carries an X-Request-Id header, such as req_3f2b1c4e-8a9d-4e1f-b6c7-2d5e8f9a0b1c, and every error body repeats it as requestId. Log it with each failed request and include it when you contact support, so the request can be found in Ternwire's logs. Requests made with an API key, rejected ones included, appear in the dashboard's Request log for 30 days. Search there for the request ID to see the route, status, error code and key.
| Status | What to do |
|---|---|
| 400 | Fix invalid input or duplicate recipients. fields says what to change. |
| 401 | invalid_api_key: the key is missing, malformed, unknown, revoked or expired. Send a current key. |
| 403 | missing_scope: the key works but lacks the scope the operation needs, named in requiredScope. Other 403 codes name a key mode or account setting to change, such as an operation that needs a live key. |
| 402 | Check your plan or spending limit before retrying. |
| 404 | Check the ID, and that it belongs to the key's workspace. |
| 409 | Tell a changed-payload idempotency conflict apart from a request still in progress. Only retry the original payload, and follow Retry-After when provided. |
| 413 | Make the message smaller. |
| 422 | Fix the cause before retrying: a sending domain that isn't verified, a paused workspace, an inactive subscription, a blocked recipient, or a template or attachment that can't be used. From Ternwire's test address, also a recipient outside your workspace or a used-up daily allowance. |
| 429, 5xx | A 503 temporarily_unavailable means the request took too long on our side and was stopped. Honor Retry-After when present, see limits, and apply bounded backoff with the original idempotency key. |
Do not automatically retry every failure with a new key. Use the accepted message ID to reconcile uncertainty, and read delivery states before you implement recovery.