Leaked an API key? › SendGrid
Leaked SendGrid API key: what to do in the next 10 minutes
Last updated: November 28, 2026. Steps checked against SendGrid's own docs on November 28, 2026.
Short answer: Create a replacement SendGrid API key first, with only the access your app needs (Custom Access, such as Mail Send), then put it only in a server-only SENDGRID_API_KEY variable everywhere it is set and redeploy. Next, delete the leaked key in Settings, API Keys. SendGrid says to rotate in a different key and delete the compromised one if a key was ever exposed in public, and that deleted keys are rejected, with a small delay. If your app can go without email for a few minutes, delete the leaked key first. SendGrid may also delete a key it finds posted publicly on GitHub, so check the API Keys page and your inbox for its notice. Then check Email Activity for sends you didn't make and the API Keys and Teammates lists for anything you don't recognize. A free SniffPup scan of a site you own can flag a SendGrid API key (SG.) in public JavaScript or an exposed environment file, but it cannot confirm the key is absent everywhere. Removing the key from code alone does not un-leak it.
Which SendGrid keys are secret?
- Secret: A SendGrid API key. It starts with SG. followed by two parts separated by a dot. SendGrid says to treat an API key like a password, and that the console shows it only once, when you create it. Twilio SendGrid can't retrieve or restore a lost or deleted key.
- Secret: What a leaked key can do depends on its access. SendGrid says a Full Access key can use the GET, PATCH, PUT, DELETE and POST endpoints for all parts of your account except billing and Email Address Validation. A Custom Access key can only do what you ticked. SendGrid warns that abusers who get an exposed key can send phish, spoof or spam from your account and damage your sender reputation.
- Meant to be public: None. A SendGrid API key is a secret. Send mail from your server, not from browser or mobile app code, and keep the key out of any VITE_ or NEXT_PUBLIC_ variable.
The next 10 minutes
Times are a rough guide. Do the first step before anything else.
1. Create a replacement key with only the access it needs (Minutes 0-2)
- In SendGrid, go to Settings, then API Keys, then Create API Key. Give it a name you will recognize, such as the app and the date. Choose Custom Access and tick only what your app does (for a typical contact form or sign-up email, that is Mail Send). Click Create & View and copy the key right away. SendGrid shows it only once.
- SendGrid's docs say you can't give an API key more permissions than your own, and that a key created through the API with no scopes gets Full Access by default. Avoid Full Access unless you truly need it.
- If your account has no working key left because SendGrid already deleted the leaked one, create the first new key in the SendGrid console, since the API needs an existing key with permission to manage keys.
- Our advice: if you are seeing sends you didn't make right now, skip ahead and delete the leaked key first (Minute 4). Your app's email will stop until the new key is in place, which is better than letting someone keep sending as you.
2. Put the new key in a server-only variable, redeploy, then delete the leaked key (Minutes 2-5)
- Set the new key as SENDGRID_API_KEY (or whatever name your code reads) in a server-only place: your local .env, your host's environment variables for each environment, your CI/CD secrets, and any scripts or serverless functions that send mail. SendGrid suggests keeping the key in an environment variable or a secured vault. Never put it in client JavaScript, a mobile app, a public repository, or a VITE_ or NEXT_PUBLIC_ variable.
- Redeploy so the new value takes effect, then send one test email and check it goes out.
- Now delete the leaked key. Go to Settings, API Keys, open the action menu for the leaked key, choose Delete API Key, and click Confirm. SendGrid says it rejects any later API calls that use a deleted key, and its API docs say a revoked key fails after a small propagation delay. SendGrid's exposed-key support article says API requests that use a deleted key fail with 401 Unauthorized, so an old key still sitting in a deploy you missed will show up as 401 errors in your logs.
- Also delete any other key you created for this project and no longer use. SendGrid says to delete unused keys.
3. Check for sends and access you didn't authorize (Minutes 5-8)
- Open Activity (the Email Activity Feed). Use Advanced Search and filter by API Key ID or API Key Name to see what the leaked key sent: subjects, recipients, and times you don't recognize. SendGrid says the feed is a snapshot of events, and keeps up to 30 days only if you have the Email Activity history add-on, so look right away.
- Open Settings, API Keys and look for keys you didn't create. SendGrid's API docs say a key with permission to manage keys can create more of them, and a Full Access key covers all parts of your account except billing and Email Address Validation. Our advice: check for a spare key someone made with the leaked one, and delete any key you don't recognize.
- Open Settings, Teammates and check the list. SendGrid says Teammates can send on behalf of the account and that you should review Teammate access regularly. Remove anyone you don't recognize.
- Turn on two-factor authentication for the account, and consider IP Access Management, which SendGrid says lets you control who can access your account by IP address. Both are on SendGrid's own list of ways to secure an account.
- If you find spam or phishing sent from your account, contact SendGrid Support. That is our advice, not a step from SendGrid's docs.
4. Clean up the leaked key (Minutes 8-10)
- Remove the key from frontend code, public files, screenshots, CI logs, and git history. History can keep a secret after the file is deleted. Rotate any other secrets that sat in the same file or commit.
- SendGrid says to never upload keys to GitHub and never leave a production app in debug mode, which can expose keys.
- Deleting the key from a repo does not revoke it. Only deleting the key in SendGrid does. Don't paste the full key into chat or a support ticket.
- Re-scan the live site you own. A clean report is not a guarantee of security.
Good to know
- SendGrid says it constantly monitors for exposed keys and may automatically delete a key that was publicly posted on GitHub. It then sends an email titled Action Required - Twilio SendGrid API Credentials Found Exposed. Don't rely on that: it only covers keys SendGrid finds, and your app stops sending until you make a new key.
- The free scan looks for SendGrid keys (SG. followed by 22 characters, a dot, then 43 characters) in the public page and same-origin JavaScript it can see, and flags exposed environment files such as /.env and Git metadata such as /.git/config. It cannot see private server environment variables, git history, or whether someone already used the key.
- Putting the new key into a public bundle or a public .env file exposes it the same way.
- The scan is passive and read-only on a live URL you own or are authorized to test. It is not a security guarantee.
After the first 10 minutes
Move the code that needs the key to the server (an API route, serverless function or Supabase Edge Function), keep the key in a server-only environment variable, redeploy, and re-check your live site. The general plan, with a prompt you can paste into Lovable, Bolt, Cursor or Claude Code, is in I leaked an API key in my vibe-coded app. What do I do now? Not sure what kind of key you found? Check it with What kind of key is this?
What SniffPup checks, and what it doesn't
A free SniffPup scan reads only what your live site serves to the public: secret key patterns in HTML and same-origin JavaScript (masked in the report) and public files such as /.env and /.git/config. It never uses a key it finds. It can't see your repo, your server or SendGrid's logs, so the steps above are always on you. A clean report is not a guarantee of security.
Sources
- Twilio SendGrid Docs: Secure your Twilio account
- Twilio SendGrid Support: Exposed API Key Deletion
- Twilio SendGrid Docs: API Keys
- Twilio SendGrid API reference: Create API keys
- Twilio SendGrid API reference: Delete API keys
- Twilio SendGrid Docs: Email Activity Feed
- Twilio SendGrid Docs: Teammates
SendGrid can change its dashboard and steps at any time. If something here doesn't match what you see, follow SendGrid's docs and tell us.
Other providers
- Leaked OpenAI API key: what to do in the next 10 minutes
- Leaked Anthropic API key: what to do in the next 10 minutes
- Leaked Gemini API key: what to do in the next 10 minutes
- Leaked Resend API key: what to do in the next 10 minutes
- Leaked Perplexity API key: what to do in the next 10 minutes
- Leaked OpenRouter API key: what to do in the next 10 minutes
- Leaked Groq API key: what to do in the next 10 minutes
- Leaked ElevenLabs API key (unauthorized charges): what to do
- Leaked Stripe secret key: what to do in the next 10 minutes
- Leaked Supabase service_role or secret key: next 10 minutes
- Leaked AWS access key: what to do in the next 10 minutes
- Leaked GitHub token: what to do in the next 10 minutes
- Leaked Twilio auth token: what to do in the next 10 minutes
- Leaked Clerk secret key: what to do in the next 10 minutes
- Leaked DATABASE_URL: what to do in the next 10 minutes