MLOps

LLM Inference Cost: How Cloudflare Cut Its Bill by 68%

LLM inference cost: Cloudflare took its AI code reviewer from $2.43 to $0.77 per review with prompt caching and model A/B tests. Here's the full playbook.

LLM Inference Cost: How Cloudflare Cut Its Bill by 68%

LLM Inference Cost: How Cloudflare Cut Its Bill by 68%

Your LLM inference cost has a habit of creeping up while nobody is looking. Cloudflare just showed how far it can drift, and how to pull it back. In a post published on October 19, 2026, “Cutting our inference bill by 68% by being obsessive about optimization”, Ryan Skidmore walks through how the company's AI code reviewer went from $2.43 per review to $0.77, while median review time dropped from 4m 9s to 1m 32s.

The headline number is nice. The method is better. The team attributes every cent of savings to a specific change, and then checks, with a blinded evaluation, that the reviewer still catches real problems. If you run agents continuously in production (code review, ticket triage, document processing), this is about as close to a field manual for LLM inference cost as you will find.

The context

Cloudflare first described its AI code reviewer back in April. On every merge request, a coordinator agent looks at the change and dispatches work to specialist sub-reviewers: code quality, security, performance, and compliance with internal standards. Jobs run in GitLab CI through a Kubernetes executor, on top of the open source OpenCode agent. Risk tiers (“trivial”, “lite”, “full”) decide how heavy each review is.

Two concepts matter for what follows:

  • Prompt caching. LLM providers let you cache the beginning of a prompt (the prefix) and read it back later at a discount. With Anthropic models you place explicit cache breakpoints, as described in the prompt caching documentation. Cache writes cost more than cache reads, so a badly structured cache can cost you more than it saves.
  • Effort levels. Some models expose a setting that trades reasoning depth and output tokens for latency and price.

In April, the average review cost $1.19. By the end of August it had climbed to about $2.46, and tokens per review had grown from 0.91M to 2.99M, partly after a switch to Claude Opus models. Before the optimization work, spend broke down into 23% output tokens, 43% cache writes and 34% cache reads.

Prompt caching: the biggest hidden lever on inference cost

A shared prefix that wasn't shared

The first finding is almost embarrassingly ordinary. Every job shared 11k to 21k identical tokens: the agent prompt plus the tool definitions. Yet the first request of each session hit the cache only 14% to 26% of the time.

The cause was structural. OpenCode v1 built a single block containing the agent prompt, followed by an environment section with the working directory and the date, and placed the only cache breakpoint at the end of that block. The cached prefix therefore always contained something job-specific, which made it nearly impossible to reuse across jobs.

The September 16 fix was small. A marker was added after the agent prompt and a plugin split the block in two, so that the first half ended on bytes every job shares and got its own breakpoint. The team also stripped repository-specific content out of the prefix (disabled skill lists, locked tool descriptions). First-request cache hits rose to 91% to 99.5%, and average cost per review fell from $2.47 on September 14 to $2.02 on September 16.

A concurrency trap in multi-agent setups

The post flags a subtle constraint: a cache entry can't be read until the response that wrote it has started streaming, and the three sub-reviewers start at the same time. Launching parallel agents on the same prefix does not mean they all benefit from it. Start order matters.

Put context in the prompt, not behind tool calls

The same logic applied to the standards reviewer. Its reference index (a table of internal standards, a skill file and a list of reference files) was moved directly into the prompt instead of being discovered through tool calls. LLM calls per run dropped from 15.9 to 9.6.

Small fixes, real money

Beyond caching, the team hunted down wasted calls one by one:

  • Tools the agent could see but not use. Sub-reviewers could see the tool that posts the final review comment. They tried to call it, got rejected, and burned another call recovering. The tool is now hidden from them.
  • Batched reads. Reviewers now read the shared context and all of their patches in their first response, up to 150 KB, instead of opening files one at a time.
  • Re-reviews. About two-thirds of jobs are a second or later review of the same merge request. Reviewers with nothing new to look at are skipped; the AGENTS.md review is skipped 56% of the time.
  • Cancelled jobs. Each job checks its own status every 15 seconds and stops if cancelled, rather than finishing a review nobody will read.

Moving to OpenCode v2 in early October also made full-tier reviews 13% faster. Altogether, code changes account for $0.65 of the $1.67 reduction per review.

