Image generated using ChatGPT
Anthropic has migrated its Messages API from Python to Rust, using Claude AI agents to help write the code, identify bugs and verify that the new system behaved like the old one.
The company says the migration reduced CPU usage per request by around 70% and improved median time to first token by approximately 20%. The API remained online throughout the process, and development continued without being paused.
The project highlights an increasingly important challenge in AI-assisted software development: writing code may be getting faster, but verifying that it works correctly is still difficult.
According to Anthropic’s official engineering report on the Rust migration, Claude wrote the first version of the API’s core request path in about a week. The company then built a system that compared the new Rust implementation with its existing Python service and used AI agents to investigate differences.
Why Anthropic Moved From Python to Rust
Anthropic originally built its Messages API in Python in 2023. As the service expanded, it became responsible for more than simply passing requests to a model.
Requests now go through several stages, including validation, prompt construction, tokenization and safety checks. Responses also need to be processed, streamed to users and checked for usage and billing.
As traffic increased, Python’s overhead across these steps became more noticeable. Anthropic said its API traffic grew roughly 1,800 times between early 2024 and fall 2026.
The company had previously rewritten part of the system in Rust, but that approach created additional complexity because requests and responses still had to move between Python and Rust.
Anthropic eventually decided a full migration would make more sense. Rust, a programming language designed with performance and memory safety in mind, offered a way to reduce the overhead of the existing service.
Developers interested in the language can explore the official Rust programming language documentation, which explains its approach to performance, memory safety and concurrency.
Claude Wrote the Initial Code, but Verification Was the Hard Part
Claude helped produce the initial version of the Rust API’s core request path in about a week. The bigger challenge was making sure it worked exactly as expected.
Anthropic already had around 700 integration tests, but these were not enough to guarantee that the new implementation matched the old one.
Some tests were closely tied to the Python implementation and had to be changed during the migration. Anthropic later found more than 100 weakened assertions in the ported tests.
The company also found that passing tests did not necessarily mean the new API behaved correctly in production. In April, the Rust implementation passed roughly 98% of its tests, but only about a quarter of its inputs matched the Python version on production traffic.
That gap pushed Anthropic to build a more reliable way of checking the migration.
How Anthropic Used Production Traffic to Find Bugs
Instead of relying only on test cases, Anthropic compared the Python and Rust implementations using production traffic. The existing Python service acted as a reference for the new version.
The company had to account for a few complications. Running requests twice could affect billing and rate limits, while Claude could produce different responses to the same request.
Anthropic solved this by running the model once and replaying the output through the Rust implementation. This allowed the company to compare the processing stages without unnecessarily calling the model twice.
The comparison looked for differences in areas such as:
- Request validation
- Prompt construction
- Tool descriptions
- Input processing
- Response handling
- Token usage and accounting
The system also recorded where differences occurred without storing customer prompts or responses. This allowed the engineers and AI agents to investigate mismatches while protecting user privacy.
Claude Agents Helped Investigate and Fix the Differences
Anthropic grouped similar mismatches together so that AI agents could focus on individual bugs rather than investigating every affected request separately.
The agents could inspect the code, reproduce a problem using their own test inputs, try potential fixes and create pull requests with tests.
Anthropic organised this process into three verification loops.
The Inner Loop
The inner loop allowed Claude agents to investigate bugs inside isolated cloud sandboxes.
Agents could test their ideas against the Python and Rust versions and receive results quickly. Some checks took less than a second because they did not need to call the model.
If an agent found a fix, it could update the Rust code and add a test demonstrating the problem.
The Outer Loop
The outer loop checked whether fixes worked beyond the sandbox.
After a human engineer reviewed and approved a change, it could be deployed and tested against shadowed production traffic. If the mismatch remained, the agent returned to the inner loop for further investigation.
This helped catch problems that local tests could miss.
The Memory Loop
Anthropic also saved lessons from rejected fixes and engineering reviews.
For example, if an agent proposed a workaround that made two versions match but was not suitable for production, engineers could explain why. That lesson was then recorded so future agents would avoid repeating the same approach.
Some lessons were also turned into tests, rules and checks to prevent similar mistakes from returning.
What Improved After the Rust Migration?
Anthropic reported three notable improvements following the migration:
| Metric | Reported Improvement |
|---|---|
| CPU usage per request | Around 70% lower |
| Memory usage per request | More than 80% lower |
| Median time to first token | Around 20% lower |
The CPU reduction could help Anthropic serve more requests using fewer computing resources. The improvement in time to first token could also make streamed responses feel faster, although it does not mean every response is now 20% faster.
These are Anthropic’s reported measurements from its own infrastructure and workloads.
The performance benefits also reflect why companies increasingly evaluate programming languages based on the demands of their infrastructure. The official Python documentation remains relevant for understanding the language and its ecosystem, while Rust’s focus on performance and memory safety makes it an option for workloads where runtime overhead matters.
What This Means for AI-Assisted Software Development
The migration offers a useful example of how AI agents could take on larger engineering projects.
Claude was not simply asked to rewrite a service and produce code. It was given a way to test its work, identify differences, investigate failures and try again.
That distinction matters. AI-generated code can look correct while still introducing bugs or missing edge cases. Anthropic’s approach used the existing production system as a reference, allowing the agents to work through problems with a clearer verification signal.
The same approach could be useful for software migrations, refactoring, performance optimisation, testing and maintaining large codebases.
However, human engineers still played an important role. They reviewed fixes, rejected unsuitable workarounds and decided which changes were ready to move forward.
This is also why AI agents are not yet a replacement for engineering oversight. Our coverage of the GDPx benchmark and the challenges AI agents still face with real-world tasks provides additional context on why reliable verification remains essential.
The growing use of agents across businesses also raises questions about how these systems should be deployed and supervised. TechDhalsim previously covered how companies are bringing AI agents into real-world operations, illustrating the shift from AI assistants answering questions to systems participating in business workflows.
Why Verification Could Become the Next Bottleneck
For years, software development has been limited by the time and effort required to write code.
AI coding tools are changing that equation. Developers can now generate implementations, tests, documentation and prototypes much faster than before.
But faster code generation creates another challenge: how do teams verify that the generated code is correct?
Anthropic’s migration demonstrates that verification can become the limiting factor in AI-assisted development.
The company did not simply ask Claude to rewrite the API and deploy the result. It built a system that could continuously compare the old and new implementations, identify differences, allow agents to investigate them and validate fixes against production behaviour.
This approach could offer a useful blueprint for companies attempting complex AI-assisted engineering projects.
The future of AI development may depend less on how quickly an agent can produce code and more on how effectively it can prove that its work is safe, reliable and correct.
Frequently Asked Questions
Why did Anthropic migrate its Messages API to Rust?
Anthropic wanted to reduce the computing overhead of its Python-based service as API traffic grew. Rust helped lower CPU and memory usage.
Did Claude write the Rust API?
Claude wrote the initial version of the core request path in about a week and helped investigate and fix differences during the migration.
How much CPU did Anthropic save?
Anthropic reported around 70% lower CPU usage per request.
What are the three verification loops?
The inner loop tests fixes in a sandbox, the outer loop checks them against production traffic, and the memory loop saves lessons from previous mistakes.
Did Anthropic take the API offline?
No. Anthropic says the migration was completed without taking the service offline or freezing feature development.
Final Thoughts
Anthropic’s migration shows that AI agents can contribute to more than small coding tasks. They helped with a complex production migration, investigated bugs and improved the new implementation through repeated testing.
But the biggest takeaway is not simply that Claude wrote the code quickly. Anthropic built a verification system that gave the agents a reliable way to check their work.
As AI coding tools become more capable, the ability to verify their output could become just as important as their ability to generate it.













Leave a Reply