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

Source: https://botpassword.com/keys/twilio
Last checked: 2026-10-25

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Auth Token (with Account SID) | — | Yes | Full access to the account, the same as a Main API key | Does not expire; rotated manually with a secondary Auth Token |
| Main API key | — | Yes | Full access to all Twilio API resources, equivalent to the Account SID and Auth Token | Does not expire until deleted |
| Standard API key | — | Yes | All Twilio API resources except the Accounts and Keys resources | Does not expire until deleted |
| Restricted API key | — | Yes | Fine-grained access to specific resources, defined by a policy | Does not expire until deleted |

## How to create a Twilio key

1. Sign in to the [Twilio Console](https://www.twilio.com/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.

## 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`).

## 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 the 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.

## Gotchas

- 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.

## Using this key with AI agents (BotPassword)

- `run_with`: Runs 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_request`: Makes 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_login`: Lets 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.
- `rotate`: Partly 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_secret`: Saves a value the agent already holds as a new vault item.

## FAQ

### 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.

## Sources

- https://www.twilio.com/docs/iam/api-keys
- https://www.twilio.com/docs/iam/api-keys/key-resource-v1
- https://www.twilio.com/docs/iam/api/authtoken
- https://www.twilio.com/docs/api/errors/20003
- https://www.twilio.com/docs/twilio-cli/quickstart
- https://www.twilio.com/docs/mcp
