Errors
Typed error envelope, error codes, and recovery guidance for the Primitive v1 REST API.
Every error response from https://api.primitive.dev/v1 uses the same envelope so agents and SDKs can branch on machine-readable codes without parsing HTTP status text or scraping prose.
Envelope
{
"success": false,
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key"
}
}error.codeis a stable machine-readable identifier. Agents and SDKs branch on this value, not on the human-readablemessage.error.messageis a short human-readable description. It can change between releases without warning. Do not parse it.- When escalating to support, include the request timestamp and the endpoint called, plus any identifier you have: your
Idempotency-Keyif you sent one, or the returned emailidwhen the request got far enough to produce one.
Validation errors name the rejected fields in error.message, with each field path prefixed onto its failure (field: reason):
{
"success": false,
"error": {
"code": "validation_error",
"message": "from: Invalid email address"
}
}Send denials (recipient_not_allowed) additionally carry an error.gates[] array. Each entry describes one failed permission gate so an agent can branch on a stable reason and self-correct:
{
"success": false,
"error": {
"code": "recipient_not_allowed",
"message": "Recipient is not allowed for this organization yet",
"gates": [
{
"name": "send_to_known_addresses",
"reason": "recipient_not_known",
"message": "You have not exchanged authenticated mail with this address yet.",
"subject": "alice@external.com",
"fix": { "action": "wait_for_inbound", "subject": "alice@external.com" },
"docs_url": "https://docs.primitive.dev/docs/sending"
}
]
}
}- Branch on
gates[].reason(and act ongates[].subject), never the humanmessage. Reasons are stable and additive — new gates may appear, existing ones are not renamed in place. gates[].fixis present only when there is a customer-side action; some denials (for example, the sender must fix their own DNS) carry nofix. When present,fix.subjectis the entity the action applies to.
send_to_known_addresses reports why the most recent inbound from the recipient did not unlock replies:
| Reason | Meaning | Fix action |
|---|---|---|
recipient_not_known | No mail has been received from this address. | wait_for_inbound |
recipient_grant_pending | A message from this address was accepted but its grant decision has not been written yet. Transient. | retry_shortly |
recipient_grant_not_recorded | Mail was received from this address, but no grant decision was ever recorded for it (it predates decision recording, or recording did not complete). Not transient; a new message is needed. | wait_for_inbound |
recipient_unauthenticated | Mail was received but the sender did not authenticate (DMARC failed). | sender_must_fix_authentication |
recipient_weak_binding | The sender authenticated, but their DKIM signature does not cover the To header, so the message could not be bound to your inbox. Unlocks once their provider signs To or a message from them passes SPF. | sender_dkim_must_sign_to_header |
recipient_only_sent_reports | Only bounces or automated reports have arrived from this address; those never unlock replies. | wait_for_inbound |
recipient_grant_replay_denied | The last message failed replay defense (stale, future-dated, duplicate or missing Message-ID, your address not in To/Cc, or the check itself failed). A fresh message is needed. | wait_for_inbound |
recipient_grant_denied | A message was received but did not qualify to unlock replies for another reason. | wait_for_inbound |
Error codes
| Code | HTTP status | Meaning | Recovery |
|---|---|---|---|
unauthorized | 401 | Missing or invalid bearer token. The response carries a spec-shaped WWW-Authenticate: Bearer realm="Primitive API", resource_metadata="..." header pointing at the protected-resource metadata. | Acquire a token via the discovery flow at /auth.md, then retry. Do not loop. |
download_token_expired | 401 | The signed download URL (from a webhook payload) is past its 24-hour validity window. The content itself is still stored. Returned only by /v1/emails/{id}/raw and /v1/emails/{id}/attachments.tar.gz. | Retry the same URL with Authorization: Bearer YOUR_API_KEY and no token parameter; API-key downloads do not expire. error.details.remediation carries this instruction. |
download_token_invalid | 401 | The token query parameter on a download URL failed verification (wrong signature, audience, or email id). | Use the signed URL exactly as delivered in the webhook payload, or switch to API-key auth as for download_token_expired. Do not retry with the same token. |
forbidden | 403 | The bearer is valid but lacks the scope required for the operation. | Reissue the token with the missing scope, or surface the missing scope to the human owner. Do not retry with the same token. |
not_found | 404 | The resource id does not exist or is not visible to the current organization. | Verify the id was returned from a previous call in the same org context. Do not retry. |
validation_error | 400 | Request body or query parameters failed schema validation. error.message names the rejected fields. | Fix the fields named in message, retry once. Do not loop without changing input. |
mx_conflict | 409 | A domain claim conflicts with an existing mailbox provider on the same domain. | Surface the conflict to the user; pass confirmed: true in the request body to override. |
conflict | 409 | The request conflicts with current state (for example, a resource was modified concurrently). | Re-read the resource, reconcile, and retry. |
rate_limited | 429 | An organization rate limit was exceeded. Returned by the org-wide API limiter and by /v1/send-mail. The API request limit is 3000 per minute for Developer, Power, and Platinum organizations, and 120 per minute for agent-tier organizations; see Limits. | Honor the Retry-After response header before retrying. Implement client-side back-off. |
rate_limit_exceeded | 429 | Rate limit exceeded on a per-resource limiter (for example domain, CLI/agent signup, and webhook-secret rotation routes). Same meaning as rate_limited. | Treat the same as rate_limited: branch on the 429 status, honor Retry-After. |
outbound_capacity_exhausted | 503 | Outbound capacity is temporarily exhausted. Returned by /v1/send-mail; see Outbound relay failures for the full relay error set. | Retry with exponential back-off. No Retry-After header is sent on this response. Do not exceed 5 attempts; escalate persistent failures with the request timestamp and endpoint. |
internal_error | 500 | An unhandled fault on the server side. Include the request timestamp and endpoint when escalating. | Retry once with back-off, then escalate with the request timestamp and endpoint if persistent. |
Send and reply errors
These codes come from the sending and sent-email management endpoints: POST /v1/send-mail, the reply/forward endpoints, the reschedule/cancel endpoints, and the read endpoints.
| Code | HTTP status | Meaning | Recovery |
|---|---|---|---|
recipient_not_allowed | 403 | A first-send gate refused the recipient. The response carries an error.gates[] array (see below) describing each failed gate. | Inspect gates[]; follow gates[].fix.action where present (for example, wait for inbound, or verify a domain). |
cannot_send_from_domain | 403 | The from address is not a verified outbound sender for your org. error.details.valid_senders lists the domains you can send from. | Send from a listed domain, or verify the from domain. Check GET /v1/outbound/status. |
inbound_not_repliable | 422 | The inbound email cannot be replied to — it was rejected at ingestion, its content was discarded, or it lacks a Message-ID/recipient. error.details.reason says which. | Do not retry. Start a fresh send instead. |
not_scheduled | 409 | A reschedule (PATCH /v1/sent-emails/{id}) or cancel targeted a send that is no longer scheduled: it already executed, is executing now, or was already canceled. The message names the current status. | Read GET /v1/sent-emails/{id} for the current state. Do not retry. |
discard_not_enabled | 403 | Content discard was requested but the org has not opted in to the feature. | Enable content discard in webhook settings first. |
search_timeout | 504 | A search query exceeded its time budget. | Narrow the date range or add more filters, then retry. |
Outbound relay failures
When the outbound relay itself fails, the send returns one of these. The same Idempotency-Key makes a retry safe.
| Code | HTTP status | Meaning | Recovery |
|---|---|---|---|
outbound_capacity_exhausted | 503 | The outbound relay is temporarily at capacity. | Retry with exponential back-off; no Retry-After header is sent. |
outbound_unreachable | 502 | The outbound relay could not be reached at all: the connection failed before the request was delivered, so nothing was sent. | Retry with back-off. |
outbound_relay_timeout | 504 | The outbound relay accepted the request but did not answer within the deadline. The message may still be in flight, so a retry of the same idempotency key replays this result rather than sending a second copy. | Retry with back-off. Reuse the same Idempotency-Key; a new key can produce a duplicate delivery. |
outbound_relay_failed | 502 | The relay returned an unclassified failure. | Retry with back-off, then escalate with the request timestamp and endpoint. |
outbound_response_malformed | 502 | The relay returned an unexpected response. | Retry once, then escalate with the request timestamp and endpoint. |
outbound_key_invalid | 500 | A server-side outbound credential is invalid. | Escalate with the request timestamp and endpoint; retrying will not help until fixed. |
Rate-limit responses
A rate-limited request gets a 429 with a Retry-After header plus the standard rate-limit headers:
Retry-After: 30
ratelimit-limit: 3000
ratelimit-remaining: 0
ratelimit-reset: 1718900000
ratelimit-policy: 3000;w=60This example shows the standard organization's API request limit. Retry-After is in seconds, ratelimit-reset is a Unix timestamp (seconds), and ratelimit-limit reports the limit that rejected the request. The value is 120 for agent-tier API traffic and unauthenticated IP traffic; send and per-resource limits can have other values. On a 429 all four ratelimit-* headers describe the limiter that rejected the request, never a different budget that still has room, and the w= value in ratelimit-policy is that limiter's own window in seconds: 60 for the API request limits, 3600 and 86400 for the hourly and daily send caps (for example 1000;w=3600), and the limiter's own window on per-resource limits (a webhook test send limited to 4 per minute reports 4;w=60). Agents should sleep for at least Retry-After seconds before retrying the same operation. The hourly and daily send caps are rolling windows rather than fixed ones, so on those two limiters Retry-After and ratelimit-reset report when the bucket will next admit a request, which can be well before the end of the current hour or day. The body matches the standard envelope; branch on the 429 status, since the code is either rate_limited (org-wide limiter, /v1/send-mail) or rate_limit_exceeded (per-resource limiters):
{ "success": false, "error": { "code": "rate_limited", "message": "Rate limit exceeded" } }A few 429 responses carry Retry-After and no ratelimit-* headers, because what refused the request reports only how long to wait: the signup and OAuth slow_down responses, the hosted MCP server, and an abuse backstop in front of the API that answers before a request reaches the rate limiters (code rate_limit_exceeded, Retry-After: 60). A 429 whose code is not rate_limited, rate_limit_exceeded or slow_down is a different kind of cap, such as a concurrency or attempt limit, and may carry no Retry-After at all; read its message. In every case, when Retry-After is present it is the value to wait for.
The same four ratelimit-* headers are on other v1 API responses too, so a client can track its budget before it runs out. On those responses they describe the API request budget the request was charged to. A 401 for a missing or invalid token reports the per-IP bucket that the request was charged to (120 per minute). Two cases carry less: organizations exempted from the API limit get no ratelimit-* headers, and while the limiter is briefly unavailable a response carries no live bucket state (a 401 then carries only ratelimit-limit and ratelimit-policy). Treat a missing ratelimit-remaining as unknown, not as zero.
Idempotency
The /send-mail endpoint accepts an optional Idempotency-Key request header. When provided, replays of the same key return the original outcome (including the Idempotency-Key response header echoing the effective value) rather than firing a second send. Use this for any operation an agent might retry after a network failure.
If you omit the header, Primitive derives a key from the canonical request payload and a fixed 5-minute window, and returns it in the Idempotency-Key response header. Two keyless sends with identical content to the same recipients inside one window are therefore a single send: the second sends nothing and returns the first send's result. That is 200 with idempotent_replay: true when the first send was accepted. When the first send failed, it is that send's stored error with its original status (for example 504 outbound_relay_timeout), not a new attempt.
A replay is always marked. The response carries an Idempotent-Replayed: true header and an idempotency object whose key_source is explicit, auto_content or function_trigger. The object is in data on a 200 and in error.details on a replayed error. Pass your own Idempotency-Key per logical send to send identical content again. See Sends without a key.
Webhook signature failures
Webhook delivery failures appear in webhook event logs, not in API responses. See the signature verification guide for verifier logic.
Versioning and deprecation
The error envelope is part of the v1 contract. Breaking changes will only land in a new major version (/v2). See API versioning.