Twilio Integration
Learn how to integrate a Conversational AI agent with Twilio to create seamless, human-like voice interactions.
Connect your ElevenLabs Conversational AI agent to phone calls and create human-like voice experiences using Twilio’s Voice API.
What You’ll Need
- An ElevenLabs account
- A configured ElevenLabs Conversational Agent (create one here)
- A Twilio account with an active phone number
- Python 3.7+ or Node.js 16+
- ngrok for local development
Agent Configuration
Before integrating with Twilio, you’ll need to configure your agent to use the correct audio format supported by Twilio.
Configure TTS Output
- Navigate to your agent settings
- Go to the Voice Section
- Select “μ-law 8000 Hz” from the dropdown
Set Input Format
- Navigate to your agent settings
- Go to the Advanced Section
- Select “μ-law 8000 Hz” for the input format
Implementation
Looking for a complete example? Check out this Javascript implementation on GitHub.
Initialize the Project
First, set up a new Node.js project:
Install dependencies
Next, install the required dependencies for the project.
Create the project files
Create a .env
& index.js
file with the following code:
Run the server
You can now run the server with the following command:
If the server starts successfully, you should see the message [Server] Listening on port 8000
(or the port you specified) in your terminal.
Twilio Setup
Create a Public URL
Use ngrok to make your local server accessible:
Configure Twilio
- Go to the Twilio Console
- Navigate to
Phone Numbers
→Manage
→Active numbers
- Select your phone number
- Under “Voice Configuration”, set the webhook for incoming calls to:
https://your-ngrok-url.ngrok.app/incoming-call-eleven
- Set the HTTP method to POST
Testing
- Call your Twilio phone number.
- Start speaking - you’ll see the transcripts in the ElevenLabs console.
Troubleshooting
Security Best Practices
Follow these security guidelines for production deployments:
- Use environment variables for sensitive information
- Implement proper authentication for your endpoints
- Use HTTPS for all communications
- Regularly rotate API keys
- Monitor usage to prevent abuse
Was this page helpful?