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
| Error Code | HTTP Status | Description |
|---|---|---|
validation_error | 422 | Invalid request parameters |
invalid_domain | 400 | Sender domain not verified |
unconfigured_domain | 400 | Domain not ready for sending |
template_not_found | 404 | Template slug not found |
send_error | 500 | Email sending error |
transmission_failed | 502 | Email delivery to upstream provider failed |
Validation Errors
Validation errors (422) mean the request was well-formed but contained invalid data — a missing required field, an unverified sender domain, or a subject line exceeding the character limit. The errors object in the response maps each invalid field to an array of error messages:
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:
Retryable vs Non-Retryable Errors
Not all errors should be retried. Retrying a validation error or an unauthorized request will produce the same result every time. The table below summarizes which errors are safe to retry and what action to take for each:| Error Type | Retryable | Action |
|---|---|---|
429 Rate limit | Yes | Wait and retry with backoff |
500 Server error | Yes | Retry with backoff |
502/503/504 Gateway errors | Yes | Retry with backoff |
401 Unauthorized | No | Check API key |
403 Forbidden | No | Check API key permissions |
422 Validation | No | Fix request data |
404 Not found | No | Check template/resource exists |
Error Handling Best Practices
Wrapping the retry function with error-specific handling gives you a clean interface for your application code. Log errors with enough context to debug later, and return structured results so calling code can decide how to proceed:Soft Bounce Retries
After Lettr accepts an email for delivery, the receiving mail server may reject it with a temporary error (soft bounce). Lettr automatically retries soft bounces on your behalf — you don’t need to implement retry logic for these. Hard bounces are permanent failures and are never retried:| Bounce Type | Auto-Retry | Max Attempts |
|---|---|---|
| Soft bounce (mailbox full) | Yes | 3 |
| Soft bounce (server error) | Yes | 3 |
| Hard bounce (invalid address) | No | - |