Skip to main content
skill CX Codex GP ChatGPT official · OpenAI

twilio-security-api-auth — Codex skill: pick the right Twilio auth

Walks you through Twilio's four auth methods and helps you wire up the right one before shipping API calls to production.

Install into Codex · Skills CLI (Vercel) All methods and platforms ↓
npx skills add openai/plugins --skill twilio-security-api-auth -a codex
Open on GitHub

What twilio-security-api-auth does

The skill covers four ways to authenticate against Twilio and tells you which fits where. Auth Token is for local testing only. Server-side production code should use API Key + Secret or OAuth2 with a token that lives for an hour. Browser and mobile SDKs need an Access Token (JWT) minted on the server.

Inside you get a comparison table, working Python and Node.js snippets, a cURL call for the bearer token, and Access Token code with VoiceGrant, VideoGrant, ChatGrant and SyncGrant. A separate section lists what does not work: standard keys cannot touch /Accounts or /Keys, restricted keys cannot issue Access Tokens, and OAuth2 supports client_credentials only — no refresh tokens.

The big trap is Auth Token rotation: it breaks every API key on the account at once. That is a good reason to start with API keys from day one instead of migrating later. The API Key Secret is shown once at creation and cannot be retrieved after. Test credentials reach only four endpoints — Messages, Calls, IncomingPhoneNumbers and Lookups — everything else returns 403.

What it helps with

  • choose a Twilio auth method for server-side code
  • get Auth Token out of production code
  • issue an Access Token for a browser or mobile client
  • fetch an OAuth2 bearer token via client_credentials
  • test Twilio APIs without getting charged

Example prompts for the agent

  • Pick the right Twilio auth method for our Python backend
  • Rewrite the Twilio client setup to use an API Key instead of the Auth Token
  • Generate an Access Token with a VoiceGrant for our browser client

How to install twilio-security-api-auth

1Skills CLI (Vercel)

npx skills add openai/plugins --skill twilio-security-api-auth -a codex

2Manually: put the files in place

.agents/skills/twilio-security-api-auth/SKILL.md

For all projects use ~/.agents/skills/

Step by step, with commands for each platform: Codex skills: how to install, where they live, how to call them

Questions about twilio-security-api-auth

How do I install twilio-security-api-auth in Claude?

Run npx skills add openai/plugins --skill twilio-security-api-auth -a codex. The skill file then lands at .agents/skills/twilio-security-api-auth/SKILL.md.

What does twilio-security-api-auth do?

It explains Twilio's four authentication methods and which one belongs in production, which is test-only, and which is meant for client-side SDKs.

How is an API Key different from an Auth Token in Twilio?

An API key can be revoked on its own, while rotating the Auth Token breaks every key on the account. So Auth Token stays for local testing and production uses API Key + Secret.

Source text

SKILL.md · MIT
---
name: twilio-security-api-auth
description: >
  Choose the right Twilio authentication method and implement it correctly.
  Covers Auth Token (testing only), API Keys (production standard), OAuth2
  client_credentials (time-limited bearer tokens), Access Tokens (client-side
  SDKs), and test credentials. Use this skill before making any Twilio API
  calls in production.
---

## Overview

Twilio supports four authentication methods. Choosing the wrong one is a security risk — Auth Tokens in production code are the most common credential leak.

| Method | Use for | Token lifetime | Revocable individually |
|--------|---------|---------------|----------------------|
| **Auth Token** | Local testing only | Permanent (until rotated) | No — rotation breaks ALL API keys |
| **API Key + Secret** | Production server-side | Permanent (until deleted) | Yes |
| **OAuth2 Bearer Token** | Production server-side (enhanced) | 1 hour | Expires automatically |
| **Access Token (JWT)** | Client-side SDKs (Voice, Video, Chat) | Up to 24 hours | No — delete issuing API key |

**Decision framework:**
- **Building a quick prototype?** → Auth Token (but switch to API Key before deploying)
- **Production server-side code?** → API Key + Secret (simplest production auth) or OAuth2 (time-limited tokens)
- **Browser/mobile client needs to connect?** → Access Token (JWT) generated server-side
- **Running tests without charges?** → Test credentials with magic numbers

---

## API Key Authentication (Production Standard)

**Create:** Console → Account → API keys & tokens → Create API key

| Key type | Access | Create via |
|----------|--------|-----------|
| **Main** | Full account access | Console only |
| **Standard** | All resources except /Accounts and /Keys endpoints | Console or API |
| **Restricted** | Specific resources only (up to 100 permissions) | Console or v1 IAM API only |

**Python**
```python
import os
from twilio.rest import Client

client = Client(
    os.environ["TWILIO_API_KEY"],      # SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    os.environ["TWILIO_API_SECRET"],
    os.environ["TWILIO_ACCOUNT_SID"]   # required as third argument
)
```

**Node.js**
```node
const client = require("twilio")(
    process.env.TWILIO_API_KEY,
    process.env.TWILIO_API_SECRET,
    { accountSid: process.env.TWILIO_ACCOUNT_SID }
);
```

---

## OAuth2 Authentication (Client Credentials)

Time-limited bearer tokens that expire after 1 hour. More secure than permanent API keys for server-to-server communication.

### Step 1 — Create an OAuth App

