Anthropic's Messages API on Rust: -70% CPU per Request

– views

Source: Anthropic — Migrating our Messages API to Rust

  • Anthropic
  • Claude
  • Rust
  • API infrastructure
  • LLM inference
  • performance

On 25 November 2026 (16:26 UTC), Anthropic’s official account @AnthropicAI announced that the company had moved its Messages API from Python to Rust, linking to an engineering blog (published 24 November) on how: Claude wrote the first version of the new request path in about a week, and teams of Claude agents chased the differences between the two versions — but proving the new API matched the old one took months.

The Messages API is the primary route customers — and Anthropic’s own apps such as Claude Code and Cowork — use to reach Claude. It was built in 2023 in Python. The blog states that traffic grew roughly 1,800× from early 2024 to autumn 2026, and that public traffic moved to Rust in September 2026 — with the service never taken offline and feature development never frozen.

Why migrate

By late 2025 a Messages API request was no longer a forwarder. As the blog describes it, every request had to be validated, converted into the model’s prompt, tokenized, and screened by safety classifiers; as the answer streamed back, the token stream had to be split into text, thinking and tool calls. Python carried overhead at each of those steps, and the traffic curve made efficiency urgent.

A partial rewrite was tried first: in March 2026 the team rewrote the code that parses model output in Rust and called it from Python. The blog says that gained only 8–10% in CPU, because each token now crossed the Python↔Rust boundary three times. They went all-in instead. The 2024 conversation about migrating the API to Go or Rust had been closed by one engineer’s ruling — “We are not rewriting the API in go or rust!” — which the post now records as settled.

Measured results

From the blog’s charts (seven-day averages; “100” ≈ the level just before the switch):

MetricChangeWindow
CPU per requestabout 70% lowerone region, Aug→Oct 2026
Memory per requestmore than 80% lowerall of production, Aug→Oct 2026
Median time to first tokenabout 20% lowercustomers’ Claude Code requests, roughly 7–21 Sept 2026

The caveats are in the figure captions: the CPU number is one region, the memory number is all of production, and the latency number comes from a shorter window of customer Claude Code traffic.

Why the tests could not carry the proof

The team started from an existing suite of roughly 700 tests. The blog gives two reasons it was not enough. First, the tests were coupled to the old implementation: the ported tests had been written with Claude’s help, and auditing them found more than 100 weakened assertions. Second, they were incomplete: just 20 binary feature options produce over a million combinations, and at one second per test that is 12 days of running for a single model.

Two more properties of the system made static testing structurally insufficient. The Python API kept changing while the migration ran, so parity was a moving target. Claude itself is non-deterministic, so two correct implementations produce different outputs. And the team could not read customer requests, so they could not directly see where the two versions diverged.

The numbers show why: in April the Rust build passed about 98% of tests while only about a quarter of compared production inputs matched the Python output. By the end of the migration that figure was 99.6%.

Production traffic as the verifier

The core move: run both implementations on the same live traffic and compare — under one constraint that ordinary diffing tools cannot assume. Each request counts once against the customer’s quotas and billing, so the model ran once and its output was replayed into the Rust side instead of being generated twice.

Every request that differed left a small record in the logs — which step, which field, the first byte that differed, and the two lengths. A single bug could leave hundreds of thousands of nearly identical records, so a script grouped them by differing fields every 10–30 minutes and alerted a coordinator agent only when a new kind of record appeared. The coordinator assigned a worker agent to own each new kind of record, and opened a shared Slack thread where human engineers could follow and steer.

The blog then describes three verification loops. The fast inner loop gave agents a sandbox to test ideas and propose fixes, with sub-second local checks. The slower outer loop validated fixes on shadowed production traffic. A memory loop recorded mistakes along the way so the same class of error was not repeated. Human review sat at the seam between them, at PR review time: in one case an agent proposed hard-coding the web-search tool descriptions into files as a shortcut, and an engineer rejected it as throwaway code. The verifier answers whether outputs match; it does not answer whether a fix is shippable.

What it means

The post frames the migration as invisible to customers: same Messages API, no downtime, features kept shipping, with the gains on the serving side — less CPU and memory per request, and a lower median time to first token.

The interesting claim is structural. Anthropic’s framing is the generator–verifier gap: it is easy to check a solution and hard to produce one, so as long as there is a reliable way to verify, ambitious work can be delegated — and verification, not generation, was the bottleneck here. The blog’s merge chart shows the pace that unlocks: from a modest trickle of changes in early April to more than 3,000 merged changes in the two-week period starting 10 August 2026.

One context point outside the blog: Dataconomy reports, citing a 27 October 2026 podcast discussion between Katelyn Lesse and Angela Jiang, that the team started the project without prior Rust experience — Claude generated most of the code, and the engineers’ job was to build the verifier.

More coverage