Skip to content
SendGridAPI key

How to rotate a SendGrid API key

Regenerate a Twilio SendGrid API key without a gap in email: create the new key first, update the API and SMTP settings, then delete the old key.

SendGridAPI key

Starts with: SG.…
Where to issue a new one
app.sendgrid.com/settings/api_keys
What a leaked key reaches
A Full Access key reaches every API endpoint of the account. Custom Access keys reach only the endpoints and access levels you select.
Can be scoped
Yes

Keys can be limited to fewer permissions or resources.

Expires
Not documented; treat the key as valid until you delete it
Switching keys
Overlap windowRevokes at once

What Crunu does here

Crunu doesn't reissue keys at providers. It shows which values to replace and keeps the new one.

Build the list for a departure with the offboarding checklist
On this page

Create a second API key with the same permissions, put it everywhere the old one is used, including SMTP settings, check that mail still goes out, and delete the old key last. A SendGrid account can hold up to 100 API keys, so the two can coexist for as long as the switch takes (Twilio docs). Twilio's own replacement steps run in the opposite order: delete the existing key, create a new one, then replace it in your code. That order leaves a window in which every send fails. Reverse it unless the old key has leaked.

Crunu doesn't regenerate or delete SendGrid keys, and it has no Twilio integration. It shows which SendGrid values a departing person or a leak exposed, keeps the new key as a new environment version, and restarts the programs that send with it.

Pick the permission before you create the key

SendGrid offers four permission levels when you create a key:

  • Full Access grants every API endpoint full access to the account.
  • Custom Access lets you choose which endpoints a key can use and at what access level.
  • Billing Access grants the billing endpoints. Billing calls need a key of their own.
  • Email Address Validation Access covers the validation endpoints and read access to reporting.

You can't give a key more permissions than you have yourself, and you can change a key's name and permissions later. Keys created through the API default to Full Access when the request leaves out scopes (API reference), so a script that reissues keys should always send the scopes it needs, such as mail.send. Only a key allowed to manage other keys can create them, and the very first key of an account has to come from the SendGrid app.

The console displays a key once, at creation, and Twilio can't retrieve or restore a lost or deleted one. Keys look like SG.xxxxxxxx.yyyyyyyy.

SMTP uses the same key

The reissue that breaks things is usually the one nobody remembers: SMTP. SendGrid's SMTP relay authenticates with an API key, expecting the literal word apikey instead of a username and the key as the password (SMTP guide). The key needs Mail Send permission. Mail servers, a CMS or monitoring tools that relay through smtp.sendgrid.net all hold a copy, so list them before you delete anything.

Reissue without a gap in email

  1. In the SendGrid console, under Settings > API Keys, create a key with the same permission level as the old one, or a narrower Custom Access set if the old key was broader than it needed to be. Copy the value.
  2. In Crunu, replace SENDGRID_API_KEY in the environment that holds it, for example payments-api / production, and save. The save creates a new version; the history names the variable, never the value.
  3. Restart the senders. Services launched with crunu run --restart on-change pick up the new version without help. Update every SMTP client by hand with apikey as the user and the new key as the password.
  4. Send a test message through each path, the API and SMTP, and check that both are accepted.
  5. Delete the old key. From then on, SendGrid rejects any API call made with it.
Shell
crunu run --env payments-api/production --restart on-change -- /opt/payments/bin/mailer

Know where each key lives

With room for 100 keys, a SendGrid account easily collects keys nobody can place. Name each key after the service and environment that use it, for example payments-api production, and give every sender its own key. A departure or a leak then means deleting one named key and replacing one value in one Crunu environment, instead of guessing which of several Full Access keys a mail server still depends on.

When to reissue a SendGrid key

  • Someone leaves. Reissue every key they could read, Full Access keys first. Removing them in Crunu produces a reissue checklist with those values by name, and Where to reissue opens SendGrid's API keys page for recognized SendGrid values.
  • A leak. Here Twilio's order is right: delete the key at once, accept the gap, then create and deploy the replacement. A leaked Full Access key can change anything in the account.
  • On your own schedule. SendGrid's documentation describes no expiry for API keys, so nothing forces a rotation. Put one in your calendar, and use it to delete keys that no service uses.

Revoking a key never requires changing your username and password, which makes short-lived, single-purpose keys cheap to keep. What to rotate when a developer leaves covers the rest of a departure, and the offboarding checklist builds the list for your own stack. The keys themselves are always created and deleted in SendGrid; Crunu records when each new value was saved and by whom.

Frequently asked questions

Something else? Write to support@crunu.com

Can a SendGrid account have two API keys at the same time?

Yes. Twilio limits an account to 100 API keys, so there is room for the old and the new key during a switch. When the limit is reached, creating another key through the API returns a 403 status.

Why does Twilio's guide delete the old key first?

Its replacement steps list deleting the existing key, creating a new one, then replacing it in code. That order leaves a window in which mail fails. Unless the old key leaked, create the new key first and delete the old one last.

Do SMTP settings change when I reissue a SendGrid key?

Yes. SendGrid's SMTP relay authenticates with an API key: the username is the literal word apikey and the password is the key. Every mail server, CMS or tool that relays through SendGrid needs the new value.

Does Crunu regenerate SendGrid keys?

No. Crunu doesn't call SendGrid or Twilio. It shows which SendGrid values a departing person received, stores the new key as a new environment version and restarts the services that read it through crunu run.

Sources

Every source this page relies on, with the date we last checked it.

  1. Twilio SendGrid Docs: API keys · checked October 30, 2026
  2. Twilio SendGrid API reference: Create API keys · checked October 30, 2026
  3. Twilio SendGrid Docs: How to send an email with SMTP · checked October 30, 2026
  • SSH

    SSH key pair

    Expiry: None for plain keys; expiry-time= or a certificate validity adds one

    Partly scoped

  • Stripe

    Secret API key

    Expiry: Until you expire or rotate it

    sk_live_…Partly scoped

  • Vercel

    Access token

    Expiry: Chosen at creation; the token stops working after that date

    vcp_…Scoped keys

  • Anthropic

    Claude API key

    Expiry: Chosen at creation: 3 hours to 30 days, custom or Never; fixed afterwards

    sk-ant-api…Partly scoped

  • AWS

    IAM user access key

    Expiry: None: a long-term credential until you deactivate or delete it

    AKIA…Partly scopedDelayed revocation

  • Bitbucket

    API token with scopes

    Expiry: 1 to 365 days; one year by default

    Scoped keys

Know which values to replace

Free during early access. When someone leaves, Crunu lists the values they received, changes the environment keys, and keeps each new value as a new version.