SendGrid authorization grant invalid, expired or revoked: fix
SendGrid returns this 401 when it rejects your credential: a deleted, truncated or wrong-account API key, a malformed Authorization header, or a restricted account. Test the key against the scopes endpoint, then replace it if it fails, and check the account status if it does not.
Sohail Hussain9 min readShort answer
- SendGrid is rejecting the credential you sent: the API key was deleted, mistyped, truncated or has lost permissions.
- Create a new key under Settings > API Keys, send it as a Bearer token (or as the SMTP password with the username apikey), and redeploy.
- If a fresh key still fails, check IP Access Management, account status and plan credits.
You call SendGrid and get this back:
The provided authorization grant is invalid, expired, or revoked
On the Web API it arrives as an HTTP 401. Over SMTP it shows up as 535 Authentication failed: The provided authorization grant is invalid, expired, or revoked. It sounds like OAuth, but you are not in an OAuth flow. SendGrid is saying it does not accept the key, or the account behind it, for this request.
Why it happens
SendGrid's troubleshooting table lists this 401 as a key that is invalid, was deleted, or had its permissions changed, and a key in an environment variable that suddenly stops working. That covers most cases. The same table lists other 401s that look similar, so check the message text carefully.
| Cause | What you see | Fix |
|---|---|---|
| Key deleted or never copied fully | The grant message on every call | Create a new key and replace it everywhere |
| Key was exposed and auto-deleted | Worked yesterday, 401 today | Create a new key and keep it out of public repos |
| Key permissions changed | Some endpoints work, others fail | Edit the key's scopes |
| Wrong header or SMTP username | Fails on first try with a new key | Use Bearer, or apikey as SMTP username |
| Whitespace or line breaks in the value | Key looks right but fails | Re-paste and trim the value |
| IP Access Management enabled | The requestor's IP address is not whitelisted | Add your server IP to the allow list |
| Account disabled | Account Disabled | Reply to the email SendGrid sent, or open a ticket |
| Plan credits used up | Maximum credits exceeded | Upgrade or wait for the reset |
The last three rows are different messages on the same 401 status. Rotating the key will not fix them.
Step-by-step fixes
1. Test the key outside your app
Run one request with the key you think is live. The scopes endpoint touches no data.
curl -i https://api.sendgrid.com/v3/scopes \
-H "Authorization: Bearer $SENDGRID_API_KEY"
A 200 with a list of scopes means the key is good and your app is sending something different (wrong variable, stale deploy, bad header). A 401 means SendGrid rejects the key itself. One caveat: SendGrid's reference says this endpoint's own 401 means the caller isn't authorized to view the scopes, so read the message text and not just the status code.
2. Check that the key still exists
- Open Settings > API Keys in the SendGrid console.
- Look for the key by name. SendGrid says the key must be available there and have the right permissions for the endpoint you call.
- If it is gone, someone deleted it. SendGrid can't retrieve or restore an unknown or deleted key.
- Check your inbox for a notice about an exposed key. SendGrid may automatically delete an exposed API key to protect your account, and requests using the deleted key then fail with a 401.
3. Create a replacement key
- Go to Settings > API Keys and click Create API Key.
- Name it after the app that will use it.
- Pick the least privilege that works; a Restricted Access key limits a key to the permissions you select. For sending only, the key needs Mail Send > Full Access.
- Click Create & View and copy the key right away. The console displays the key only once.
- Put it in your secrets store or environment variable, then restart or redeploy. Many apps read variables only at startup.
Do not paste the key into tickets or chat
Anyone with the key can send as your account. Share only the first few characters when you ask for help, and delete any key you pasted somewhere public.
4. Fix the header format (Web API)
SendGrid expects an Authorization header with the value Bearer followed by your key. Common mistakes:
- No
Bearerprefix, or two spaces after it. - The key sent as
Basicauth or in a query string. - Quotes or a trailing newline inside the environment variable.
- A
.envfile your deployment never loaded, leaving an empty or old value.
Log the length of the variable, never the value, and compare it with the key you created. SendGrid's SMTP guide describes the password as the full 69-character key. A shorter length means truncation, and a longer one means extra characters.
5. Fix the SMTP settings
For SMTP, the 535 version of this error has its own checklist from SendGrid. Work through these:
- Host:
smtp.sendgrid.net. - Username: the literal string
apikey. It is the exact string "apikey" and not the API key itself. - Password: the full API key, not your account password. Using the account credentials you set up through Azure will fail, and the same applies to any login you use for the SendGrid console.
- Port: TLS ports 587, 25 or 2525, or 465 if you need SSL.
- TLS: your SMTP client and its dependencies must support TLS 1.2 or higher, or the connection can fail with the 535 error. With TLS 1.0 or 1.1 the connection never reaches SendGrid's servers, so nothing is logged on their side.
- Whitespace: SMTP is line-oriented, and stray linefeed characters prevent authentication. This bites when you Base64-encode a key in a shell that wraps long output.
Host: smtp.sendgrid.net
Port: 587
Username: apikey
Password: {your-full-api-key}
If you are using old username-and-password logins, SendGrid says its API endpoints reject new requests and SMTP configurations made with a username and password via Basic Authentication. Switch to a key. Our SMTP glossary entry covers the protocol basics.
6. Rule out an IP allow list, permissions and account status
If the key is right and the message differs slightly, match it against SendGrid's table:
The requestor's IP address is not whitelistedmeans IP Access Management is on and your server's IP is not in the allow list. An administrator must add the IP or turn the feature off. This often hits after moving hosts or changing a NAT address.Authenticated user is not authorizedpoints to a Teammate without the right permissions.Account Disabledmeans the account was suspended, banned or deactivated by Consumer Trust. In most cases SendGrid emails you about it, so look for that message and reply. If no message was sent, for example after a suspension for dormancy, open a ticket with technical support.Maximum credits exceededmeans you reached your plan's credit limit; free trial accounts count more than 100 daily credits. The fix is to upgrade or wait for the next reset, which is daily for Free Trial direct accounts.
Read the exact message text
Several different 401 responses share a status code. The message string tells you whether to rotate the key, change an allow list or talk to support.
Checklist before you try again
- The key exists under Settings > API Keys and has the scopes your endpoint needs.
- The deployed app actually reads the new value (restart done, correct environment).
- No quotes, spaces or line breaks around the key.
- Web API:
Authorization: Bearer {key}. SMTP: usernameapikey, password is the key. - The key belongs to the same account or subuser you are sending from.
- Your server's IP is allowed if IP Access Management is on.
- The scopes
curltest above returns 200.
If nothing works
Contact SendGrid support through the SendGrid support center with the details below. For SMTP failures, SendGrid also has a dedicated 535 authentication troubleshooting article.
Include:
- The full response body and HTTP status, or the full SMTP reply.
- A UTC timestamp of one failed call.
- The key's name and API Key ID (never the key itself).
- The account or subuser name, and the sending server's public IP.
- What you already tried (new key, header check, scopes test result).
Subject: 401 "The provided authorization grant is invalid, expired, or revoked"
Hi SendGrid support,
Since {date and time, UTC}, requests from {server IP} to {endpoint or smtp.sendgrid.net:587}
return: "The provided authorization grant is invalid, expired, or revoked".
Account/subuser: {name}
API key name and ID: {name} / {id} (created {date})
Already tried: created a new key with Mail Send access, confirmed Bearer header,
tested GET /v3/scopes (result: {status}), checked IP Access Management.
Please confirm whether the account is in good standing and why this key is rejected.
How to prevent it
- Give each app its own named key, so deleting one never breaks another.
- Rotate by creating the new key, deploying it, confirming sends work, then deleting the old one.
- Keep keys out of source code and public repos, since exposed keys can be auto-deleted.
- Alert on 401s from your sending service. Auth failures are silent otherwise; mail just stops.
- Watch bounces and complaints, because a poor sender reputation is a common path to account review. This matters most for transactional email that users wait on.
Common questions
Is this an OAuth problem?
No. The wording matches the invalid_grant language from OAuth 2.0, but SendGrid uses API keys here. Treat it as "the key or account was not accepted."
Why did a key that worked yesterday stop?
SendGrid lists a deleted key, changed permissions and a key stored in an environment variable that suddenly stops working as causes. Also check for an exposed-key deletion notice, an IP allow list change and account status.
Can I recover a deleted API key?
No. SendGrid says it can't retrieve or restore a deleted or unknown key, so create a new one and update every app that used the old one.
Why does SMTP fail when my API key works over HTTP?
The usual culprits are the username (it must be apikey), line breaks in the password, or an SMTP client that does not support TLS 1.2. The Web API and SMTP use the same key but different client code paths.
Explore: Email Marketing Strategy
Related Articles
414 Request-URI Too Large in n8n's Amazon SES node: fix
The error 414 Request-URI Too Large in n8n's AWS SES node means a server in the path refused a request whose URL was too long, which a long HTML body can cause when it travels in the URL. Send through the SES v2 API with an HTTP Request node, or use SES SMTP.
Access denied, bad outbound sender: Outlook cold email fix
"Access denied, bad outbound sender" (550 5.1.8) means Microsoft 365 has put your mailbox on its restricted users list for spam-like sending. An admin must unblock it under Restricted entities in the Microsoft Defender portal. Then clean your list, lower your volume and resume gradually.
Acoustic Campaign "Application error" on login: bookmark fix
Acoustic Campaign shows "application error" at login when you open it from a bookmark saved while you were logged in, because the bookmark carries the old session. Log out, type your pod URL (campaign-us-[X].goacoustic.com) into the address bar, log in, then save a fresh bookmark.
ActiveCampaign 502 Bad Gateway and Tags Failed to Load: Fixes
"Bad gateway Error code 502" in ActiveCampaign means Cloudflare, the proxy in front of the app, got no valid response from ActiveCampaign's servers. That is usually their side. Check the status page, retry in a clean browser session, clear cookies, then send support the Ray ID if it persists.
Ready to supercharge your email marketing?
Start sending smarter emails with AI-powered campaigns. No credit card required.
Get Started Free