How to Connect Your Twilio Agent to External APIs with PHP
Blog post from Twilio
A Twilio tutorial explains how to build a PHP voice AI agent that uses Conversation Relay, OpenAI tool calling, and external REST APIs to provide real-time information and actions during phone conversations. Using PHP 8.5, OpenSwoole, Composer, ngrok, and a Twilio voice-enabled number, the example creates a WebSocket-based application that receives voice prompts, converts them into conversational messages, streams responses from OpenAI, and returns spoken text through Twilio. The demonstration configures an OpenAI function tool that retrieves a random fact from the unauthenticated Cat Facts API, with a system prompt requiring the model to call the API rather than invent facts. It also covers environment-variable configuration, TwiML setup for incoming calls, session and interruption handling, API error handling, exposing the local server with ngrok, and configuring the Twilio phone-number webhook. The approach can be extended to authenticated services such as customer databases, inventory systems, calendars, and booking platforms, enabling voice agents to access live data and perform customer-facing tasks.
| Trend | Post Mentions | Total Month Mentions | Posts | Companies | MoM |
|---|---|---|---|---|---|
| AI Agents | 4 | 5,784 | 1,463 | 277 | -5% |
| Voice AI | 4 | 3,423 | 311 | 54 | +20% |
| LLM | 3 | 6,074 | 1,188 | 248 | +14% |
| Real-time | 3 | 4,886 | 1,109 | 246 | +3% |
| Serverless | 1 | 1,232 | 286 | 105 | +38% |
Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.