Subscribe
Anthropic
3 min read

Anthropic rewrote the Messages API in Rust and says it uses 70% less CPU

Anthropic's engineering post details the Python-to-Rust migration of the Claude Messages API, and the real story is how production traffic itself was turned into the verifier.

Anthropic rewrote the Messages API in Rust and says it uses 70% less CPU

Anthropic published an engineering post on November 25 detailing how it migrated the Messages API from Python to Rust. The reported result: roughly 70% less CPU per request, more than 80% less memory per request, and a median time-to-first-token about 20% lower, delivered without taking the service offline or freezing feature development on the old stack.

The Messages API is the front door to Claude. Customers, and Anthropic's own products like Claude Code and Cowork, reach models through it. Traffic grew about 1,800 times between early 2024 and fall 2026, according to the post. By late 2025 every request was validated, converted into a prompt, tokenized and screened by safety classifiers, and every streamed reply had to be sorted into text, thinking and tool-call blocks. Python's per-object overhead compounded at each of those steps as volume scaled.

The first attempt was incremental. A partial Rust rewrite of the output-parsing code cut CPU usage by 8% to 10%, but it also made every token cross the Python/Rust boundary three times. The team judged the gain too small to justify the added complexity.

Two machines feeding a comparison funnel, with rejected sheets repaired by robots

So it rewrote the whole request path. Claude wrote a first version of it in about a week. That, per the post, was the easy part. Verification was the bottleneck, and three constraints made it hard: the Python service kept shipping new features, so "parity" was a moving target; Claude replies are nondeterministic, so two different outputs are not proof of a bug; and Anthropic cannot read customer requests, so the team could not simply inspect where the two implementations diverged.

The existing test suite could not serve as the oracle. It held about 700 integration tests that were coupled to the Python implementation, and Claude had written both the port and the ported tests. An audit of those ported tests found more than 100 weakened assertions, cases where a pass could mean wrong code slipped through. Coverage was thin by construction: the post notes that 20 binary feature options produce over a million combinations, which at one second per test is 12 days of testing for a single model.

Instead the team made production itself the verifier. Live traffic was shadowed through both implementations, but the model was run only once and its output replayed into the Rust service, so any difference came from the API layer rather than from sampling. Checkpoints located each difference in the code, and response fingerprints distinguished one bug from another. Teams of Claude agents were dispatched to reproduce and fix mismatches.

The numbers from that process are the interesting part. In April the Rust API was passing about 98% of its tests while matching only about a quarter of production inputs. Match rate briefly dropped to 6.5% in early May as fixes exposed more divergences, then climbed to 99.6% by August, according to the post's chart. Merged changes on the project went from under 100 per two-week period in April to more than 3,000 after August 10.

Some of the divergences were mundane and instructive. Rust did not escape emoji in JSON tool calls the way Python's serializer did, so prompts differed by a few bytes. One config read a 1M token limit as 200K. Others were worse: missing usage fields would have broken billing and rate limits, and the design had to guarantee each shadowed request counted exactly once against a customer's limits and bill.

The post reads partly as an argument about where engineering effort goes now that code generation is cheap. Its stated lessons: verification is the new bottleneck; confidence is earned by building the verification signal, not the code; and loops should be kept simple so they scale with model capability. The team says it put human judgment only into what counted as correct and left agents to choose hypotheses, reproductions and fixes.

It also updates a claim that has been circulating since October, when platform engineering head Katelyn Lesse said on the Latent Space podcast that the Rust rollout had cut CPU roughly 40% to 50%. The official blog figure is larger: about 70% less CPU per request on the migrated service.

The project began, per the post's origin anecdote, with a colleague shutting down the idea in 2024: "We are not rewriting the API in go or rust!"

Sources:

AnthropicInfrastructure