Anthropic has finished its Messages API Rust migration, moving the service that handles Claude requests from Python to Rust. The new version uses about 70% less CPU per request and cuts median time to first token by roughly 20%. The service never went offline, and feature work kept going the whole time.
The harder story is how the team trusted the result. Claude wrote a first version of the core request path in about a week. Proving it behaved like the live system took months.
Why Python stopped being enough
The Messages API launched in 2023 as a thin layer. One engineer called it “basically a request forwarder.” It was written in Python because much of the company’s research code was too.
That changed as traffic grew roughly 1,800 times between early 2024 and fall 2026. By late 2025 every request had to be validated, converted into a prompt, tokenized and screened by safety classifiers. Replies came back as a stream of tokens that had to be sorted into text, thinking and tool calls. Python added overhead each time it created an object, freed memory or passed work along.
The API also shared dependencies with Python libraries owned by the research and inference teams. Leaving Python would have meant rebuilding logging, metrics and tooling from scratch.

A partial rewrite that didn’t pay off
The team first followed the usual advice and rewrote only the slow part. They moved the code that parses model output into Rust and called it from Python. CPU use dropped by about 8% to 10%.
It wasn’t enough. Each token now crossed between Python and Rust three times, which created new overhead and more complexity than the gain justified.
What changed the calculation was Claude itself. By May 2026, Claude was writing more than 80% of the code Anthropic merged. Writing a full rewrite was no longer the obstacle. Checking it was.

Why the tests weren’t trustworthy
The team had about 700 integration tests, and they had two problems. They were tied to the Python implementation, running the API inside the test process with services such as billing and rate limiting mocked in memory. When tests had to change alongside the code, a pass could mean the code was right or that the test had been loosened. An audit of the ported tests found more than 100 weakened assertions.
They were also incomplete. Twenty binary options alone produce over a million combinations, which would take about 12 days to run at one second each, for a single model.
The Rust API passed about 98% of its tests in April. Only about a quarter of production inputs matched the Python output. One example: Python escapes certain characters in JSON tool calls, such as emoji, while Rust wrote them as is, so prompts differed by a few bytes.

Using production as the verifier
So the team ran the Rust API against live traffic in a shadow setup. Two constraints shaped it. A request could count only once toward a customer’s limits and bill, and Claude can reply differently to the same input. The fix was to run the model once and replay its output to the Rust path.
Engineers also couldn’t read customer requests. Instead the system recorded the shape of each difference:
- Checkpointing compared every step before and after the model call, so the first mismatch showed roughly where the code diverged.
- Fingerprinting recorded where a difference began in the prompt and how much longer or shorter it was, so one bug left the same fingerprint on every request it touched.
A single bug could produce hundreds of thousands of near-identical records. A script ran every 10 to 30 minutes, grouped records by differing fields and alerted a coordinating Claude agent only for new kinds. That agent assigned a worker agent to each one and opened a Slack thread where engineers could follow along.
Three loops, and a human gate
Early on, agents guessed at causes, opened pull requests and waited hours or days for feedback. The team moved them into cloud sandboxes holding both codebases. A local input check built the prompt each version would send and showed the difference in under a second, without calling the model. An output check later fed a scripted reply, such as a tool call, through both versions.
Fixes then went through pull request review before reaching production, where an outer loop compared builds with and without each fix. A third loop saved lessons from reviews as memory for later agents.
The review step mattered. In mid-May, an agent found that web search tool descriptions were missing from Rust prompts because Rust didn’t yet call the internal service that supplies them. It copied the text into files Rust could read, and the prompts matched. An engineer rejected the shortcut, since Rust would have to call the service before launch anyway. The agent saved a note explaining why, and later agents linked related records to the known bug instead of writing new workarounds. Building the real call took weeks.
Other lessons became permanent checks: tests that fail when Rust drifts from Python, lints for patterns reviewers kept flagging, and a merge check requiring any Python change to come with a matching Rust change or an exemption.
What this means for other migrations
Anthropic’s takeaway is that verification, not code generation, is now the bottleneck for large rewrites. Where a proof assistant or test suite can’t define “correct,” a live system can serve as the checker, provided it produces a signal an agent can act on.
The engineers’ role moved outward over the project. They started by chasing differences themselves, then reviewed fixes in Slack, and finally wrote the rules and checks the agents worked within. The Messages API Rust migration shows a rewrite of a live, fast-changing service can be done without a freeze, as long as the team invests in the verification first.
Source: anthropic.com