Anthropic migrates Messages API from Python to Rust with agents and cuts CPU by 70%

Anthropic described, in an engineering post published on Wednesday (November 25), how it used Claude agents to migrate its Messages API — the main path through which customers and the company's own apps, such as Claude Code and Cowork, reach its models — from Python to Rust. The result: about 70% less CPU per request, more than 80% less memory, and about a 20% cut in median time to first token — without taking the service offline or freezing feature development.

The Messages API was born in 2023 as a simple Python request forwarder, but traffic grew about 1,800 times from early 2024 to fall 2026, and Python started weighing on every step: validating, tokenizing, safety screening, and sorting output tokens into text, thinking, and tool calls. A first incremental attempt — rewriting only the model-output parsing in Rust and calling it from Python — cut CPU by just 8% to 10%, with each token crossing the language boundary three times. It was not worth the complexity.

Claude wrote the code in a week; proving it worked was the project

Claude wrote a first version of the Messages API's core request path in about a week. The problem, according to Anthropic, was not generating the code — by May 2026 Claude was already writing more than 80% of the code the company merged — but trusting the migration of a live system. The roughly 700 existing integration tests were not enough: an audit found more than 100 weakened assertions, and in April 2026 the Rust version passed about 98% of the tests yet only about 25% of real production inputs matched Python — for example, Python escapes emoji in JSON tool calls, while Rust wrote them as-is.

The fix was to turn the production Messages API itself into a verifier. The team used shadowing: running the model once (Claude is nondeterministic) and replaying the same output through both versions, comparing every step before and after the model call. To protect privacy, nobody read customer requests: the team recorded only the shape of each difference — where it happened and how large it was — using checkpoints and fingerprints that grouped the same kind of bug.

Three verification loops — with human review as the gate

The differences fed three loops: a fast inner loop, in a sandbox, where agents tested hypotheses in seconds; a slower outer loop, which validated fixes on shadowed production traffic; and a memory loop, which saved review lessons as rules — including in the CLAUDE.md file — so no mistake had to be corrected twice. Human review was the gate between the loops: when an agent proposed a shortcut for the web-search tool description problem, an engineer rejected it, because the fix did not actually solve the problem — Rust would still need to call the internal service.

Anthropic's lesson from the project is that when generating code stops being the bottleneck, verification becomes the bottleneck — and that a production system can serve as a verifier when tests and formal verification are not enough. The company says it is now increasingly feasible to migrate production systems with Claude, for performance or security, without taking the API offline.

Read also: Anthropic apresenta Siren: teste avalia se agentes Claude escapam de sandboxes.

Image: the Claude symbol (Anthropic, via Wikimedia Commons, public domain).

Sources

Transparency note: this article was produced with the assistance of artificial intelligence, cross-checked against public posts on X and internet sources, and reviewed before publication. Please consult the original sources to confirm the information.

By Muse