How I cut our OpenAI API costs by 67% with prompt caching
A multi-agent WhatsApp system, an API bill growing with every customer, and the one-line config change that cut our OpenAI costs by 67%.
Carlos Peraza · 4 min read

On this page
A while ago I built a system of AI agents that serves thousands of people a month over WhatsApp. It worked well. So well that the problem stopped being technical and became financial: every new customer grew the OpenAI API bill almost in the same proportion.
This is how I cut that cost by 67% without touching the quality of the service, and what I learned along the way.
The setup
The platform is connected to the WhatsApp Business API. Behind it there are several agents, each specialized in one area, handing the conversation to one another depending on what the customer needs. One identifies the intent, another answers questions about a specific topic, another runs a particular process, and so on. Customer service ended up almost 100% automated.
When growth starts to hurt
A multi-agent system has a detail you don't notice at first: on every message, the model receives a lot of text that never changes. The agent's instructions, the description of its tools, the business rules and a good part of the conversation history travel in full with every request. And when one agent hands the case to another, that context gets sent again.
With a few customers, it didn't matter. But customers grew, messages grew, and the cost followed closely. At some point the daily spend set off an alarm and I had to change the approach.
Step one: a newer model
The first move was migrating to a newer model, gpt-5.6 terra. With that base in place, the change that really moved the needle came next.
Step two: prompt caching
Prompt caching lets the provider keep the part of the prompt it has already processed. If the next request starts exactly the same way, those tokens aren't processed from scratch again: they're read from the cache, billed at a significant discount, and the response comes back faster.
The key is the word "exactly". The cache works by prefix: it compares the beginning of the request with what it already has stored. If something changes at the start, everything after it stops being reused. That's why it fits agents so well: their instructions and tools are always the same.
To turn it on, I added a single line to each agent's model configuration:
extra_args={"prompt_cache_key": PROMPT_CACHE_KEY},The prompt_cache_key parameter tells OpenAI which requests share the same prefix, so it routes them to the same cache. Without it, nearly identical requests can end up processed in different places and reuse nothing. With it, the agents' repeated context starts being read from the cache instead of being paid in full every time.
The results
The chart shows the daily API spend. The change is obvious at a glance:

Before the change, spend ranged between 115 and 195 dollars a day. Afterwards it settled between 30 and 60 dollars, with the same service volume. Overall, a 67% reduction in API cost.
The cache metrics explain why:

- 85.9% of input tokens were read from the cache. Almost 9 out of every 10 tokens we sent had already been processed.
- 18.24 reads per write. Every time something was cached, it was reused about 18 times on average.
- 1.488 billion tokens served from the cache, versus 162 million that had to be fully processed.
What I learned
Sometimes the biggest saving is one line of configuration. Before cutting features or switching providers, it's worth checking what the API you already use has to offer.
Multi-agent systems are ideal for this. Precisely because they repeat so much context, they benefit the most. The longer each agent's static prompt, the bigger the savings.
Measure from day one. The usage dashboard is the best way to estimate and monitor costs.
Cutting costs doesn't have to make the product worse. The service kept working the same way. The only thing that changed was how much we paid for it.
If you run agents in production and your API bill grows at the pace of your users, check whether you're taking advantage of prompt caching before you think about cutting features. You're probably paying many times for the same text.
- Prompt Caching
- OpenAI
- AI Agents
- LLM Costs
Comments
No comments yet. Be the first to share your thoughts.