I’ve always hated phone menus. "Press 1 for sales, 2 for support." By the time you reach the right department, you've listened to three minutes of hold music. I wanted to build something better: a call router that just asks you what you need and routes you instantly.
I built this using Telnyx. Not just their voice API, but their new Edge Runtime. Here’s why that matters.
Building voice AI is usually a glue-code nightmare. You need a telephony provider, a speech-to-text service, an LLM provider, and a database to store your routing logic. That’s four different API keys, four different SDKs, and four points of failure.
When latency spikes on the LLM, the caller waits. When the database connection drops, the call fails.
Telnyx is AI Communications Infrastructure. They own the telephony network, the AI inference layer, and now, an edge compute runtime.
For this project, I used a StatefulActor
on the Edge Runtime. When a call comes in, the runtime spins up an actor dedicated to that call leg. This actor holds the call state in memory. No external session database is required.
To classify the caller's intent, I used the built-in AI Inference binding. It looks like this:
const completion = await this.env.TELNYX.ai.openai.chat.createCompletion({
model: 'meta-llama/Llama-3.3-70B-Instruct',
messages: [...]
});
Notice anything missing? API keys. The binding is pre-authenticated. The runtime handles the credentials. I just call the model.
Once the LLM tells me the caller wants "billing," I need to know where to transfer them. I stored the route table in Telnyx KV, a globally distributed key-value store.
const destination = await this.env.ROUTES.get('route:billing');
If the key is missing, it falls back to a default destination.
gather_using_ai
captures the caller's request.All of this happens in one edge function. No external servers. No glue code.
When you build on AI Communications Infrastructure, you stop stitching together disparate services. You start composing capabilities. The telephony, the AI, and the compute live in the same place. The latency is lower. The code is cleaner.
If you want to see the code, I’ve open-sourced it. You can deploy it right now with the Telnyx CLI.