Skip to content

Errors, request ids and retries

Every failed call answers with a status code and a JSON body:

{
"error": "\"grumpy\" is not a valid temperament",
"code": "invalid_value",
"request_id": "req_9b1e04f3c2a7d815",
"field": "temperament",
"allowed": ["responsive", "busy", "procedural", "skeptical", "flaky", "difficult", "ghost"]
}
FieldMeaning
errorWhat went wrong, in words, for people. It may change; do not match on it.
codeA stable name a program can act on (below).
request_idThe request’s id, also in the X-Request-Id header. Quote it when you ask for help.
fieldThe parameter or field at fault, where there is one.
allowedThe values the field allows, when a value was not one of them. See the settings reference.
near_misses, matched, waited_ms, messagesOn a wait that timed out: see the wait API.
messageOn unexpected_email: the email that arrived.
featureOn not_in_plan: the plan feature it needs.
CodeStatusMeaning
bad_request400The request is wrong: bad JSON, a missing field.
invalid_value400A value is not one the field allows; see field and allowed.
invalid_regex400A wait’s subject_regex or body_regex is not a valid regular expression.
unauthorized401No key, or a key that is not valid.
not_in_plan402Your plan does not include this feature.
forbidden403Your role cannot do this, the key belongs to another universe, or the organization is suspended.
not_found404No such mailbox, message, persona, case, job or share.
method_not_allowed405Wrong method.
wait_timeout408A wait timed out.
timeout408Another request timed out.
unexpected_email409GET /api/wait/none: a matching email arrived.
conflict409A conflict, such as a person who decided not to reply to a fast reply wait.
too_large413The request body is too large.
idempotency_mismatch422The Idempotency-Key was used for a different request in the last 24 hours.
unprocessable422The request is well formed but cannot be done.
rate_limited429Too many requests; wait as Retry-After says.
internal_error500Something failed on the server.
bad_gateway, unavailable502, 503The server could not be reached; try again.

A plan’s numeric limits (people, logins, streams) are refused with 400 and a message such as “the Starter plan includes 250 people; upgrade for more”.

Every answer, success or failure, carries an X-Request-Id header, and every error body repeats it as request_id. Send your own X-Request-Id (letters, digits and . _ : -, up to 64) to tie simmail’s logs to your test run; otherwise simmail makes one, such as req_40d5c947215616d7.

Terminal window
curl -s -i https://c1.simmail.dev/api/me -H "Authorization: Bearer smk_your_key" -H "X-Request-Id: ci-4821-signup-test"

A network blip during POST /api/send or POST /api/inject leaves you unsure whether the email went. Send an Idempotency-Key header (any string up to 255 characters, unique per email) and retry freely:

  • The same key with the same request within 24 hours gets the first answer back, with the header Idempotent-Replayed: true, and nothing is sent again.
  • The same key with a different request answers 422 (idempotency_mismatch).
  • Server errors (5xx) are not remembered, so a retry after one runs again.
  • Two requests with the same key at once run one after the other; the second gets the first’s answer.
Terminal window
curl -s -X POST https://c1.simmail.dev/api/send \
-H "Authorization: Bearer smk_your_key" -H "Content-Type: application/json" \
-H "Idempotency-Key: signup-test-4821-welcome" \
-d '{"from": "[email protected]", "to": ["[email protected]"], "subject": "Welcome", "text": "Hi Dana"}'

The SDKs send a fresh key with every send and inject and retry on network errors, 502 and 503, so a retried call can never send twice. Pass your own with { idempotencyKey: "…" } (idempotency_key= in Python), or false (False) to send none.

Every error is a SimmailError with status, code, requestId (request_id), and the fields above (field, allowed, nearMisses / near_misses, and so on). Its class says what happened, so a test can catch exactly what it expects:

ClassCodes
ValidationErrorbad_request, invalid_value, invalid_regex (and any other 400)
AuthErrorunauthorized
PlanLimitErrornot_in_plan
ForbiddenErrorforbidden
NotFoundErrornot_found
WaitTimeoutErrorwait_timeout, timeout
ConflictErrorconflict
UnexpectedEmailError (a ConflictError)unexpected_email
IdempotencyErroridempotency_mismatch
RateLimitedErrorrate_limited, with retryAfter (retry_after)
SimmailErroranything else
JavaScript
import { WaitTimeoutError, ValidationError } from "@plexuslabs/simmail";
try {
await mail.waitForEmail({ to: addr, subject: "verify", timeout: "20s" });
} catch (e) {
if (e instanceof WaitTimeoutError) console.log(e.nearMisses, e.requestId);
else if (e instanceof ValidationError) console.log(e.field, e.allowed);
else throw e;
}
Python
from simmail import WaitTimeoutError, ValidationError
try:
mail.wait_for_email(addr, subject="verify", timeout=20)
except WaitTimeoutError as e:
print(e.near_misses, e.request_id)
except ValidationError as e:
print(e.field, e.allowed)