Why You Need a Tunnel
Twilio’s servers need to reach your application:- Voice Webhooks - TwiML instructions when a call starts (
POST /twilio/voice) - Media Streams - Real-time audio WebSocket (
WSS /twilio/media-stream)
Tunnel Providers
Agentic AI supports two popular tunnel providers:ngrok
Popular, easy to use, generous free tier
Cloudflare Tunnel
Enterprise-grade, unlimited bandwidth, free
ngrok Setup
ngrok is the most popular tunneling solution and easiest to get started with.Step 1: Install ngrok
Step 2: Get Your Auth Token
- Sign up at ngrok.com
- Go to dashboard.ngrok.com/get-started/your-authtoken
- Copy your authtoken
Step 3: Configure ngrok
Step 4: Start the Tunnel
Copy the
https://abc123.ngrok.io URL - this is your webhook URL!Step 5: Configure Agentic AI
Add the ngrok URL to your.env (optional):
ngrok Free vs Paid
| Feature | Free | Paid ($8/month) |
|---|---|---|
| Tunnel count | 1 online tunnel | 3+ tunnels |
| URL format | Random (https://abc123.ngrok.io) | Custom domain |
| URL persistence | Changes on restart | Fixed domain |
| Rate limiting | 40 requests/minute | Higher limits |
| Best for | Development | Production |
Cloudflare Tunnel
Cloudflare Tunnel (formerly Argo Tunnel) is a free, enterprise-grade alternative with unlimited bandwidth.Step 1: Install cloudflared
Step 2: Authenticate
Step 3: Create a Tunnel
Step 4: Configure the Tunnel
Create~/.cloudflared/config.yml:
YOUR_USERwith your usernameabc123-def456-ghi789with your actual tunnel IDagenticai.yourdomain.comwith a subdomain you own
Step 5: Add DNS Record
Step 6: Start the Tunnel
https://agenticai.yourdomain.com!
Step 7: Configure Agentic AI
Updateconfig.yaml:
Run as a Service
Install cloudflared as a system service for automatic startup:Cloudflare Tunnel Benefits
- Free, unlimited bandwidth
- Fixed custom domain
- DDoS protection
- No rate limiting
- Enterprise-grade reliability
- Survives restarts
Cloudflare Tunnel requires you to own a domain managed by Cloudflare.
Configuration Reference
Configure tunnel behavior inconfig.yaml:
Enable automatic tunnel startup.Set to
true only if you want Agentic AI to manage the tunnel process.The tunnel provider to use.Options:
ngrok- Most popular, easy setupcloudflare- Enterprise-grade, custom domain
A fixed tunnel URL (for paid plans with custom domains).Examples:
- ngrok:
https://myapp.ngrok.io - Cloudflare:
https://agenticai.yourdomain.com
Setting Up Twilio Webhooks
Once your tunnel is running, configure Twilio to use it:For Incoming Calls
- Go to Twilio Console → Phone Numbers → Manage → Active Numbers
- Click your phone number
- Under “Voice & Fax” → “A call comes in”:
- Set to: Webhook
- URL:
https://your-tunnel-url.com/twilio/voice - Method: HTTP POST
- Click Save
For Outgoing Calls
When triggering calls via CLI, pass the webhook URL:/twilio/voice to the webhook path.
Webhook Endpoints
Your tunnel exposes these endpoints:| Endpoint | Protocol | Purpose |
|---|---|---|
/twilio/voice | HTTP POST | TwiML webhook for call setup |
/twilio/media-stream | WebSocket | Real-time audio streaming |
/health | HTTP GET | Health check |
Testing Your Tunnel
1. Test HTTP Webhook
2. Test WebSocket Connection
Use a WebSocket client:3. Test with Actual Call
Production Considerations
Recommended Production Setup
- Deploy to cloud - AWS, GCP, Azure, DigitalOcean, etc.
- Use a real domain - e.g.,
api.yourcompany.com - Enable HTTPS - Let’s Encrypt or cloud provider SSL
- Set up monitoring - Track webhook health
- Configure firewall - Only allow Twilio IPs
When to Use Tunnels
- Local development and testing
- Demos and proof-of-concepts
- Debugging webhook issues
- Short-term staging environments
When NOT to Use Tunnels
- Production deployments
- High-traffic applications
- Mission-critical services
- Compliance-sensitive environments
Troubleshooting
Tunnel not connecting
ngrok:Twilio can’t reach webhook
- Verify tunnel is running:
- Check Agentic AI server is running:
- Check firewall - Ensure port 8080 is accessible locally
-
Check Twilio webhook logs:
- Go to Twilio Console → Monitor → Logs → Errors
Random disconnections
- ngrok free tier - Has timeout limits, upgrade or switch to Cloudflare
- Network instability - Check your internet connection
- Server crashes - Check Agentic AI logs:
agenticai service logs
URL changes on restart (ngrok)
Free ngrok URLs are temporary. Options:- Upgrade to paid - Get a fixed domain ($8/month)
- Use Cloudflare Tunnel - Free fixed domain
- Script the update - Auto-update Twilio webhooks on restart
SSL/TLS errors
Twilio requires HTTPS. Both ngrok and Cloudflare provide automatic SSL:- ngrok:
https://abc123.ngrok.io(automatic) - Cloudflare:
https://agenticai.yourdomain.com(automatic)
http:// URLs with Twilio.
Advanced: Custom Tunnel Integration
If you’re using a different tunnel provider (localtunnel, bore, etc.), configure it manually:- Start your custom tunnel
- Set
tunnel.enabled: falseinconfig.yaml - Pass the webhook URL when starting:
Related Configuration
- Configuration File - Server and tunnel settings
- Environment Variables - API keys and credentials
- Quickstart Guide - Complete setup walkthrough