SendGrid API error codes: 400, 401, 403, 413, 429 and 5xx
SendGrid's v3 API answers 202 Accepted for a good Mail Send request and a JSON errors array for anything else, each entry with a message and, when one field caused it, the field. 400 means the request body is wrong, 401 an invalid or revoked key or no credits left, 403 a From address that isn't a verified Sender Identity or a key without the right permission, 413 a message that's too large (the limit is 30MB), 429 too many requests, and 500 an error on SendGrid's side.
Every status code at a glance
The texts below are the ones SendGrid's API reference and its troubleshooting article list for each status.
| Status | Text you'll see | Meaning | Fix |
|---|---|---|---|
202 | Accepted | Queued for delivery | Nothing; track it in Email Logs |
200 | OK | Sandbox mode: validated, not sent | Turn sandbox mode off |
400 | Bad Request | Malformed JSON or an invalid field | Read errors[].message; see the table below |
401 | The provided authorization grant is invalid, expired, or revoked | Key deleted, wrong, or its permissions changed | Check Settings > API Keys |
401 | Maximum credits exceeded | Plan credits used up | Upgrade or wait for the reset |
401 | The requestor's IP address is not whitelisted | IP Access Management is on | Add the server's IP to the allow list |
401 | Account Disabled | Account suspended or deactivated | Reply to SendGrid's email, or open a ticket |
403 | The from address does not match a verified Sender Identity | From domain not authenticated here | Fix the sender identity |
403 | Access Forbidden | Key missing the scope, wrong method, or feature not on your plan | Check the key's scopes |
403 | You are temporarily blocked from sending emails due to repeated bad requests. | Too many bad requests in a short time | Fix the data, then wait |
404 / 405 | Not allowed (405) | Wrong path or HTTP method | Mail Send is POST /v3/mail/send |
406 | Not acceptable | A problem with the Accept header | Send Accept: application/json, or drop the header |
413 | Payload Too Large | Email plus attachments over the limit | Keep the total under 30MB |
429 | too many requests | Rate limit for this endpoint | Wait for X-RateLimit-Reset |
500 | Internal server error | SendGrid-side failure | Retry with backoff |
How to read an error response
Errors share one shape: an errors array whose entries have a message, a field (or null) and sometimes a help object. Print the status and the body together:
curl -s -i https://api.sendgrid.com/v3/mail/send \
-H "Authorization: Bearer $SENDGRID_API_KEY" \
-H "Content-Type: application/json" \
-d '{"personalizations":[{"to":[{"email":"[email protected]"}]}],
"from":{"email":"[email protected]"},
"subject":"Your receipt",
"content":[{"type":"text/plain","value":"Thanks!"}]}'A rate-limited call comes back like this, from SendGrid's own example:
HTTP/1.1 429 TOO MANY REQUESTS
X-RateLimit-Limit: 150
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1392815263
{"errors": [{"field": null, "message": "too many requests"}]}A 400 can hold several entries at once, so log the whole array rather than the first message. EU regional subusers send through https://api.eu.sendgrid.com instead of https://api.sendgrid.com.
Common 400 messages on Mail Send
SendGrid's Mail Send errors page lists every 400 message by field. These are the ones that catch people most:
| Field | Message | Fix |
|---|---|---|
personalizations | You must have at least one personalization. | Add a personalizations entry with a to |
personalizations | There is a limit of 1000 total recipients (to + cc + bcc) per request. | Split the send |
personalizations.cc / .bcc | Each unique email address in the personalization block should only be included once. You have included email address more than once. | De-duplicate recipients across to, cc and bcc |
subject | The subject is required. You can get around this requirement if you use a template with a subject defined. | Set a subject, or use a template that has one |
content.value | A content value is required, this is the content of the email you are sending. | Add a body, or send a template_id instead of content |
attachments.content | The attachment content must be base64 encoded. | Base64-encode the file |
| (body) | Invalid UTF8 in request. | Encode the payload, attachments included, as UTF-8 |
Also watch content order: text/plain must come before text/html. To validate a body without sending, set mail_settings.sandbox_mode.enable to true (a JSON boolean, not a string).
Rate limits and 429
Every v3 response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. Each endpoint has its own fixed number of requests per refresh period; once it's used up, that endpoint answers 429 until the period ends. Read the headers instead of guessing, pause until the reset time, and queue sends rather than firing them in parallel bursts. For many recipients of the same message, one Mail Send request can carry up to 1,000 recipients across its personalizations, which uses far fewer calls.
SMTP relay codes
Over SMTP (smtp.sendgrid.net, username apikey, port 587 with TLS recommended) the errors are SMTP replies. 4xx replies are treated as deferrals and retried for up to 72 hours; 5xx are generally not retried.
| Code | Text | Meaning |
|---|---|---|
250 | Queued mail for delivery | Accepted |
451 | Authentication failed: Maximum credits exceeded | Out of credits |
550 | Unauthenticated Senders Not Allowed | The client sent mail before logging in |
550 | You are temporarily blocked from sending emails due to repeated bad requests. | Temporary block after bad requests |
Replies passed on from the recipient's server, such as 550 5.1.1, are bounces rather than SendGrid errors; see SMTP bounce codes.
Questions
What does SendGrid HTTP Error 403 Forbidden mean?
Either the From address isn't covered by a verified Sender Identity in this account, or the API key lacks the permission for the endpoint (Access Forbidden). The message in the errors array tells you which.
Why does SendGrid return 401 Unauthorized?
The key is invalid, deleted or revoked, the account is out of credits, the request came from an IP not on your allow list, or the account is disabled. Each has its own message.
What is SendGrid's email size limit?
The total size of the email, including attachments, must be less than 30MB. Larger requests are refused with 413 Payload Too Large.
Related
- SendGrid 403: from address not a verified Sender IdentitySendGrid returns 403 when the From address isn't a verified single sender or on an authenticated domain. The fix, and the other 403: access forbidden.
- SendGrid API key: create one with the right permissionsSendGrid API keys are Full Access, Custom Access (chosen scopes) or Billing Access. The scopes sending and read-only monitoring need, and how to check.
- SendGrid not sending emails: a troubleshooting checklistNo 202 Accepted? SendGrid refused the request. Got 202? Find it in Email Logs: dropped, deferred, bounced or delivered each point to a different fix.
- SendGrid dropped vs bounce: every event status explainedDropped means SendGrid never attempted delivery; bounce means the receiving server refused it. Deferred is retried for 72 hours. Every event and reason.
- SMTP codes and email bounce codes: the full listEvery SMTP reply code (421 to 555) and enhanced status code (X.1.1 to X.7.7) from RFC 5321 and RFC 3463, with what each means and what to do next.
- Postmark API error codes: every code and what to doPostmark returns an ErrorCode with a Message, mostly with HTTP 422. Table of codes from 10 to 1502 with meanings, HTTP status and whether to retry.