Models and effort levels: the other $1.06

The remaining $1.06 came from model and effort choices. The coordinator now runs Opus 5.5 at medium effort. For sub-reviewers, Cloudflare did what too few teams do: a real A/B test on production traffic. On October 3, every Sonnet reviewer was split 50/50 between Sonnet 5 and Sonnet 5.5. Sonnet 5.5 came out 62% cheaper per run for code quality, 58% for performance and 47% for security, with similar findings. All reviewers moved to 5.5 on October 5.

Medium effort has a price

Effort was tuned per reviewer, and this is the most useful part of the write-up. Full-tier jobs on medium effort finished 20% sooner than on high. But the team measured that performance and security reviewers lost real findings at medium effort: roughly 64% fewer important performance issues per review (one fewer every 24 reviews), and about a quarter fewer on security, the latter not statistically significant. The code quality reviewer runs at high effort, where it still finds about as many real problems as before. Testing security and performance at high effort is next on the list.

Measuring quality, not just spend

Cutting inference cost is easy if you are willing to ship a worse product. Cloudflare used two checks to make sure it wasn't.

The first is behavioral. The share of the code quality reviewer's serious findings that led the author to change code rose from 34% to 59%, while acted-upon findings per 1,000 reviews stayed flat (132 vs. 145, within the margin of error). Less noise, same signal.

The second is a blinded evaluation of 657 findings by three independent judges, who labeled each one (important, minor, duplicate, wrong, unverifiable) and rated its severity. Important findings per review went from 0.28 to 0.30, with overlapping intervals, so no significant change. Findings rated as more severe than they deserved fell from 0.46 to 0.14 per review: a 70% drop in severity inflation. Reliability improved too, with reviews ending without a verdict falling from 0.79% to 0.27%.

The author is candid about the limits: an author changing flagged lines shows they did something, not that the finding was right; each judged group holds only 35 to 66 findings; and the most recent window is only a day long. The takeaway is worth quoting in spirit: cheaper reviews didn't automatically mean worse quality, but they didn't automatically mean fine either.

What this means for AI teams

More teams are moving agents from demo to always-on: every commit, every ticket, every document. At that point inference cost becomes a budget line, and as Cloudflare's April-to-August doubling shows, it drifts fast. Here is how we would apply these lessons on a client engagement.

1. Instrument the cache first. The author's own advice is the right starting point: check whether the first request of each session actually reads from the cache. The API's usage metadata reports cache reads and writes. If hit rates are low while your prompts look “identical”, look for a date, a job ID or a file path leaking into the prefix.

2. Order prompts from most stable to most volatile. System instructions, tool definitions, shared context, and only then task-specific content. This is an architecture decision, not a tuning knob: your agent framework assembles the prompt, so it belongs in the framework evaluation.

3. Track cost per unit of work. The useful metric is not the monthly invoice but cost per review, per ticket or per document, broken down into output tokens, cache writes and cache reads. That breakdown is what let Cloudflare attribute every cent.

4. Treat model choice as an experiment. A 50/50 split on real traffic beats any generic benchmark. And effort should be set per task: a security reviewer does not behave like a style reviewer.

5. Kill calls that do nothing. Visible-but-forbidden tools, file-by-file reads, cancelled jobs that keep running, full re-reviews: these leaks stay invisible until you trace every call.

6. Pair every optimization with a quality check. A blinded evaluation of a few hundred outputs, imperfect as it is, protects you from savings that quietly degrade the service.

None of this needs a new tool. It needs LLM observability and discipline, which is exactly what most hastily shipped agents lack. Controlling LLM inference cost starts with measuring it.

TL;DR

  • Cloudflare cut its AI code reviewer's LLM inference cost by 68%, from $2.43 to $0.77 per review, and median time from 4m 9s to 1m 32s.
  • A badly structured prompt cache was the first leak: 14-26% first-request hits before, 91-99.5% after.
  • Code changes explain $0.65 of the savings; model and effort choices explain $1.06.
  • A Sonnet 5 vs. Sonnet 5.5 A/B test on production traffic drove the model decision.
  • A blinded review of 657 findings showed stable signal and 70% less severity inflation.

Industrialising AI agents? SeedVision offers 3-5 day AI audits and 15-30 day production rollouts. See the packages or book a 30-min call.

Cover photo: Photo by Paul Hanaoka on Unsplash.