Create an OAuth App in the Twilio Console to get a Client ID and Client Secret.

### Step 2 — Request a Bearer Token

**cURL**
```bash
curl -X POST 'https://oauth.twilio.com/v2/token' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'client_id={ClientID}' \
  -d 'client_secret={ClientSecret}' \
  -d 'grant_type=client_credentials'
```

**Response:**
```json
{
    "access_token": "{BearerToken}",
    "token_type": "Bearer",
    "expires_in": 3600
}
```

### Step 3 — Use the Bearer Token

```bash
curl 'https://api.twilio.com/2010-04-01/Accounts/{AccountSID}/Messages.json' \
  -H 'Authorization: Bearer {BearerToken}'
```

### SDK Support

OAuth2 is supported in all Twilio SDKs:

| Language | Minimum version |
|----------|----------------|
| Java | 10.6.0 |
| C#/.NET | 7.6.0 |
| Node.js | 5.4.0 |
| Python | 9.4.1 |
| Ruby | 7.4.0 |
| PHP | 8.5.0 |
| Go | 1.25.1 |

**Docs:** [OAuth access tokens](https://www.twilio.com/docs/iam/oauth-apps/oauth-access-token) | [Segment OAuth connections](https://www.twilio.com/docs/segment/connections/oauth)

---

## Access Tokens (Client-Side SDKs)

Short-lived JWTs for authenticating browser/mobile clients. Generate server-side, pass to the client.

**Python**
```python
from twilio.jwt.access_token import AccessToken
from twilio.jwt.access_token.grants import VoiceGrant

token = AccessToken(
    os.environ["TWILIO_ACCOUNT_SID"],
    os.environ["TWILIO_API_KEY"],
    os.environ["TWILIO_API_SECRET"],
    identity="user-123",
    ttl=3600
)
token.add_grant(VoiceGrant(outgoing_application_sid="APxxxx"))
print(token.to_jwt())
```

Grant types: `VoiceGrant`, `VideoGrant`, `ChatGrant` (Conversations), `SyncGrant`

---

## Test Credentials

Make API calls without charges. Find at Console → Account → API keys & tokens → Test credentials.

Magic numbers: `+15005550006` (valid), `+15005550001` (invalid, error 21211), `+15005550007` (no SMS, error 21612)

---

## CANNOT

- **Standard keys cannot access /Accounts or /Keys endpoints** — Returns 20003 (401). Use Auth Token or Main key.
- **Cannot create restricted keys via v2010 API** — Silently creates a standard key instead. Use v1 IAM API.
- **Restricted keys cannot generate Access Tokens** — Only Standard and Main keys can.
- **Cannot revoke individual Access Tokens** — Valid until expiration (max 24h). Delete the issuing API key to revoke all.
- **OAuth2 only supports `client_credentials` grant** — No refresh tokens, no authorization code flow.
- **OAuth2 tokens expire after 1 hour** — Your application must handle token refresh.
- **API Key Secret shown only at creation** — Cannot be retrieved afterward.
- **Auth Token rotation breaks ALL API keys** — One-way door. This is why you should use API keys from day one.
- **Test credentials work with only 4 endpoints** — Messages, Calls, IncomingPhoneNumbers, Lookups. All others return 403.

---

## Next Steps

- **Account setup and sub-accounts:** `twilio-account-setup`
- **HIPAA account configuration:** `twilio-security-compliance-hipaa`
- **Webhook signature validation:** `twilio-webhook-architecture`
- **Credential security patterns:** `twilio-security-hardening`

© Twilio · MIT · openai/plugins

Similar skills

All skills for Security →

From the same set337

The whole set →
twilio-verify-send-otp A skill that walks your agent through the full OTP lifecycle in Twilio Verify: create a service, send a code, check the submitted one. CX Codex GP ChatGPT ★ 7,596repo stars twilio-isv-sms-best-practices A skill for teams embedding SMS into a SaaS platform where customers message their own end users. Covers A2P 10DLC and toll-free onboarding, subaccounts and billing. CX Codex GP ChatGPT ★ 7,596repo stars twilio-sendgrid-inbound-parse A skill that walks your agent through SendGrid Inbound Parse: MX records, parsed vs raw mode, attachments and the usual pitfalls. CX Codex GP ChatGPT ★ 7,596repo stars twilio-sendgrid-email-send A skill that shows the agent how to send mail through the SendGrid v3 Mail Send API: single sends, batch sends with templates, scheduled sends and attachments. Requires an SG-prefixed API key. CX Codex GP ChatGPT ★ 7,596repo stars twilio-rcs-messaging A Claude and Claude skill that walks you from RCS sender onboarding to sending rich cards and carousels through Twilio. CX Codex GP ChatGPT ★ 7,596repo stars twilio-notifications-alerts-advisor Walks you through channel choice, urgency, delivery confirmation and fallback chains for transactional messages. CX Codex GP ChatGPT ★ 7,596repo stars twilio-lookup-phone-intelligence A Claude and Claude skill that validates phone numbers through Twilio Lookup v2 and scores fraud risk before you send an SMS or place a call. CX Codex GP ChatGPT ★ 7,596repo stars twilio-debugging-observability Walks through why messages fail to deliver and calls drop, then sets up Twilio monitoring for production. CX Codex GP ChatGPT ★ 7,596repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor