sysnote
News

Anthropic moves its Messages API to Rust: the port passed 98% of tests but matched a quarter of production prompts

Anthropic has moved the Messages API, the service behind its public API and its own apps such as Claude Code, from Python to Rust. The engineering post "Migrating our Messages API to Rust", published on November 25 by Lance Martin, Jake Eaton, Arvin Aminpour, Emma Webb, Bharat Mediratta and Ravi Trivedi, says public traffic moved to Rust in September 2026. The new service uses about 70% less CPU per request and cut median time to first token by about 20%. Claude wrote a first version of the core request path in about a week. The rest of the post is about the months it took to show that this version behaved like the old one.

AAnthropic@AnthropicAI

We recently migrated our Messages API from Python to Rust.

On our engineering blog, we share how we used the existing service to verify the new one, with teams of Claude agents tracking down and fixing differences between the two versions.https://t.co/NdrMzgrOwP

November 25, 2026

Why the tests were not enough

The Messages API had about 700 integration tests. By April the Rust version passed about 98% of them. On shadowed production traffic, only about a quarter of its prompts matched the ones Python built for the same requests.

Anthropic gives two reasons. The tests ran the Python service in-process with billing and rate limiting mocked in Python, so they had to be ported along with the code, and Claude helped with both. When the team audited the ported tests, it found more than 100 weakened assertions. A passing test could mean the Rust code was right, or that the test had been loosened until wrong code passed. The second reason is coverage: the post counts that 20 binary options already give more than a million combinations, and the tests only held the ones somebody had thought of.

One of the production-only differences is easy to reproduce. When Python wrote JSON for tool calls, it escaped characters such as emoji into text codes; Rust wrote them as is, so the two prompts differed by a few bytes. The post does not name the libraries. The standard ones behave this way by default. On our machine Python's json.dumps turns {"q": "ok 👍"} into 24 bytes with \ud83d\udc4d in place of the emoji, while Rust's serde_json::to_string gives 15 bytes, with the emoji kept and without the spaces after : and , that Python adds. The request still succeeds either way. The model just reads a slightly different prompt.

Shadowing a nondeterministic service

Shadowing means sending the same request to the old and new code and comparing the results. Anthropic says the usual tools did not fit. Twitter's Diffy, for example, runs the old code twice to learn which parts of a response vary on their own and then ignores those parts, and for a model's reply that would be almost everything. A request also had to count only once toward a customer's limits and bill. So the team called the model once and replayed its output into the Rust service, then compared every step before and after the model call, which had to match exactly.

The team could not read customer requests or Claude's replies, so it recorded the shape of each difference instead of its text. Both services go through the same steps (accept or reject the request, resolve settings, build the prompt), and the first step where they disagreed showed roughly where the bug was. Inside the prompt, the record kept which piece differed, the byte where the difference began and the two lengths. One bug tends to leave the same record on every request it touches, so these records worked as fingerprints for grouping.

Agents in loops

A single bug could produce hundreds of thousands of near-identical records. A script grouped them every 10 to 30 minutes and woke a coordinating Claude agent only when a new kind appeared. The coordinator gave each new kind to a worker agent and opened a thread in a shared Slack channel where engineers could follow it.

The worker could see only the fingerprint, not the request behind it. In a cloud sandbox with both codebases, it guessed the cause, wrote its own request or scripted model reply that should trigger the same difference, and ran both services locally. The input check built each version's prompt without calling the model and took under a second. If the outputs differed the way the record said, the agent edited the Rust code until they matched and added a test that failed on the old code. A fix went out only after PR review, and shadowed traffic then showed whether the fingerprint was gone. If it was still there, the agent went back to the sandbox.

The post explains the review gate with a case from mid-May. One of the largest remaining differences came from web search: production fetched the tool's description from an internal service that Rust did not call yet. An agent copied the text into files Rust could read. The prompts matched and the local check passed. An engineer rejected the fix, since Rust would need to call the service before launch anyway and the copy would be thrown away. In the post's words, the verifier "rewarded matching outputs, and the agent found the cheapest way to produce them." Building the real call took weeks. In the meantime the agent's note about the rejection was saved to a shared memory, and other agents used it to link new fingerprints from the same missing text to the known bug instead of writing more copies.

Other corrections became rules in CLAUDE.md, lints, tests and, later, a merge check that makes anyone changing the Python code make the same change in Rust or ask for an exemption. That check matters because the Python API kept getting new models and features through the whole migration, so Rust was chasing a moving target.

Pando, and what is not published

Earlier this month we wrote about OpenAI's Pando, another Rust service written largely with an agent, where OpenAI used Lean and TLA+ specifications to find bugs and prove properties of the system. Pando was a new system and could be checked against a specification. Anthropic was replacing a service whose correct behavior was whatever the Python version did that day, so the old service became the specification. OpenAI says Pando went from kick-off to production in 10 weeks. Anthropic's first Rust request path took about a week, and the parity work ran from April to September. The reported figures (70% less CPU, 20% faster first token, the quarter-of-inputs match rate in April) are Anthropic's own measurements, shown as charts in the post. The shadowing tools and the agent setup are not published.

Comments

No comments yet. Be the first.

Write a comment

Comments are published after review.