How to rotate a Twilio Auth Token and API keys
Twilio gives the Auth Token a built-in overlap: request a secondary token, deploy it, then promote it. The catch is the moment of promotion, which kills the old token instantly and changes the key your webhooks are signed with.
- Credentials
- Account SID + Auth Token (primary, plus an optional secondary), and API keys: Main, Standard or Restricted, each a key SID plus a secret.
- Where
- Console → Settings → Account settings → API keys & auth tokens, after choosing the region.
- Overlap
- A secondary Auth Token works immediately alongside the primary. Promoting it deletes the old primary on the spot.
- By API
POST https://accounts.twilio.com/v1/AuthTokens/Secondary, thenPOST …/AuthTokens/Promote. Only the Account SID and Auth Token are accepted; API keys fail with error 20003.- Webhooks
- By default
X-Twilio-Signatureis an HMAC-SHA1 of the request, keyed with your primary Auth Token. - Notifications
- Every Auth Token change emails all owners and administrators, unless you pass
SuppressEmailNotification=true. - API key types
- Main keys can manage accounts and keys and are created only in the Console. Standard and Restricted keys can be created through the API.
- Keysquid
- Automatic for API keys: a new key and secret each rotation, created and deleted through IAM v1.
Auth Token or API key?
| Credential | Access | How it rotates | Use it for |
|---|---|---|---|
| Auth Token (primary) | Everything on the account | Secondary token, then promote | Signing webhooks; rotating the token itself |
| Main API key | Everything, including /Accounts and Keys | Create a new key in the Console, swap, delete the old | Tools that manage other keys |
| Standard API key | Everything except /Accounts and Keys | Create a new key, swap, delete the old | Your application's API calls |
| Restricted API key | Only the permissions you grant | Create a new key, swap, delete the old | A single job, such as sending SMS |
Main keys are equivalent to the Account SID and Auth Token. For Standard and Main keys you can only edit the name; Restricted keys can also change permissions.
The Auth Token is a single shared secret with full access, and it also signs your webhooks. Every service that holds it has to change at once when it rotates. Moving your application to an API key separates the two jobs: the app authenticates with a key you can rotate any time, and the Auth Token stays with the few places that genuinely need it.
Rotate the Auth Token in the Console
- Open API keys & auth tokens and pick the region at the top right.
- In the Auth Tokens section, click Request a secondary token, then Request Token.
- Reveal it with the eye icon and deploy it to every service that uses the Auth Token. It authenticates straight away, next to the primary.
- Prepare your webhook validators for the switch (next section).
- Click Promote to Primary and acknowledge the dialog. From that moment, every request made with the old token fails.
Changed your mind before promoting? Delete this Token removes the secondary and leaves the primary as it was.
The same rotation through the API. Twilio only accepts the Account SID and current Auth Token here:
# 1. Create the secondary token (works immediately)
curl -s -X POST https://accounts.twilio.com/v1/AuthTokens/Secondary \
-u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" | jq -r '.secondary_auth_token'
# 2. Deploy it everywhere, then promote it. The old primary is deleted.
curl -s -X POST https://accounts.twilio.com/v1/AuthTokens/Promote \
-u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN"
# Rotating many subaccounts? Add this to each call to skip the emails:
# --data-urlencode "SuppressEmailNotification=true"Twilio Functions and Services (Classic): if you pasted the Auth Token into their code instead of using a variable, wait one minute after promoting before relying on them, or they fail with 403 Forbidden.
Keep webhook signatures valid during the switch
Twilio signs each webhook with your primary Auth Token. While a secondary token exists, requests are still signed with the old one; after you promote, they are signed with the new one. A validator that knows only one token rejects real Twilio requests on one side of that moment. Two ways to avoid it:
- Accept both tokens for the rotation window. Check the signature against the current token, and if that fails, against the other one. Remove the fallback once the promotion is done.
- Sign webhooks with a shared key instead. With Twilio’s Webhooks configuration API you can sign with a key you manage, using HMAC-SHA256 or HMAC-SHA1. It is separate from your account credentials, so rotating the Auth Token no longer touches webhook validation. Requests signed this way carry an
X-Twilio-Webhooks-Signature-Settingsheader naming the key; when that header is missing, the Auth Token signed the request.
import twilio from "twilio";
// Accept either token while a rotation is in progress
function isFromTwilio(signature, url, params) {
const tokens = [process.env.TWILIO_AUTH_TOKEN, process.env.TWILIO_AUTH_TOKEN_NEXT].filter(Boolean);
return tokens.some((t) => twilio.validateRequest(t, signature, url, params));
}Rotate an API key
- In API keys & auth tokens, click Create API key, give it a name and choose Standard or Restricted.
- Copy the secret and store it somewhere secure before you click Got it! and Finish.
- Deploy the key SID and secret to your app (they replace the username and password in HTTP basic auth) and confirm calls succeed.
- Open the old key on the API keys tab, click Delete this key and confirm.
Two keys can be live at the same time, so this rotation has no gap. Main keys don’t appear in that Console flow; they are offered only in the legacy Console’s API keys & tokens page. Twilio recommends API key authentication for fetching media files too, rather than the Auth Token.
By hand vs. with Keysquid
By hand
- Create a new API key in the Console and copy the secret.
- Update every service and CI secret that uses it.
- Test, then delete the old key.
- Rotate the Auth Token separately, with webhook validators ready.
With Keysquid
- Keysquid creates a new API key through IAM v1.
- It checks the key works against your account, writes it everywhere and redeploys.
- It deletes the old key after the grace period.
- The Auth Token stays a deliberate, manual change.
How Keysquid handles Twilio credentials
Automatic Keysquid creates, verifies, distributes and revokes Twilio keys on a schedule, with no one in the loop. Standard API keys (SK…) with secrets, created and deleted through IAM v1.
Setup, as the app shows it:
- In the Twilio Console create a Main API key for Keysquid (Main keys can manage other keys).
- Your app should authenticate with an API key + secret rather than the Auth Token.
- Writes to: API key SID (default variable TWILIO_API_KEY), API key secret (default variable TWILIO_API_SECRET), in every platform and secret store you map it to.
- Interval: from every 1 hour to every 4 weeks, subject to your plan’s minimum.
- Inventory: Keysquid lists every Twilio key the connection can see, including keys it doesn’t manage, with names and last use.
Every rotation runs in the same order: create the new key, verify it, write it everywhere, redeploy where a platform needs it, and only then revoke the previous key after a grace period. If any write fails, everything written so far is restored and the new key is revoked. The value is encrypted to the agent you run, so Keysquid’s servers never see it.
Keysquid needs a Main key for its own connection, because only Main keys can reach the Keys endpoints, and Main keys can only be made in the Console. Your app gets the keys Keysquid creates. Keysquid doesn’t promote or request Auth Tokens: that change also moves webhook signing, so it’s better made by a person with the steps above.
Frequently asked questions
Does promoting a Twilio secondary Auth Token invalidate the old one?
Yes, immediately. Promoting deletes the old primary token, and every request still using it fails from that moment. Deploy the secondary token everywhere before you promote.
Can I rotate the Twilio Auth Token with an API key?
No. The Auth Token endpoints accept only the Account SID and Auth Token; requests made with an API key fail with error 20003.
Will rotating my Auth Token break webhook validation?
It can. Twilio signs webhooks with the primary Auth Token, so after promotion the signatures change. Validate against both tokens during the switch, or sign webhooks with a shared key, which isn't affected by Auth Token rotation.
What's the difference between Main, Standard and Restricted API keys?
Main keys have full access, including the Accounts and Keys resources, and can only be created in the Console. Standard keys can do everything except manage accounts and keys. Restricted keys have only the permissions you choose.
Why does Twilio email my whole team when I rotate?
Every Auth Token change emails all owners and administrators of the account. When rotating many subaccounts through the API, Twilio suggests setting SuppressEmailNotification to true.