2026-11-26 15:48 UTC

Cloudflare reports 68% lower AI code-review costs after caching and model/effort tuning

state: corroboratedheat: lowuncertainty: mediumrelevance: highinference-optimization cost-reduction production-serving token-optimization cloudflareRyan SkidmoreCloudflare

What is this?

Cloudflare engineer Ryan Skidmore reports that the company reduced its AI code reviewer’s average cost from $2.43 to $0.77 per review and median completion time from 4m 09s to 1m 32s. The changes combined prompt-cache reuse across repositories, fewer or parallelized model calls, removal of redundant work, and changes to model and effort settings. Cloudflare attributes about $0.65 of the $1.67 cost reduction to code changes and $1.06 to model and effort changes. This is a first-party account of one production system, not an independently verified benchmark.

Why it matters

A useful production case study in reducing agent costs without treating token price as the only lever: Cloudflare reports that cache reuse, fewer redundant calls, and model/effort tuning cut its AI code reviewer’s average cost by 68% and median latency by about 63%. The quality evidence is mixed by reviewer, underscoring that cheaper settings need workload-specific evaluation rather than assuming cost savings are free.

Current assessment

Cloudflare engineer Ryan Skidmore reports that its AI code reviewer’s average cost fell from about $2.43 to $0.77 per review and median latency from 4m 09s to 1m 32s. The reported changes include making shared prompt prefixes cacheable across repositories, reducing redundant calls and work, and changing models and effort settings. Cloudflare attributes $0.65 of the $1.67 reduction to code changes and $1.06 to model and effort changes; first-request cache hits reportedly rose from 14–26% to 91–99.5%. This is a detailed first-party operational case study, not an independently controlled benchmark, and Cloudflare notes that its before/after comparisons are not statistically sound. Quality results vary by reviewer and effort: some findings were preserved or improved, but medium-effort settings also missed real findings in code quality and performance review, while security results were inconclusive. It is evidence that cache design, call reduction, and workload-specific model/effort evaluation can materially lower agent costs, not that the same savings or quality tradeoff will generalize. No new independent confirmation or implementation evidence has appeared; engagement is low and past its peak.

Measured heat

now 0 pts/hpeak 0 pts/hcomments 0/hpeers p10momentum: steady2 platformsage 938h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

