twilio-reliability-patterns
This skill teaches patterns for handling rate limits and failures when using Twilio at scale, including exponential backoff with jitter for 429 errors…
Identity proven by GitHub's verified organisation badge (twilio)
- Agents
- Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode, claude.ai and API
- License
- MIT (permissive)
- Pin
- 8aba46fpinned Oct 9, 2026
- Context cost
- about 2,700 tokenswhen the skill loads
- GitHub stars
- 37on twilio/ai
- Scripts
- None found
What it does
“Handle rate limits, retries, and failures when building on Twilio at scale. Covers 429 exponential backoff with jitter, per-number throughput limits, StatusCallback resilience, thin-receiver pattern, and fallback chains. Use this skill whenever sending messages or making calls at volume, or when building production-grade Twilio integrations.”
Generated summary from the skill's own text
This skill teaches patterns for handling rate limits and failures when using Twilio at scale, including exponential backoff with jitter for 429 errors, per-number throughput management, resilient webhook callbacks using the thin-receiver pattern, and fallback chains across channels. It covers production-grade reliability for SMS, voice calls, and status callbacks with code examples in Python and Node.js.
When to use it
- Sending SMS or making calls at high volume to many recipients
- Building production Twilio integrations requiring StatusCallback webhooks
- Handling 429 rate limit errors from Twilio APIs
- Implementing fallback delivery chains across SMS, voice, and email
When not to
- Testing Twilio with low message volume or single recipients
- When your application cannot implement async callback processing
- If you need to configure Twilio's own retry behavior directly
Install
These commands install from the publisher's repository and need no account.
skills CLI
npx skills add twilio/ai --skill twilio-reliability-patternsInstalls from the repository's default branch, which may have changed since the commit we checked.
GitHub CLI 2.90 or later
gh skill install twilio/ai twilio-reliability-patterns@8aba46fb65dc8d9a20f4b301a68352064b4159a5Installs the commit we checked (8aba46f).
Copy by hand
Download the folder at 8aba46f and put it in .claude/skills/twilio-reliability-patterns for Claude Code and in .agents/skills/twilio-reliability-patterns for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode.
Claude Code plugin
/plugin install twilio-developer-kit@claude-plugins-officialThe publisher's plugin in Claude's official marketplace. It may hold more than this skill, and we have not pinned it.
Copy for your agent
A prompt for any coding agent. It installs this skill from GitHub at the pinned commit, copies the files as they are, and runs nothing unless you ask.
Prompt
Install the agent skill "twilio-reliability-patterns" by Twilio. Source, pinned to commit 8aba46fb65dc8d9a20f4b301a68352064b4159a5: https://github.com/twilio/ai/tree/8aba46fb65dc8d9a20f4b301a68352064b4159a5/skills/twilio/twilio-reliability-patterns 1. Download that folder at exactly this commit. Do not use the default branch. 2. Copy every file unchanged, keeping the folder structure, into .claude/skills/twilio-reliability-patterns/ for Claude Code and .agents/skills/twilio-reliability-patterns/ for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode. Create the folders if they do not exist. 3. Do not edit the files, and do not run any script in the folder unless I ask you to. 4. When you are done, list the files you copied and where you put them. Listing and checks: https://www.agentnative.dev/skills/twilio/twilio-reliability-patterns
SKILL.md at the pin
---
name: twilio-reliability-patterns
description: >
Handle rate limits, retries, and failures when building on Twilio at
scale. Covers 429 exponential backoff with jitter, per-number throughput
limits, StatusCallback resilience, thin-receiver pattern, and fallback
chains. Use this skill whenever sending messages or making calls at
volume, or when building production-grade Twilio integrations.
---
## Overview
Twilio enforces per-resource rate limits. At scale, 429 errors are expected behavior — not bugs. This skill teaches the patterns that prevent production failures: exponential backoff, throughput management, and resilient callback handling.
429 concurrency errors are not well documented — implement exponential backoff with ±10% jitter.
---
## Prerequisites
- A working Twilio integration (any product)
- Understanding of your expected volume (messages/sec, calls/sec)
- StatusCallback URLs configured — see `twilio-messaging-services`, `twilio-sms-send-message`
---
## Key Patterns
### 1. Exponential Backoff with Jitter
When you receive a 429 (Too Many Requests), wait and retry. Naive fixed-interval retry creates thundering herds. Use exponential backoff with randomized jitter.
**Python**
```python
import time, random, requests
def send_with_backoff(client, to, body, messaging_service_sid, max_retries=5):
for attempt in range(max_retries):
try:
message = client.messages.create(
to=to,
body=body,
messaging_service_sid=messaging_service_sid,
status_callback="https://yourapp.com/status"
)
return message
except Exception as e:
if hasattr(e, 'status') and e.status == 429:
# Exponential backoff: 100ms, 200ms, 400ms, 800ms, 1600ms
base_delay = 0.1 * (2 ** attempt)
# Add ±10% jitter to prevent thundering herd
jitter = base_delay * 0.1 * (2 * random.random() - 1)
delay = min(base_delay + jitter, 30) # cap at 30 seconds
time.sleep(delay)
else:
raise # Non-429 errors: don't retry, investigate
raise Exception(f"Failed after {max_retries} retries")
```
**Node.js**
```node
async function sendWithBackoff(client, to, body, messagingServiceSid, maxRetries = 5) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
return await client.messages.create({
to,
body,
messagingServiceSid,
statusCallback: "https://yourapp.com/status",
});
} catch (err) {
if (err.status === 429) {
// Exponential backoff: 100ms, 200ms, 400ms, 800ms, 1600ms
const baseDelay = 100 * Math.pow(2, attempt);
// Add ±10% jitter
const jitter = baseDelay * 0.1 * (2 * Math.random() - 1);
const delay = Math.min(baseDelay + jitter, 30000); // cap at 30s
await new Promise(r => setTimeout(r, delay));
} else {
throw err; // Non-429: don't retry
}
}
}
throw new Error(`Failed after ${maxRetries} retries`);
}
```
**Parameters:**
- Initial delay: 100ms
- Multiplier: 2x per attempt
- Jitter: ±10% of base delay (randomized)
- Max delay: 30 seconds
- Max retries: 5 (covers up to ~3.2 second base delay)
### 2. Per-Number Throughput Limits
These limits are not prominently documented:
| Number type | SMS throughput | Voice throughput | Notes |
|-------------|---------------|-----------------|-------|
| Local (long code) | ~1 SMS/sec | 1 concurrent call | Lowest cost, lowest throughput |
| Toll-free | ~3 SMS/sec | — | Faster verification (3-5 days) |
| Short code | 10-100 SMS/sec | — | Highest throughput, 8-12 week provisioning, expensive |
| Messaging Service (pool) | Sum of all numbers in pool | — | Multiply throughput by adding numbers |
**Throughput opacity:** Sending velocity and queue depth are opaque — there is no dashboard showing messages per second. Use Messaging Services to multiply throughput by pooling numbers. A pool of 10 long codes = ~10 SMS/sec.
### 3. Bulk Send Pattern
For sending to large lists, use a rate-limited dispatch loop:
**Python**
```python
import asyncio
from collections import deque
async def bulk_send(client, recipients, body, messaging_service_sid, rate_per_second=10):
"""Send to a list of recipients with rate limiting and backoff."""
queue = deque(recipients)
results = []
while queue:
batch = []
for _ in range(min(rate_per_second, len(queue))):
batch.append(queue.popleft())
for recipient in batch:
try:
msg = send_with_backoff(client, recipient, body, messaging_service_sid)
results.append({"to": recipient, "sid": msg.sid, "status": "sent"})
except Exception as e:
results.append({"to": recipient, "error": str(e), "status": "failed"})
if queue: # Don't sleep after last batch
await asyncio.sleep(1) # 1 second between batches
return results
```
**Key:** Set `rate_per_second` based on your number pool size, not your desired speed. Sending faster than your pool supports just generates 429s.
> **Compliance:** Before bulk sending, verify recipient consent (opt-in records), respect quiet hours, and implement maximum batch size limits. Monitor for anomalous send patterns that could indicate abuse.
### 4. StatusCallback Resilience
At scale, StatusCallbacks create their own load problem.
**The math:** 50 concurrent calls × 6 status events per call = 300 webhook invocations per second. Twilio Functions allow 30 concurrent executions per service.
**Thin-receiver pattern** — receive, queue, respond immediately:
**Node.js (Express)**
```node
const { Queue } = require("bullmq");
const statusQueue = new Queue("twilio-status");
// Thin receiver: accept callback, queue it, respond 200 immediately
app.post("/status", async (req, res) => {
await statusQueue.add("status-event", {
callSid: req.body.CallSid,
callStatus: req.body.CallStatus,
timestamp: Date.now(),
});
res.sendStatus(200); // Respond FAST — Twilio will retry on timeout
});
// Process asynchronously
const worker = new Worker("twilio-status", async (job) => {
const { callSid, callStatus } = job.data;
await updateDatabase(callSid, callStatus);
});
```
**Python (Flask + Celery)**
```python
@app.route("/status", methods=["POST"])
def status_callback():
# Queue for async processing
process_status.delay(
call_sid=request.form["CallSid"],
call_status=request.form["CallStatus"]
)
return "", 200 # Respond FAST
@celery.task
def process_status(call_sid, call_status):
update_database(call_sid, call_status)
```
**Idempotency key:** Use `{CallSid}-{CallStatus}` as a composite key. Twilio retries on timeout, which can cause duplicate callbacks. Deduplicate before processing.
### 5. Fallback Chains
When delivery on one channel fails, escalate to the next:
**Python**
```python
async def send_with_fallback(client, to, message, messaging_service_sid):
"""Try SMS → Voice → Email fallback chain."""
# Try SMS first
try:
msg = client.messages.create(
to=to, body=message, messaging_service_sid=messaging_service_sid,
status_callback="https://yourapp.com/status"
)
# Wait for delivery confirmation via StatusCallback
# If undelivered after timeout, fall through to voice
return {"channel": "sms", "sid": msg.sid}
except Exception:
pass # SMS failed, try voice
# Fallback to voice
try:
call = client.calls.create(
to=to, from_="+15551234567",
twiml=f"<Response><Say>{message}</Say></Response>",
status_callback="https://yourapp.com/call-status"
)
return {"channel": "voice", "sid": call.sid}
except Exception:
pass # Voice failed, try email
# Last resort: email
# Use SendGrid — see twilio-sendgrid-email
return {"channel": "email", "status": "queued"}
```
### 6. Voice Concurrency Limits
| Resource | Default limit | Notes |
|----------|--------------|-------|
| Concurrent calls per account | 1 (trial) / variable (paid) | Request increase via support |
| Calls per second (CPS) | 1 CPS (default) | Increase via support for outbound campaigns |
| Conference participants | 250 per conference | |
| Twilio Functions concurrent | 30 per service | Use thin-receiver pattern above |
For outbound campaigns, request CPS increase before launch — not during.
### 7. Webhook Timeout Handling
Twilio expects a response within **15 seconds** for voice webhooks and **15 seconds** for messaging webhooks. If your endpoint doesn't respond:
- Voice: Twilio hangs up or falls back to `voiceFallbackUrl`
- Messaging: Twilio retries the callback
**Always configure fallback URLs:**
```python
# On phone number configuration
number = client.incoming_phone_numbers(phone_sid).update(
voice_url="https://yourapp.com/voice",
voice_fallback_url="https://yourapp.com/voice-fallback", # backup endpoint
sms_url="https://yourapp.com/sms",
sms_fallback_url="https://yourapp.com/sms-fallback"
)
```
---
## Monitoring Checklist
Set up these alerts before going to production:
| Metric | Alert threshold | How to track |
|--------|----------------|-------------|
| 429 error rate | > 5% of requests | Count 429s in your backoff handler |
| Delivery failure rate | > 2% of messages | StatusCallback `failed`/`undelivered` events |
| Webhook response time | > 5 seconds p95 | Your APM tool (DataDog, New Relic) |
| Queue depth | Growing over 5 minutes | Your message queue metrics |
| Concurrent calls | > 80% of limit | Twilio Usage API or Event Streams |
Twilio's built-in alerting systems are under-used — end-users often discover issues before developers do. Configure StatusCallbacks + Event Streams for delivery failure alerts on every integration.
---
## CANNOT
- **Cannot avoid 429 errors on any Twilio API** — Backoff patterns apply to all APIs (Messaging, Voice, Verify, Lookup)
- **Cannot increase per-number throughput** — Add more numbers via Messaging Services instead
- **Cannot configure StatusCallback retry behavior** — Twilio retries on timeout automatically; not configurable
- **Cannot exceed Twilio Functions limits** — 30 concurrent executions/service, 10-second timeout, 256 MB memory
- **Cannot use a native Twilio rate limiting API** — You must implement rate limiting in your application
---
## Next Steps
- **Messaging at scale:** `twilio-messaging-services`
- **Monitor delivery:** `twilio-sms-send-message` (StatusCallbacks)
- **Debug failures:** `twilio-debugging-observability`
- **Compliance for bulk sends:** `twilio-compliance-traffic`
From twilio/ai at 8aba46f, shown as plain text under its license: MIT (permissive). The license text is in LICENSE.
View SKILL.md on GitHub at 8aba46fFiles
- SKILL.md11 KB · 0ca7d88af0b2
- agents/
- openai.yaml455 B · 07e03281c899
- assets/
- icon-large.png9.6 KB · 0ba822e01172
- icon-small.png5.6 KB · 400e3f49b6c1
4 files, 27 KB in total. Each file has a sha256 in the pin's manifest; the first 12 characters are shown.
Skill folder on GitHub at 8aba46fMore from Twilio
twilio-account-setup
Sets up a Twilio account from scratch, including free trial signup, credential retrieval, phone number purchase, and enabling specific products like AI…
Claude Code, Codex, Cursor +4 · about 2.5K tokens · pinned 6 days ago
twilio-agent-augmentation-architect
This skill helps developers design AI-augmented contact center systems that enhance human agents with real-time intelligence.
Claude Code, Codex, Cursor +3 · about 3.6K tokens · pinned 6 days ago
twilio-agent-connect
Twilio Agent Connect is middleware that integrates LLM agents with Twilio communication channels (voice, SMS, RCS, WhatsApp, chat).
Claude Code, Codex, Cursor +4 · about 4.1K tokens · pinned 6 days ago
twilio-ai-agent-architect
Planning skill that helps developers design AI-powered conversational agents by assessing their use case across outcome sophistication, channels, and customer…
Claude Code, Codex, Cursor +3 · about 4.9K tokens · pinned 6 days ago
twilio-call-recordings
This skill teaches agents to record Twilio voice calls correctly using the appropriate method for the use case.
Claude Code, Codex, Cursor +4 · about 2.6K tokens · pinned 6 days ago
twilio-cli-reference
The Twilio CLI reference enables agents to manage Twilio resources directly from the terminal, including phone number provisioning, sending SMS and email…
Claude Code, Codex, Cursor +4 · about 1.8K tokens · pinned 6 days ago
Related in Backend and APIs
twilio-conference-calls
This skill enables multi-party call handling using Twilio Conference, covering warm and cold transfers, hold versus mute, supervisor coaching with whisper…
by TwilioOfficial publisher
Claude Code, Codex, Cursor +4 · about 2.8K tokens · pinned 6 days ago
twilio-content-template-builder
This skill enables agents to create, manage, and send message templates through Twilio's Content API across WhatsApp, SMS, RCS, and MMS channels.
by TwilioOfficial publisher
Claude Code, Codex, Cursor +4 · about 1.3K tokens · pinned 6 days ago
twilio-conversation-orchestrator
This skill configures Twilio Conversation Orchestrator to automatically capture and route SMS, voice, WhatsApp, RCS, and web chat into unified conversations.
by TwilioOfficial publisher
Claude Code, Codex, Cursor +4 · about 8.3K tokens · pinned 6 days ago
twilio-conversations-classic-api
Build multi-channel messaging conversations using Twilio's classic API, combining SMS, WhatsApp, and web chat participants in persistent threads with message…
by TwilioOfficial publisher
Claude Code, Codex, Cursor +4 · about 4.2K tokens · pinned 6 days ago
twilio-iam-auth-setup
This skill guides agents through setting up Twilio authentication methods including Auth Tokens, API Keys (Standard, Main, Restricted), Access Tokens for…
by TwilioOfficial publisher
Claude Code, Codex, Cursor +4 · about 2.3K tokens · pinned 6 days ago
twilio-isv-sms-best-practices
This skill guides ISVs building multi-tenant SMS platforms on Twilio through subaccount architecture, customer onboarding for A2P 10DLC and toll-free…
by TwilioOfficial publisher
Claude Code, Codex, Cursor +4 · about 2.7K tokens · pinned 6 days ago