Claude helped Anthropic move its Messages API from Python to Rust, cutting CPU per request by about 70%
· Anthropic
Anthropic rewrote the API that serves Claude in Rust, with Claude writing the first version of the core request path in about a week. Checking the rewrite was the hard part: it used live traffic as the test and AI agents to fix mismatches, with engineers reviewing.
Key numbers
- ~70% less CPU per request
- ~20% faster median time to first token
- ~1,800× API traffic growth, early 2024 to fall 2026
What happened
On 25 November 2026, Anthropic described how it moved its Messages API, the main way customers and its own apps such as Claude Code reach Claude, from Python to Rust without taking the service offline or pausing feature work. Public traffic switched to Rust in September 2026.
Why rewrite at all
API traffic grew roughly 1,800 times from early 2024 to fall 2026, and Python added overhead at every step of a request. Rewriting just the output parser in Rust saved only 8–10% of CPU, because each token then crossed between the two languages three times. By May 2026 Claude was writing more than 80% of the code Anthropic merged, so a full rewrite became realistic.
"Verification, not generation, had become the bottleneck." — Anthropic
Checking the rewrite
- In April the Rust version passed about 98% of its tests, yet only about a quarter of real requests matched the Python output.
- An audit of the ported tests found more than 100 weakened assertions, meaning a "pass" could hide wrong code.
- Anthropic shadowed live traffic: each request ran on Python and was replayed through Rust. The model ran only once, so customers were not billed twice and Claude's varying replies didn't cause false alarms.
- Agents fixed differences in a sandbox, then on shadow traffic, and saved reviewers' corrections as rules for later agents. A merge check now requires any Python change to come with a matching Rust change.
Takeaway: an AI can write a large rewrite quickly, but trusting it needs tests that can't be quietly weakened and a comparison against real behaviour.
Source: https://www.anthropic.com/research/migrating-api-to-rust
Tags: Agents, Anthropic, Claude, Rust, Software engineering