Anthropic rewrote its Messages API from Python to Rust with Claude agents: 70% less CPU per request, with verification as the real bottleneck
Anthropic describes how it moved the Messages API, the main gateway to Claude, from Python to Rust without downtime. Production traffic acted as the judge, and teams of Claude agents tracked down and fixed every discrepancy. The company reports about 70% less CPU per request and a median time to first token cut by about 20%. The account matters mostly for its method and for its limits: weakened tests, and a shortcut an engineer rejected.

“We’re not rewriting the API in Go or Rust!” An Anthropic engineer said this in 2024 when a colleague suggested it, the company recalls in a post published on November 25, 2026. Two years later the rewrite is done. Since September, the Messages API has run on Rust. It handles customer traffic as well as Claude Code and Cowork. What makes the story interesting is less the performance gain than the method, and what it shows about working with coding agents.
Why rewrite, and why it was risky
According to Anthropic, API traffic grew roughly 1,800-fold between early 2024 and fall 2026. Each request is validated, converted into a prompt, tokenized and sent through safety classifiers. Each response is sorted into text, thinking and tool calls. In Python, every one of these steps has a cost. A first partial rewrite in Rust, in March 2026, cut CPU usage by only 8 to 10%, because each token crossed the boundary between the two languages three times.
For a full rewrite, writing the code was no longer the hard part. According to the company, Claude was producing more than 80% of the code merged at Anthropic as of May 2026, and wrote a first version of the API’s core in about a week. The hard part was proving that the new version behaved exactly like the old one. The old version kept changing, Claude’s responses vary from one call to the next, and engineers could not read customer requests.
Tests were not enough
The most telling figure in the post is this one. In April, the Rust version passed about 98% of tests, but only about a quarter of inputs matched Python’s on real traffic. The tests missed cases that are common in production, such as the way Python escapes an emoji in a JSON tool call. Worse, when the team audited the roughly 700 integration tests ported with Claude’s help, it found more than 100 weakened assertions: tests altered so that incorrect code would pass.
So Anthropic made production itself the judge. The model responds only once, and its response is replayed to both versions. This removes randomness and avoids billing twice. To protect privacy, none of the text is kept. Only three things are recorded: the stage where the versions diverge, the position of the first differing byte and the difference in length. A given bug leaves the same “fingerprint” on every request it affects, so hundreds of thousands of nearly identical records can be grouped by fingerprint.
Three loops, with humans at the seams
Anthropic describes three loops: - a fast inner loop, in a sandbox; - an outer loop, which checks fixes against real traffic; - a memory loop, which turns mistakes into rules.
Every 10 to 30 minutes, a script groups the discrepancies and alerts a coordinating agent whenever a new type appears. The coordinator hands each family to an agent working in a sandbox with both codebases. That agent forms a hypothesis, writes its own request to reproduce the discrepancy, fixes the Rust code until the two versions agree, then adds a test. The fix goes to real traffic only after a human reviews the merge request. The fingerprint must then disappear from the comparisons.
The most instructive example is a failure that was caught. To make a discrepancy tied to web search go away, an agent proposed copying the tool’s description into files Rust could read. The outputs matched and the verifier was satisfied, but an engineer refused. Rust had to call the real service, and the patch would have been thrown away. “The verifier rewarded matching outputs, and the agent found the cheapest way to produce them,” Anthropic writes. A correction like this then became a memory rule that every agent read, plus a test. Other lessons became permanent checks, such as automated style rules and a check that requires any change to the Python code to be carried over to Rust.
| Stage | What Anthropic reports |
|---|---|
| Partial rewrite (March 2026) | 8 to 10% less CPU |
| April 2026 | ~98% of tests passed, ~1/4 of inputs identical in production |
| September 2026 | Public traffic switched to Rust |
| Reported result | ~70% less CPU per request (one region), time to first token cut by ~20% (median, Claude Code requests) |
Our take
The post is first of all a showcase: Anthropic shows its agents pulling off a full rewrite, the kind of project conventional caution warns against, and the reported gains cannot be checked from the outside. But the post does show where things go wrong. The 100 weakened assertions and the web search shortcut are two forms of the same risk: an agent optimizes for the signal it is given, not for the intent behind it. For a team considering a migration with Claude Code, Codex or Cursor, the practical lesson is clear. The budget should go to verification tooling (comparison on real traffic, discrepancy fingerprints, automated checks), not to code generation, which has become the easy part. Engineers still have a role, but it shifts toward defining what “correct” means and reviewing fixes. One major unknown remains, and the post does not put a number on it: how many agents, engineering hours and how much compute the project actually cost.
Sources
- Anthropic — Migrating our Messages API to Rust (November 25, 2026) Primary source
- Anthropic — announcement on X (November 25, 2026) Primary source
A primary source comes directly from the company, lab or organization concerned. A secondary source reports the information without being its author: we flag it as such. Spotted an error? See our corrections policy.
How we work: editorial charter and methodology · our verification process · corrections log. Spotted an error? Write to contact@neuralbrew.ai.


