Retries and errors

Networks fail. Send an idempotency key with every email, and a retry never sends it twice. To learn how PostHog queues, retries, and delivers each send, see how PostHog delivers messages reliably.

Idempotency keys

Build the key from the record that caused the email, and send the same key on every retry. A random value or a timestamp makes each retry look like a new email.

EmailKey
Password resetpassword-reset-{reset_request_id}
Sign-in codesign-in-code-{code_id}
Team inviteinvite-{invite_id}
Receiptreceipt-{order_id}

Send it as the Idempotency-Key header, or idempotencyKey in the SDKs. A key is 1 to 255 visible ASCII characters, is kept for 7 days, and is separate for each project.

  • Same key, same request: nothing new sends. You get the first send's message ID, with "replayed": true.
  • Same key, different request: 422 idempotency_key_reused. Use a new key for a new email.
  • First request still running: 409 idempotency_key_in_flight. Wait a few seconds and retry.
  • Refused request: the key stays unused, so you can send it again later.
  • Lost response: look up the email by its key to see if PostHog queued it, or send it again with the same key.

What to retry

The SDKs retry the codes marked Yes for you, up to two times, with the same idempotency key. Use code in your own error handling. The detail text can change.

StatuscodeRetry?What to do
409idempotency_key_in_flightYesRetry with the same key after a few seconds.
429throttledYesWait for the time in the Retry-After header.
503delivery_unavailableYesRetry with backoff and the same key. PostHog might have queued the email. Don't resend through another email provider, or the recipient can get two copies.
network_error (SDKs)YesSame as a 503.
400A field code, such as required or invalidNoFix the field that attr names.
400invalid_idempotency_keyNoSend 1 to 255 visible ASCII characters.
400sandbox_fields_unsupportedNoYour project has no verified domain, so the test sender can't send cc, bcc, attachments, reply headers, or a marketing category. Remove them, or verify a domain.
400template_not_transactionalNoMake it transactional.
400template_not_sendableNoAdd a subject and body, and publish.
400marketing_templateNoRemove its marketing category.
400transactional_email_pausedNoThe email's workflow is turned off. Turn it back on.
401authentication_failed or not_authenticatedNoSend a valid project secret API key.
403permission_deniedNoUse a key from this project with the transactional_email:write scope.
404not_foundNoCheck the template ID and project.
422idempotency_key_reusedNoUse a new key.
422recipient_suppressedNoThe address hard bounced, or was suppressed through the API with reason bounce. See the suppression list.
422recipient_unreachableNoThe address or its domain can't receive email. Check for a typo.
422sending_pausedNoToo many bounces or complaints on this email. Check the Reputation tab.
422sending_suspendedNoSending is suspended for your project. Check the Reputation tab.
422sandbox_recipient_not_memberNoYour project has no verified domain, so the test sender only sends to members of your organization. Verify a domain.
429quota_limitedNoYour project is over its email quota. Check billing limits.

The SDKs also check some fields before they call PostHog, and return an invalid_* code, such as invalid_recipient, when one is wrong. Send emails from code and attachments have their own checks.

Rate limits

A project can send 600 emails a minute and 20,000 an hour, and all its keys share these limits. The limits rise with the project's sending tier, to about 1% of its daily allowance a minute and 10% an hour at the top tiers. Status lookups have their own limits, so they don't use up the limits for sends. See API and SDK limits for every limit on a send.

Still have questions?

Was this page useful?