Route inbound phone calls to an AI agent with Telnyx Call Control. Webhook-driven voice infrastructure: answer, speak, gather input, and hang up programmatically.

To route phone calls to an AI agent, connect Telnyx Phone Numbers, available in 140+ countries with instant activation, to a Call Control Application. Telnyx sends call control webhooks to your app. Your app answers the call with call_control_id, runs agent logic, then sends commands back to Telnyx. The Telnyx Voice API provides programmable voice with WebSocket support, SIP and PSTN, and global coverage. Telnyx Voice AI adds sub-500ms latency, multi-model support, and co-located infrastructure when you want a managed voice AI agent.
This guide covers the voice infrastructure layer. You will see the webhook loop, the exact Call Control API actions for answer, speak, and hangup, and where to place AI inference. The sample app uses Python Flask and follows the route-phone-calls-to-ai-agent-python example.
A voice AI agent cannot answer a PSTN call by itself. It needs a carrier layer, a webhook endpoint, and call commands. Telnyx handles the carrier layer. Your application handles state and business rules. The AI agent handles dialog decisions.
Call Control flow
Telnyx Call Control is a webhook-driven API for programmable voice. Instead of static IVR menus, your application receives HTTP events for every call state change and responds with commands.
The event loop is direct. Telnyx sends a webhook to your application. Your app processes the event. Your app issues a Call Control command. Telnyx sends the next event when that command completes. This cycle repeats for the life of the call.
This pattern is what makes inbound call automation practical. Your app can put model inference, CRM lookup, fraud checks, routing rules, or text-to-speech between the event and the command. For a broader build path, read the Voice API guide.
Everything below works with any language or framework. You need an HTTP endpoint to receive webhooks and an HTTP client to send Call Control commands.
When you receive a call.initiated webhook, answer the call with this command.
curl -X POST https://api.telnyx.com/v2/calls/{call_control_id}/actions/answer \
-H "Authorization: Bearer YOUR_TELNYX_API_KEY" \
-H "Content-Type: application/json"
The call_control_id comes from the call.initiated webhook payload. It is the handle you use to issue every later command on this call.
Once the call is connected, play a text-to-speech message.
curl -X POST https://api.telnyx.com/v2/calls/{call_control_id}/actions/speak \
-H "Authorization: Bearer YOUR_TELNYX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"payload": "Thank you for calling. Your call is important to us. Goodbye.",
"voice": "female",
"language_code": "en-US"
}'
The payload field is the text to speak. The voice field accepts female or male. The language_code field controls the language and accent. en-US, en-GB, es-ES, and others are supported. When playback finishes, Telnyx sends a call.speak.ended webhook event.
When the flow is done, terminate the call.
curl -X POST https://api.telnyx.com/v2/calls/{call_control_id}/actions/hangup \
-H "Authorization: Bearer YOUR_TELNYX_API_KEY" \
-H "Content-Type: application/json"
Telnyx sends a call.hangup event to confirm the call has ended. The hangup_reason field in the event payload tells you why the call terminated.
Telnyx signs every webhook request with an Ed25519 signature. Your application should verify this signature before processing the event. That check rejects requests that did not come from Telnyx.
The Telnyx SDKs handle this automatically. In Python, call client.webhooks.unwrap() with the raw request body and headers. This requires the TELNYX_PUBLIC_KEY environment variable, which you can find in the Mission Control Portal.
Most inbound AI flows start with a Telnyx number. Buy or port the number, assign it to a Call Control Application, and set your webhook URL to your /webhooks/call endpoint.
Existing PBX traffic can come through Telnyx SIP Trunking, an enterprise-grade service with a 99.999% uptime SLA. Keep SIP for agents or legacy queues, then route selected calls into programmable voice when automation should answer. For migration basics, read the SIP trunking guide.
Teams building for contact centers can route by number, queue, department, or caller intent. Start with one flow. Measure containment and transfer rate. Expand when the data supports it.
| Option | Best fit | Control model |
|---|---|---|
| Static IVR | Simple menus with fixed paths | Configuration driven |
| Call Control API | Custom inbound call automation | Webhook events plus commands |
| Voice AI | Managed voice AI agent flows | Agent runtime on Telnyx voice infrastructure |
The sample app speaks a fixed sentence. A production voice AI agent replaces that decision point. After your app receives an event or caller input, it calls your model or managed agent. The returned decision maps to a Call Control command.
Wait for call_control_id before sending commands. Verify signatures first. Treat call.speak.ended as the signal that TTS playback has finished before issuing the next command.
Every call state change arrives as an HTTP event. Your app stays in control without polling or long-lived connections.
Answer, speak, gather DTMF or speech, transfer, conference, record. One API covers the entire call lifecycle.
Telnyx operates a private global IP network. Voice traffic avoids unnecessary public internet hops, reducing latency and improving call quality.
Pay for what you use. No inflated per-minute fees or hidden platform surcharges.
| Feature | Static IVR | Call Control |
|---|---|---|
| Call flow | Fixed menu tree | Programmable state machine |
| AI integration | Limited or bolted on | Native, inserted between events |
| Response logic | Pre-recorded prompts | Dynamic TTS, any voice or language |
| Scalability | Menu depth limits | Unlimited conversation turns |
Telnyx provides a working Python Flask example that implements webhook signature verification, Call Control event handling, text-to-speech, and error handling. Clone the route-phone-calls-to-ai-agent-python example from GitHub.
The example includes a webhook endpoint at /webhooks/call, a state machine that answers inbound calls and plays a TTS greeting, and proper error handling for authentication, rate limiting, and API errors.
/webhooks/call endpointTELNYX_API_KEY and TELNYX_PUBLIC_KEY environment variablesFull API documentation is available at developers.telnyx.com. For more on messaging automation, see the SMS auto-reply bot and WhatsApp OTP guides.
Route calls to your AI agent todayOne webhook endpoint. Full call control. Sub-500ms latency with co-located Voice AI.
Get started freeRelated articles