Anthropic Retrospectives: Validation Methods for Migrating the Messages API from Python to Rust
Using the production system as the validator, post-migration CPU per request dropped by about 70%, and median time to first token improved by about 20%

Table of Contents (3)
Key Takeaways (TL;DR)
- 01Anthropic rewrote the Messages API from Python to Rust and used the production system as a validation benchmark to test behavioral consistency between old and new versions.
- 02After migration, CPU usage per request dropped by about 70%, median time to first token improved by about 20%, and the service stayed online throughout.
- 03API traffic grew roughly 1,800x from early 2024 to fall 2026, the core driver behind the migration.
Anthropic disclosed its validation methodology for migrating the Messages API from Python to Rust, treating the production system itself as the validator. After migration, CPU per request fell by about 70%, median time to first token improved by about 20%, and the service remained live without freezing feature development.
1,800x Traffic Surge Forces an Architectural Rewrite
In an official research blog post, Anthropic reviewed the complete process of migrating the Messages API from Python to Rust. This API is the primary channel through which customers and first-party applications such as Claude Code and Cowork access Claude. From early 2024 to fall 2026, API traffic grew roughly 1,800x, far exceeding the design capacity of the original Python service. As the Messages API grew more feature-rich, each request had to go through validation, conversion into prompts, tokenization, and safety classifier screening, and Python's overhead in object creation, memory deallocation, and task handoff was amplified at every step.
The team initially tried an incremental approach, rewriting only the part that parses model output in Rust and calling it from Python, which reduced CPU usage by only about 8% to 10%. But each token had to make three round trips between Python and Rust, and the added complexity did not yield commensurate benefits. Anthropic therefore reassessed the feasibility of a full migration, and by then Claude could write more than 80% of the code Anthropic merges, the cost of generating code was falling rapidly, and verifying correctness had become the real bottleneck.
After migration, CPU per request dropped by about 70%, median time to first token improved by about 20%, and the service stayed online throughout.
- Messages API traffic grew roughly 1,800x from early 2024 to fall 2026
- The incremental Rust approach reduced CPU usage by only about 8% to 10% and introduced cross-language round-trip overhead
- By May 2026, Claude wrote more than 80% of the code Anthropic merges
Why Verification Is Harder Than Generation
Anthropic points out that many problems involve a gap between generation and verification: verifying whether a solution is correct is often far easier than coming up with one. Sudoku is a classic example—checking an answer only requires counting the digits in each row, column, and box, but solving it can take a long time. When Claude began to be involved in transforming live systems, this gap was magnified—the edge cases and special behaviors users rely on are often not covered by the test suite, and it is hard to write a definition of "correct" that covers everything.
Migration Strategy: Using the Production System as the Validator
Anthropic first needed to define what "correct" means. Mathematical theorems can be verified step by step by proof assistants such as Lean, while software engineering commonly uses test suites to define correctness—for example, when Bun migrated from Zig to Rust, it used the TypeScript test suite to judge both versions simultaneously. But the Messages API was trickier: during the migration, the Python version continued to evolve, with new models and features rolling out constantly, making "correct" a moving target; Claude's responses to the same request are non-deterministic, so two different outputs do not necessarily indicate a defect; and the team could not read customer request content, making it difficult to directly pinpoint differences between the two versions.
The final approach was to treat the Messages API in production itself as the validator. The team tested the new Rust version with production traffic, compared behavioral differences between the two, and automatically dispatched AI agents to fix inconsistencies. This method bypassed the problem of test suites being too tightly coupled to the Python implementation, and it could detect divergences under real traffic without reading customer request content. Anthropic said it was this validation mechanism that gave the team the confidence to complete the migration without downtime or freezing feature development.
Verification, not generation, was the real bottleneck of this migration.
- About 700 existing integration tests were coupled to the Python implementation, making it hard to independently judge migration correctness
- Production traffic comparison can cover edge-case behaviors beyond the test suite
- Automatically dispatched AI agents locate and fix behavioral differences between old and new versions
The Dual Challenge of Non-Determinism and a Moving Target
Claude may give different responses to the same request, so output differences cannot be directly judged as defects; the team had to distinguish the model's inherent randomness from behavioral deviations introduced by the migration. At the same time, the Python version kept changing throughout the migration, and any static baseline would quickly become outdated. Using the production system as the validator means the validation standard evolves in sync with online behavior, preserving the effectiveness of the comparison in a dynamic environment.
Implications for Transforming Live Systems
Anthropic's retrospective shows that as AI's ability to generate code improves rapidly, the constraint engineering teams face is shifting from "can we write it" to "can we verify it clearly." For live systems with massive traffic, complex behavior, and continuous evolution, traditional test suites struggle to cover all production behavior, while full rewrites have long been treated cautiously due to risk and workload. Using the production system as a validation benchmark offers an actionable path for such transformations.
It is worth noting that this method relies on the combination of production traffic and automated repair agents, placing high demands on observability and agent orchestration capabilities. Anthropic did not disclose plans to reuse this migration method on other services, nor did it specify the Rust version's performance in edge cases. Industry observers believe that as AI agents participate in maintaining more online systems, how to build a reliable verification loop will become a key issue in engineering practice.
No downtime and no freeze on feature development throughout the migration directly demonstrate the effectiveness of this method.
- As AI-generated code accounts for a growing share, verification capability becomes the main bottleneck for migration and refactoring
- Production traffic comparison suits live systems with insufficient test suite coverage
- Automatically dispatched agents fix differences, reducing manual troubleshooting costs
Impact
Industry Impact & Strategic Takeaways
This retrospective provides a migration paradigm that high-frequency API services and AI platforms in the Asia-Pacific region can learn from: under the dual pressure of surging traffic and continuous feature iteration, using the production system as the validator enables language-level rewrites without downtime. For teams evaluating high-performance runtimes such as Rust as replacements for Python, the quantified benefits in CPU and time to first token are worth referencing, but the cost of building the validation mechanism and the agent orchestration capability must be assessed in advance.
Frequently Asked Questions
Why did Anthropic migrate the Messages API from Python to Rust?
+
API traffic grew roughly 1,800x from early 2024 to fall 2026, amplifying Python's overhead in object creation, memory deallocation, and task handoff. After migration, CPU per request dropped by about 70%, and median time to first token improved by about 20%.
How did Anthropic verify that the Rust version behaves consistently with the production version?
+
The team treated the Messages API in production itself as the validator, using real traffic to compare behavioral differences between the two versions and automatically dispatching AI agents to fix inconsistencies, thereby completing the migration without downtime.
Why choose a full migration instead of an incremental rewrite?
+
The incremental approach reduced CPU usage by only about 8% to 10%, and each token had to make three round trips between Python and Rust; the added complexity did not yield commensurate benefits, so the team turned to a full migration.
Primary Source & Attribution
Anthropic:Research(发表成果 · 网页)
Migrating our Messages API to Rust
Related Deep Dives

Anthropic Stress-Tests Claude Docs with a Chaos Loop: 60 Errors in 2 Billion Requests, Resource Estimates Cut by 90%
79 pts · 7 min read

Kazik Breaks Down the Claude, GPT, and Gemini Multi-Model Orchestration: Divide Work by Personality, Not a Single Version of the Answer
72 pts · 6 min read

Anthropic Merges Claude Connectors and Skills into Plugins, Unifying Tool Integration
70 pts · 4 min read

Anthropic Platform Engineering Lead Katelyn Lesse on Building Software with Claude in 2026
78 pts · 5 min read