Cloudflare significantly reduced the cost and latency of its AI code reviewer by 68% through aggressive optimization. This involved strategically leveraging LLM prompt caching, reducing the number of API calls, and carefully selecting models and effort levels. The article details the architectural adjustments and operational insights gained from this optimization effort.
Read original on Cloudflare BlogCloudflare's AI code reviewer saw its average cost per review double, primarily due to models becoming more capable (leading to larger, more complex code changes needing 'full reviews') and the adoption of more advanced, albeit more expensive, LLMs like Anthropic's Claude Opus. Critically, token usage per review tripled, from 0.91 million to 2.99 million, indicating increased context processing despite a high cache hit rate.
The optimization effort focused on two main areas: code changes within the reviewer system (accounting for 40% of savings) and experimenting with LLM models and their 'effort' levels (the remaining 60%).
System Design Takeaway
When integrating with large language models, treat API calls and token usage as critical performance and cost metrics. Design your system to maximize caching opportunities for common prompts and context, minimize redundant information sent in each request, and strategically select models and inference parameters based on a clear understanding of cost-benefit trade-offs for different workloads.