Objective
Twilio CLI
User Account Permission/Role(s) Required
To follow this process, you’ll need permission to view your Twilio Account SID and create API Keys in the Twilio Console. These actions require appropriate access to account-level settings.
The following roles typically have this level of access:
- Owner
- Administrator
- Developer
Procedure
Follow these steps to authenticate the Twilio CLI using environment variables:
Step 1: Generate a Twilio API Key and Secret
- Sign in to the Twilio Console.
- Click Create new API Key.
- Choose Standard as key type.
- Give your key a recognizable friendly name and click Create API Key.
- Copy both the API Key SID and Secret. The secret will be shown only once.
Step 2: Set Environment Variables
Set the following environment variables in your terminal or automation environment.
For macOS/Linux (bash/zsh):
export TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export TWILIO_API_KEY=SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export TWILIO_API_SECRET=your_api_secret
For Windows PowerShell:
$env:TWILIO_ACCOUNT_SID="ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$env:TWILIO_API_KEY="SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$env:TWILIO_API_SECRET="your_api_secret"
For Windows CMD:
set TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
set TWILIO_API_KEY=SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
set TWILIO_API_SECRET=your_api_secret
Step 3: Run a Twilio CLI Command
Once the environment variables are set, you can run commands without logging in or using a stored profile. For example:
twilio api:core:messages:list
The CLI will use the environment variables to authenticate your request.
If multiple credentials are available, Twilio CLI uses them in this order:
- Profile specified with the
-p
flag - Environment variables
- Active CLI profile
Setting TWILIO_REGION
is optional unless working outside the default us1
.
For best practices, use limited-scope API Keys, rotate them regularly, and avoid exposing credentials in scripts or version control.