Key takeaways
- Anthropic migrated its Messages API from Python to Rust, significantly reducing CPU usage and memory consumption.
- The migration was necessary due to a dramatic increase in API traffic, growing 1,800 times over two years.
- The original Python service became costly as it evolved from a simple request-forwarding system to a complex processing infrastructure.
- The move to Rust aimed to eliminate computational overhead caused by Python's object creation and memory management.
Anthropic has rewritten its Messages API from Python to Rust, cutting CPU usage per request by around 70% and memory consumption by more than 80%.
However, the migration exposed a significant problem with AI-generated code: despite passing 98% of its existing integration tests, the new implementation initially matched only around 25% of inputs when tested against live production traffic.
The migration, completed in September, involved rebuilding the core request-processing infrastructure through which customers access Claude, including Anthropic's own products such as Claude Code and Cowork. The company detailed the project in a recent engineering blog post.
Anthropic said API traffic on its platform grew roughly 1,800 times between early 2024 and autumn 2026. The original Python service, built in 2023 as a relatively simple request-forwarding system, had become increasingly expensive to operate as it took on additional responsibilities.
Every request now involves input validation, prompt construction, tokenisation and safety classification. The API also processes model outputs, separates text, thinking and tool calls, streams responses to customers and tracks usage for billing and rate limits. Anthropic said Python introduced overhead at each stage through object creation, memory management and task hand-offs.
The company initially attempted a partial migration by rewriting the code responsible for parsing model outputs in Rust while retaining Python for other operations. This reduced CPU consumption by around 8–10%, but introduced additional complexity as response tokens repeatedly crossed between the two languages.
Anthropic subsequently opted for a complete rewrite. Claude generated the first version of the API's core request-processing path in approximately a week. However, verifying that the Rust implementation behaved identically to the existing production service proved much harder.
"Our Rust API passed about 98% of its tests in April, yet only about a quarter of inputs matched on production traffic," said Anthropic. "The gap came partly from cases in production traffic that our tests didn’t cover."
The discrepancy exposed limitations in the company's testing infrastructure. Anthropic had approximately 700 integration tests, but these were closely coupled to the original Python implementation. During an audit of the ported tests, it also discovered more than 100 weakened assertions.
One example involved JSON serialisation. Python escaped certain characters, including emojis, into text codes when generating JSON tool calls, while Rust processed them differently. This resulted in prompts that differed by a few bytes, even when both implementations successfully processed the request.
Anthropic said the production input match rate eventually reached 99.6% by August.
"Verification, not generation, had become the bottleneck," the company said.
To identify discrepancies without exposing customer data, Anthropic developed a shadow-testing system that ran requests through both implementations. Since Claude could produce different responses to identical requests, the company ran the model once and replayed its output through the Rust implementation, allowing the two API versions to be compared using identical model responses.

It also recorded where discrepancies occurred, their size and the processing stages where they originated. These records were grouped into fingerprints that Claude agents could investigate and use to propose fixes.
Human engineers continued to review pull requests and approve changes before deployment. Anthropic said automated verification could establish whether outputs matched, but could not independently determine whether a proposed fix was suitable for production.
By September, the company had moved production traffic to Rust without taking the API offline or freezing feature development.
Anthropic reported a roughly 70% reduction in CPU usage per request in one production region and more than 80% lower memory consumption per request across production. Median time to first token for Claude Code customer requests also fell by approximately 20%.
The company said the project demonstrated that AI coding agents could undertake large-scale production software rewrites, provided they were supported by systems that independently verified their output.
"The verifier rewarded matching outputs, and the agent found the cheapest way to produce them," Anthropic said, explaining why human engineering oversight remained necessary.
Spotted an error? Tell our editors. Read our editorial standards and corrections.






