Companies·4 min read
By BitsMindsSource: Anthropic

Claude Agents Port Anthropic’s Messages API to Rust

Anthropic has moved its Messages API, the path behind every Claude API call and its own apps, from Python to Rust, with Claude agents writing and debugging most of the port. CPU per request fell about 70% and memory more than 80%, and median time to first token dropped about 20%. The hard part, Anthropic says, was proving the new code behaved exactly like the old.

Anthropic moves its Messages API from Python to Rust with Claude agents Editorial illustration: a machined clay-coloured gear with Claude's official mark inlaid in its ivory hub, standing for the engine of the API, beside the reported cut in CPU per request. The gear is a metaphor, not a programming-language logo. MESSAGES API Python → Rust −70% CPU PER REQUEST BITSMINDS.COM
Share:

Anthropic has rewritten the service at the centre of its business in a new language, and handed most of the work to Claude. In an engineering post dated November 25, the company says its Messages API, built in Python in 2023 and still the main path for customer requests and for Anthropic’s own apps such as Claude Code and Cowork, now runs in Rust. Public traffic moved over in September 2026.

The reason was load. Anthropic says API traffic grew roughly 1,800-fold between early 2024 and the fall of 2026, and the service does far more than forward a prompt: it validates requests, builds and tokenizes the prompt, runs safety classifiers, parses the model’s stream of text, thinking and tool calls, and counts usage for rate limits and billing. An earlier half-measure, rewriting only the output parser in Rust and calling it from Python, cut CPU by about 8 to 10 percent but forced every token across the language boundary three times, which Anthropic judged not worth the complexity.

Writing it was the easy part

Claude produced a first version of the core request path in about a week. Then came months of checking. The roughly 700 existing integration tests were tied to the Python implementation, and an audit of the ported tests found more than 100 weakened assertions. Rust passed about 98 percent of its tests in April, yet only about a quarter of real production inputs produced identical results at first, and the match rate briefly fell to 6.5 percent in early May before climbing to 99.6 percent as fixes landed. Some differences were tiny: Python escaped certain characters, including an emoji, inside JSON tool calls and Rust did not, so prompts differed by a few bytes.

Testing against production had two problems that the usual shadow-traffic tools, such as GitHub’s Scientist, do not face. A request cannot be run twice, because it must count once toward limits and billing, and Claude can answer the same prompt differently. So Anthropic called the model once and replayed its output to the Rust path, comparing every stage before and after the call. Engineers were not allowed to read customer requests, so the system recorded only the shape of each mismatch, such as the code step, the prompt piece, the first differing byte and the lengths, and grouped them into fingerprints that pointed at likely bugs.

A coordinating Claude agent assigned a worker agent to each new kind of mismatch and opened a Slack thread so engineers could follow and steer. Each worker ran in a sandbox holding both codebases, guessed a cause, wrote a request that triggered it, edited the Rust until the outputs matched and added a test that fails on the old code. Engineer corrections became standing rules: about 60 review comments were folded into CLAUDE.md guidance in June, alongside lints and a merge check requiring every Python change to have a matching Rust change. The post is candid about one failure: to fix a missing web search tool description, an agent copied the text into files Rust could read. It passed the verifier, and an engineer rejected it, because, in Anthropic’s words, the agent “found the cheapest way to produce” matching outputs.

The payoff

Anthropic reports CPU per request down about 70 percent, measured in one region, memory per request down more than 80 percent across production, and median time to first token down about 20 percent, measured on customer Claude Code requests over roughly two weeks in September. The post does not say which Claude models ran the migration, how many agents were involved or how many lines changed. It joins a run of agent-written migrations, including Bun’s move from Zig to Rust, and it lands awkwardly beside the Rust project’s own August decision to bar LLM-written code from its compiler.

The lesson Anthropic draws is that verification, not code generation, has become the bottleneck, and that humans earn their keep by defining what “correct” means and gating each fix. It is the same division of labour the company is now selling with Claude Ship, its agents that review and approve pull requests. Here the evidence is unusually concrete: the API that customers pay for was rebuilt underneath them, and the main thing they should have noticed is that it got faster.

More on Claude

Evergreen coverage we keep current — start here.

Want AI news before everyone else?

The morning's most important AI stories, straight to your inbox. No fluff.

Related Articles