Error Response Format
All API errors return a JSON object with a consistent structure. Theerror_code field identifies the category of failure, message provides a human-readable description, and errors (present on validation failures) lists problems for specific fields:
Common Error Codes
Validation Errors
Validation errors (422) mean the request was well-formed but contained invalid data — a missing required field, a malformed recipient address, or a subject line exceeding the character limit. The errors object in the response maps each invalid field to an array of error messages:
An unverified or misconfigured sending domain is not a validation error. It returns
400 with
invalid_domain or unconfigured_domain, so a handler scoped to 422 will miss the most common
first-send failure. SDKs that map only 422 to a validation exception — lettr-php raises a
generic ApiException here — will not route it to a validation catch block either. See
Domain Errors below.Domain Errors
Domain-related errors occur when thefrom address uses a domain that hasn’t been verified or whose DNS records aren’t properly configured. These are the most common errors during initial integration setup:
Retry Logic
A well-designed retry function should distinguish between retryable errors (server failures, rate limits) and non-retryable errors (validation, authentication). The following pattern uses exponential backoff and respects theretry_after value from rate limit responses: