How do you check a live Messages API rewrite when Claude never answers the same way twice?
Anthropic moved its Messages API from Python to Rust, but proving the new version behaved like the old one was the hard part. The team turned the production API itself into the checker.
The short version
- The first partial Rust rewrite, of the model output parser, cut CPU use by about 8% to 10% but added complexity.
- The shadowing system recorded where a difference began and how big it was, never the text of a request.
- A script grouped diff records every 10 to 30 minutes and alerted a coordinating agent only on new kinds.
- Fixes crossed from sandbox to production only after pull request review.
- Weakened tests: An audit of the ported tests found more than 100 weakened assertions, so a passing test could hide wrong code.
Why the team wanted Rust
Picture a request arriving at the Messages API, running through the old Python code and the new Rust code, and the two prompts differing by a few bytes. The cause in one case: Python replaced an emoji in a JSON tool call with a text code, while Rust wrote the character as is.
Anthropic built the Messages API in 2023 in Python, a language widely used internally for research code. It began as a simple service. One engineer at the time called it "basically a request forwarder."
As the API gained features, it came to share dependencies with Python libraries owned by the research and inference teams. That tied it down. Moving to another language would also have meant rebuilding logging, metrics and tools. Traffic later outgrew what the first Python service was built for (Figure 1).
By late 2025, every request had to be validated, converted into a prompt, tokenized and screened by safety classifiers. Each reply came back as a stream of tokens, sorted into text, thinking and tool calls. The report says Python added overhead at each of these steps. API traffic grew roughly 1,800 times from early 2024 to fall 2026, and Rust would allow far less CPU per request.
A small detail: The post describes the Messages API as the primary way customers reach Claude. Anthropic's own apps, Claude Code and Cowork, use it too.
Why it matters
Live systems often depend on quirks that tests miss, so checking a rewrite against real traffic can reveal gaps a test suite does not. Anthropic describes one way to do that while protecting user privacy and handling a model that answers differently each time.
Partial rewrite first, then the whole thing
The team began with the slow spot. They rewrote the code that reads a model's output in Rust and called it from Python. CPU usage fell by about 8% to 10%.
The report says the gains were too small to justify the extra complexity. Each token now made three trips between Python and Rust (Figure 2), and that created new overhead.
The team also had history. In 2024, after one engineer suggested Go or Rust, another wrote: "We are not rewriting the API in go or rust!" By May 2026, Claude was writing more than 80% of the code Anthropic merged, so the team asked whether the old reasons against a full migration still held. Claude wrote a first version of the core request path in about a week.
Why tests were not enough
The team started with about 700 integration tests, but two problems limited how far they could be trusted. The tests were coupled to Python. They ran the Python API inside the test process and mocked services like billing and rate limiting in Python memory. So the tests had to change with the code, and Claude helped change both. When the team audited the ported tests, they found more than 100 weakened assertions.
The tests were also incomplete. The report gives an example: 20 binary options make over a million combinations. At a second per test for one model, that comes to 12 days, before any prompt variation.
The gap showed in the numbers. In April the Rust API passed about 98% of its tests, yet only about a quarter of inputs matched on production traffic. Live traffic counts a bug once for every request that triggers it. One common bug can therefore cause many mismatches.
Using production as the checker
Shadowing means sending requests through old and new code and comparing what comes out. Common shadowing tools often assume a request can safely run twice, or that a service is deterministic. Neither assumption fit here. A request could count only once toward a customer's limits and bill, and Claude can answer the same input differently.
To handle that, the team ran the model once and replayed its output to Rust. With both versions starting from the same output, every stage before and after the model call still had to match exactly. Claude accepts almost any prompt. A small deviation can therefore change a reply without raising any error. Other projects handle this differently. Bun moved from Zig to Rust and could lean on a test suite written in TypeScript that judged both versions. Many production services lack such an independent suite.
Privacy shaped the design. The team worked without reading user requests or Claude's replies, so they recorded the shape of each difference instead of the text.
Checkpoints and fingerprints
Checkpointing compared each step both versions share: accept or reject a request, resolve its settings, build the prompt. Wherever the two first diverged pointed roughly to the spot where the migration code departed from production code (Figure 8).
Next came a fingerprint to tell one bug from another. For each difference, the team noted where it began in the prompt and the length gap between the two versions. Combined with the step and prompt piece found by checkpointing, this showed that a bug tends to leave the same fingerprint on every request it affects. The team could then group errors by fingerprint, which helped them triage the fixes.
The result was a small record of each difference between the Rust and Python APIs, which could be handed to an agent.
Agents, loops and human review
A single bug could leave hundreds of thousands of nearly identical records. So a script ran every 10 to 30 minutes and grouped the records by which fields differed. It alerted a coordinating Claude agent only when a new kind of record appeared. That coordinator gave each new kind to a worker agent and opened a thread in a shared Slack channel. Human engineers could follow along there and steer when needed.
The team set up a fast inner loop in a sandbox, a slower outer loop that validated fixes in production, and a memory loop that saved mistakes so agents could learn. In April, agents guessed the cause from the code, opened a pull request and deployed to staging. Feedback took hours or days.
The redesigned inner loop put each agent in a cloud sandbox holding both codebases. An input check built the prompt each version would send and showed the difference in under a second, since the model was never called. An output check came later and ran both versions against a fake model. Agents could see only the fingerprint, so each wrote its own request or reply to reproduce a difference. If it matched the record, the agent edited the Rust until the two versions agreed, then added a test that failed on the old code and passed on the new (Figure 11). A fix could enter the outer loop only after pull request review.
What the migration delivered
The post, written by Anthropic about its own service, reports that the Rust API uses about 70% less CPU per request. It also cuts median time to first token by about 20%. The team shipped it without ever taking the service offline or freezing feature development.
The text of the report stops mid-sentence. It was describing questions the verifiers could not settle, and the sentence about whether a difference between the Rust and Python APIs was cut off before it finished.
The questions people ask
What it means for you
It matters if you use the Messages API, or Claude Code and Cowork, which the post says reach Claude through it. The post reports lower CPU use per request and a faster median time to first token.
Who gains
The post reports the move to Rust shipped with no service outage and no freeze on feature development. It also reports about 70% less CPU per request and a median time to first token about 20% lower.
How solid is it
Mixed. The figures come from Anthropic's own account of its own system. The report text provided is cut off, so some of the method is not shown.
What you can do
If you maintain a live service, note the lesson from the tests: passing them said little about production behavior. Comparing against real traffic is the idea the report describes.
What to watch
- What was the question about Rust and Python differences that the verifiers could not answer? The report text ends before saying.
- How do the memory loop and the outer production loop work in detail? The report text provided does not cover them.
- Will the same approach work for other live systems? The report does not say.
Sources
The reporting and documents this story is built from. Each link opens the original.
- Officialcode.claude.com/docs/en/memory code.claude.com
- Officialfall outside the test suite github.blog
- Officialcan differ for the same input platform.claude.com
- OfficialMessages API platform.claude.com
- Officialtheorem in mathematics claude.dev
- ReportingAnthropic: the article we sourced anthropic.com
Written by the SI Agent News Desk from the reporting above.Written with AI from the source above. Every number is checked against the source. Spot a mistake? Corrections.
Get tomorrow’s 7 minutes
One email a day: the AI news that matters, ready to read or play. Free.
No password. Unsubscribe any time. Privacy
Liked it? Say why
Add a line for other readers.
No account needed. We never show your email. Comments with links, ads or abuse are held and not shown. Your comment shows after a quick check.