Email, messaging and chat

Twilio API keys: find, store, rotate, and use them safely with AI agents

Twilio authenticates API calls with either an Account SID plus Auth Token, or an API key SID plus secret. API keys come in three types (Main, Standard, Restricted) and are created in the Twilio Console; the secret is shown only once, at creation.

Twilio key types

TypePrefixSecret?ScopeExpiry
Auth Token (with Account SID)
The Account SID identifies the account and is not the secret half.
—YesFull access to the account, the same as a Main API keyDoes not expire; rotated manually with a secondary Auth Token
Main API key
Can be created in the Console only, not through the REST API.
—YesFull access to all Twilio API resources, equivalent to the Account SID and Auth TokenDoes not expire until deleted
Standard API key
Created in the Console or through the REST API.
—YesAll Twilio API resources except the Accounts and Keys resourcesDoes not expire until deleted
Restricted API key
Created in the Console or through the Key resource v1 REST API. A policy update overwrites the whole existing policy.
—YesFine-grained access to specific resources, defined by a policyDoes not expire until deleted

How to create a Twilio key

  1. Sign in to the Twilio Console.
  2. Open the API keys page at twilio.com/console/runtime/api-keys and choose to create a new API key.
  3. Pick the key type (Standard, Main or Restricted), then create it.
  4. Copy the secret immediately. Twilio returns it only in the creation response and cannot show it again.

Open Twilio's key settings

Limiting what the key can do

Use a Restricted key to limit access to named resources. Restricted keys are defined by a Policy with an allow list of permission paths and are created through the Console or the Key resource v1 API. A Standard key cannot manage Accounts or Keys resources. Twilio recommends API keys over the Auth Token for production.

How to rotate a Twilio key

  1. For an API key, create a replacement with the same type and permissions.
  2. Update every environment variable, secret store and deployed app that used the old key.
  3. Delete the old key with DELETE https://iam.twilio.com/v1/Keys/{Sid} or in the Console.
  4. For the Auth Token, create a secondary Auth Token, deploy it, then promote it with a POST to https://accounts.twilio.com/v1/AuthTokens/Promote (CLI twilio api:accounts:v1:auth-tokens:promote:update).

Promoting a secondary Auth Token deletes the old primary one. Each token change emails all account owners and administrators unless SuppressEmailNotification is true. Services or Functions (Classic) with a hardcoded Auth Token fail with 403 for about a minute after promotion.

How to revoke a Twilio key

  1. Delete the API key in the Console, or send DELETE https://iam.twilio.com/v1/Keys/{Sid}.
  2. A successful delete returns HTTP 204 and revokes REST API authorization and invalidates Access Tokens signed with that key's secret.

If your Twilio key leaked

  1. Delete the exposed API key, or rotate the Auth Token if that is what leaked.
  2. Create a replacement and update every environment variable, secret store and deployed app.
  3. Review the account's usage and message logs for activity you did not start.

Environment variables and CLI

Twilio CLI (twilio): twilio login prompts for your Account SID and Auth Token, creates an API key for you and stores it in a local profile

Things that catch people out

  • The key secret is returned only when the key is created and cannot be fetched later.
  • API credentials are Region-specific; a key made in one Twilio Region does not work in another.
  • The official Twilio MCP server at mcp.twilio.com/docs is a public-beta, read-only documentation server and needs no credentials; it does not call your account.
  • Test credentials only work against test resources, not live ones.

Common Twilio authentication errors

20003: Permission Denied

The credentials are wrong or deleted, a Standard key was used on an endpoint that needs a Main key, test credentials were used on live resources, or the key belongs to a different account or Region.

Using your Twilio key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a Twilio key, these intents fit:

IntentWhat BotPassword does
run_withRuns a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
http_requestMakes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
cli_loginLets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
rotatePartly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
store_secretSaves a value the agent already holds as a new vault item.

Twilio also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

Where do I find my Twilio API key?

Open the API keys page in the Twilio Console at twilio.com/console/runtime/api-keys. You can only see a key's secret at the moment you create it.

What is the difference between a Twilio Auth Token and an API key?

The Auth Token plus Account SID gives full account access. An API key is a separate, deletable credential that can be Standard, Main or Restricted, so a leaked key can be revoked without rotating your Auth Token.

How do I rotate a Twilio Auth Token?

Create a secondary Auth Token, update your apps to use it, then promote it. Promotion deletes the old primary token.

Can an AI agent use my Twilio key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, store_secret, so the agent gets the result and never the value.

Stop pasting Twilio keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.