Insights6 min read
Building a Production Voice AI Pipeline: WhatsApp, Whisper and Prompt Caching
Lessons from a 24/7 WhatsApp voice pipeline with Whisper, Claude replies and the prompt caching setup that cut input-token costs by roughly 90%.
Muhammad Mubashir
Founder & CEO, Retrieva Labs
- Voice AI
- Prompt Caching
- Twilio
- Claude API
The problem
A recovery-support SaaS client needed their AI sponsor chatbot to be reachable by voice over WhatsApp, not just text. For users who wanted to talk through something difficult without typing it out, this mattered. It meant a full round trip: receive a voice note, understand it, generate a thoughtful reply and send that reply back as synthesized speech, all inside a latency budget that still felt like a conversation.
The pipeline
Twilio's WhatsApp Business API receives the incoming voice note and hands it off. Whisper transcribes it to text. That text goes to Claude along with the conversation's system prompt and history. The reply comes back as text, is synthesized to speech, and goes out over WhatsApp as a voice reply.
Every one of those hops adds latency, so the part of the system I spent the most time on wasn't any single component. It was making sure the LLM call, the most expensive and slowest hop, wasn't also the most wasteful one.
Where prompt caching pays off
The system prompt for this chatbot is long: personality, safety guardrails, crisis-detection instructions and conversation guidelines. Without caching, that entire block is resent and reprocessed as input tokens on every turn of every conversation. For a product meant to be available 24/7, that adds up fast.
Prompt caching fixes this by letting the model provider cache the processing of a stable prefix and reuse it across calls, so you pay full input-token price far less often. On this project it brought input-token costs down by roughly 90%.
The catch is that caching only helps if the cached prefix is genuinely stable and comes first in the prompt. I structure every request as: system prompt and static instructions first, then conversation history, then the new user turn last. The moment something volatile is inserted before the stable block, the cache stops matching and you are back to paying full price without realizing it. So I added logging on cache-hit rate specifically, not just latency or token count, because it is the one metric that silently degrades without showing up anywhere else.
Testing a pipeline you can't easily eyeball
Voice is hard to spot-check the way you can read a chat transcript. I built a 12-category automated test suite covering chat logic, session handling, webhook behavior and security boundaries separately from the audio hops, so a regression in conversation quality couldn't hide behind "did the audio play correctly."
Lessons learned
A latency budget forces different trade-offs than a text chatbot. A response that reads as fine when typed can feel sluggish when someone is waiting for a voice reply, so time to first token mattered more here than it would for a text-only product.
And caching is a design constraint, not a configuration flag you switch on afterwards. The prompt structure has to be built around it from the start, or you end up rewriting the request assembly once you realize the savings aren't materializing.