Route Phone Calls to an AI Agent With the Telnyx Voice API<br>_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream max-header-md:typography-h3-mobile">Products_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream max-header-md:typography-h3-mobile">Solutions_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream max-header-md:typography-h3-mobile">Pricing_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream max-header-md:typography-h3-mobile">Why Telnyx_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream max-header-md:typography-h3-mobile">Resources_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream max-header-md:typography-h3-mobile">Developers<br>_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream">Contact us_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream">Log in<br>_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream">Contact us_[data-state='open'])_>_*:not([data-state='open'])_&]:text-gray-inactive header-md:[[data-state='open']_&]:dark:text-cream">Log inSign upOpen menu
Back to blog&]:translate-x-xxs ml-xxs [.link-rtl>&]:order-[-1] [.link-rtl>&]:ml-[0] [.link-rtl>&]:mr-xxs [.link-rtl:hover>&]:-translate-x-xxs"><br>Voice<br>Route Phone Calls to an AI Agent With the Telnyx Voice API
Route inbound phone calls to an AI agent with Telnyx Call Control. Webhook-driven voice infrastructure: answer, speak, gather input, and hang up programmatically.
By Harpreet Singh Seehra
svg]:w-full [&>svg]:h-full">svg]:w-full [&>svg]:h-full">svg]:w-full [&>svg]:h-full"><br>div:first-child_p:first-child]:mt-[0px] [&>div:first-child_h2:first-child]:mt-[0px] [&_p:first-of-type]:mt-[0px] sm:col-span-8 md:col-[5/13]">To route phone calls to an AI agent, connect Telnyx span]:typography-paragraph md:[&>span]:typography-paragraph-md" style="color:#00C894;text-decoration:none;border-bottom:1px solid rgba(0,227,170,0.3)" href="https://telnyx.com/products/phone-numbers">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 span]:typography-paragraph md:[&>span]:typography-paragraph-md" style="color:#00C894;text-decoration:none;border-bottom:1px solid rgba(0,227,170,0.3)" href="https://telnyx.com/products/voice-api">Voice API provides programmable voice with WebSocket support, SIP and PSTN, and global coverage. Telnyx span]:typography-paragraph md:[&>span]:typography-paragraph-md" style="color:#00C894;text-decoration:none;border-bottom:1px solid rgba(0,227,170,0.3)" href="https://telnyx.com/products/voice-ai">Voice AI adds sub-500ms latency, multi-model support, and co-located infrastructure when you want a managed voice AI agent.<br>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.<br>Note: The curl examples below are the minimal call path from the original sample. The sample answers an inbound call, speaks a TTS message, and hangs up. Insert your AI agent logic in the same event loop.<br>Route phone calls to AI agent workflow<br>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.<br>Call Control flow<br>Caller calls Telnyx number<br>call.initiated webhook<br>App sends answer<br>call.answered event<br>Speak or agent logic<br>call.speak.ended event<br>App sends hangup
Call flow steps<br>A customer calls your Telnyx number. Telnyx sends a call.initiated webhook to your application with the caller's number, your number, and a call_control_id you use for later commands on this call.<br>Your application answers. Your webhook handler calls POST /v2/calls/[call_control_id]/actions/answer. Telnyx sends call.answered when the call connects.<br>Your application responds. The sample calls POST /v2/calls/[call_control_id]/actions/speak with payload, voice, and language_code. Telnyx sends call.speak.ended when playback finishes.<br>Your application ends the call. It calls POST /v2/calls/[call_control_id]/actions/hangup. Telnyx sends call.hangup. The hangup_reason field tells...