10-18 13:00⭐ origin echo-reconstructedCloudflare cut their inference bill by 68% by optimizing their AI code reviewer: sharing cached prefixes across repositories (40% of savings
Ryan Skidmore (Cloudflare) on blog (echo) · attributed from hn.story.50157504
—
10-19 20:16first on hacker news · published · +31.3hCutting our inference bill by 68% by being obsessive about optimization
wondersky
—
10-19 20:16amplified on hacker news 👑hn.story.50157504
wondersky
peak 2 · 0 comments · 69% of case engagement
10-23 07:03amplified on hacker newshn.story.50205383
ryanskidmore
peak 1 · 0 comments · 34% of case engagement
10-19 20:32our radar first saw it · +31.5hdiscovery anchor: hn.story.50157504—
pace: p23 vs 879 stories at the 720h mark (now 938h old) — ahead of adap-delegated-authority-protocol-draft (2.0x), behind agentprobe-failure-injection-agent-testing (0.7x)

Evidence (3) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnCutting our inference bill by 68% by being obsessive about optimization
Retrieved article excerpt

Open article · Retrieved 2026-10-19T20:47:58.234708+00:00

[Agents](https://blog.cloudflare.com/tag/agents/)[AI](https://blog.cloudflare.com/tag/ai/)[Durable Objects](https://blog.cloudflare.com/tag/durable-objects/)

October 19, 2026

# Cutting our inference bill by 68% by being obsessive about optimization

Ryan Skidmore

[Ryan Skidmore](https://blog.cloudflare.com/author/ryan-skidmore/)

15 minute read

COPY URL

When we previously [blogged about our AI code reviewer in April](https://blog.cloudflare.com/ai-code-review/), an average review cost a palatable $1.19. By the end of August, that figure had shot up to about $2.46. We hadn't made any significant architectural changes: the coordinator was still handing work to the same set of specialist reviewers, and the same risk tiers decided how intensive of a review we gave.

Around mid-September we tasked our agents with working out where those tokens were going and cutting them — aggressively. With code quality at high effort, the average review now costs just $0.77, down 68% from the $2.43 it averaged over our two most expensive weeks before we started. Our main goal was to cut costs, but as part of this work we also managed to optimize the reviewer, so that the median review now takes just 1m 32s instead of the 4m 09s it took before.

About 40% of the savings came from changes and optimizations to the reviewer's code, and the rest from experimenting with which models we use and how much effort they put in.

## How a review doubled in cost

The chart below shows the cost of an average review on each weekday since March. It holds the mix of review tiers fixed, so a day with more large reviews doesn't skew the data.

The cost per review steadily rose from $1.22 (March) → $1.44 (June) → $1.74 (July) and finally, to $2.32 (August). A small part of that is that more reviews landed in the most expensive tier (59% of reviews in March and then 65% in August). We believe there’s a simple answer for why: models are getting much better, and much more capable. Naturally, engineers are producing bigger, more complex changes which means more of them fall into our “full review” tier. We found that most of the cost increase actually came from model changes over those months, though.

At the start of August we moved every reviewer onto Anthropic models, which raised the cost per job from $1.38 to $2.03. We made this choice because we found that during our evals, Anthropic models performed better on this specific workload than other models.

Our internal [standards reviewer, Codex](https://blog.cloudflare.com/engineering-standards-enforcement), ended up on Claude Opus 4.7 due to a mix of performance and reliability. That took it from about $0.25 per review to $0.88 in August, which made it more expensive than the coordinator agent itself.

The cache hit rate also increased, going from 85.7% in April to 97% by September, while the number of tokens per review more than tripled, from 0.91 million to 2.99 million. A high hit rate on three times as many tokens still costs a lot more, even with the low cache read cost.

## What else has changed since our last post?

One of the biggest changes is that the reviewer now runs on [OpenCode](https://opencode.ai/) v2, which is a [ground-up rewrite](https://anoma.ly/notes/opencode-2-0/) from v1. Before switching all reviews over from v1 to v2, we ran every review in every canary repo on both v1 and v2 in a comparative shadow mode. The two agreed on the approval decision in 98% of the merge requests we tested, so we moved everyone over in one go in early October and removed the v1 code. Comparing two days with the same models, full-tier reviews on v2 finish about 13% faster. We’re also currently experimenting with other ways to run our internal AI reviewer, including solely on Durable Objects using [pi-durable](https://earendil.com/posts/pi-durable/). We’re hopefully going to have more on this coming soon, so keep an eye out!

## So, where were the tokens going?

Right before we started focusing on cost optimization, our AI review spend was split by: output tokens making up about 23%,  cache writes cost 43%, and cache reads cost 34%. This means that  most of the money was going on context the model had already seen or was about to see again.

That makes complete sense when you look into a single session. The code quality reviewer made 16.6 large language model (LLM) calls per review on average and over those calls it wrote 72k tokens to the cache and read back 1.08m, because each call sends the whole conversation as context. A session's cost grows with both the number of calls and the size of the context, and over the last few months we had slowly increased both.

It’s worth taking a few minutes to read about how [Anthropic's prompt cache](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching) works. It works by caching parts of the prompt that have already been computed by the large language model (LLM). These are known as prefixes, because they only work on the messages at the start of the conversation, not mid way through or the end. This means that a future request can reuse an earlier prefix, up to the part of the conversation that changes from what’s been cached. In our case, the harness tools, system prompt and messages at the start of our AI reviewer sessions rarely change, so they’re a great candidate for prefix caching. A prefix is only stored where a cache breakpoint ends it. Writing to the cache costs 1.25 times the normal input price and reading costs 0.1 times, and an entry expires after five minutes unless something reads it.

That means we had two things to work on: make the first request of each session read from the cache instead of writing to it, and make each session use fewer calls.

## Sharing a cached prefix between every repository

Beginning September 14, the reviewer recorded the token usage of each reviewer's first LLM call, plus a hash of the first system block exactly as it was sent to the provider.

The data showed that the first request of a session found a cached prefix only 14% to 26% of the time. Every session starts with the same tool definitions and the same agent prompt, between 11k and 21k tokens that are identical in every repository we review, so almost all of them should have been cache hits.

The problem ended up being in how OpenCode v1 constructed the system prompt: It built one block containing our 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 shared part was never stored on its own, so a review in one repository could never reuse what a reviewer ran in another repository had written.

On September 16, we added a marker to the end of every agent prompt and a plugin hook that split the block in two at that marker. The first half now ended on bytes that every job shares, and got its own breakpoint. To keep it that way we had to remove anything repository-specific from in front of it, so the list of available skills is disabled and tool descriptions can't change between jobs.

Chart showing the share of reviewers' first requests that read from the cache rising from 14–26% to 91–99.5% after September 16.

The same day we also moved our internal standards (Codex) reviewer's reference index (a table of internal standards, a skill file and a list of reference files) into its prompt. Until then every session had spent its first three turns reading those files with tool calls. Its LLM calls per run decreased from 15.9 to 9.6, and its cost per run dropped from $1.12 to $0.72.

Together these took the cost per review from $2.47 down to $2.02, and the drop was noticeable as soon as we kicked off the release.

## Fewer calls, fewer dollars

The next set of changes went out on September 21 and 23. None of them were particularly impressive by themselves, but together they took about $0.20 off every review.

|  |  |  |
| --- | --- | --- |
| Change | What was happening | Effect of change |
| Removing tools that reviewers couldn't use | Sub-reviewers could see the tool that posts the final review comment. In 57% to 76% of sessions they tried to call it, were rejected by a check on the server, and spent another call recovering. | One wasted call gone, and about 2.9k fewer tokens of tool definitions in every sub-reviewer request |
| Reading files in parallel | In 64% of the code quality reviewer's turns, the model made exactly one tool call, usually to read a single file. | Reviewers read the shared context and all of their patches in their first response, up to 150 KB |
| Skipping reviewers on re-reviews | About two-thirds of our jobs are a second or later review of the same merge request, and often three of the reviewers have nothing new to look at. | On full-tier re-reviews, AGENTS.md reviews are skipped 56% of the time, performance reviews skipped 23% and documentation reviews skipped 13%. |
| Stopping after the review is posted | OpenCode passed the result back to the model for one more turn, which read the entire conversation again to write a summary nobody saw. | About $0.07 saved per job |
| Treating a slow reviewer differently from a broken provider | A reviewer that hit its time limit was treated like a provider failure and started again with the same time limit. | Together with longer time limits and lower effort, security reviewer timeouts went from 1.8% of runs to almost none |
| Canceling canceled jobs | GitLab's Kubernetes executor doesn't send a signal to a job's script when the job is cancelled. In a sample of 446 cancelled jobs, 358 kept running until the review was finished. | Jobs check their own status every 15 seconds and stop if cancelled |

The most involved change was sharing one prefix between three reviewers. The code quality, security, and performance reviewers now send identical first requests with the same tools, a shared rules file, then the merge request with every patch included. Each reviewer's own instructions follow after that, and we make sure that one of them writes the cache and the other two read from it.

Diagram showing three sub-reviewers sharing one cached first request: the first writes it and the other two read it, so only each reviewer's own instructions differ. The tools and shared rules at the start are shared across every repository.

A cache entry can't be read until the response that wrote it has started streaming, and the three reviewers start at the same time. So the second and third wait for the first one's response to begin, for up to 20 seconds, before sending their own first request. It slows them down slightly and saves about nine cents per reviewer.

## Changing models and effort

The next chart shows the same line from the start of September, with each change marked.

Chart showing cost per review falling in steps from about $2.40 to $0.75, each step matching a specific change.

When we split the period at every release and every configuration change, the code changes turn out to be the smaller part of the saving.

Chart splitting the drop from $2.44 to $0.77 by change. The shared cached prefix was the biggest single saving, but model and effort changes together saved more than code changes.

Code changes account for $0.65 of the $1.67, and model and effort changes for $1.06. Each step compares the weekday hours before a change with the hours after it, so this isn't a statistically sound controlled experiment.

The coordinator had been running three model and effort combinations since August. On the same model, full-tier jobs on medium effort finished 20% sooner, so we dropped the other two. In a later randomized split, Opus 5.5 at medium showed no measurable change in review outcomes or critical findings compared with Opus 5, so we switched. Opus 5.5 at high effort cost more than Opus 5.5 at medium while not producing a meaningful increase in findings.

Opus 5.5 is cheaper per token than Opus 5, but price is only responsible for about $0.20 of the dr
wondersky20
🟧 echo.blog ⭐Cloudflare cut their inference bill by 68% by optimizing their AI code reviewer: sharing cached prefixes across repositories (40% of savingsRyan Skidmore (Cloudflare)——
🟧 hnCutting our inference bill by 68% by being obsessive about optimizationryanskidmore10

Interpretation history

Decision trace