A summary of how Anthropic migrated its Messages API from Python to Rust, with no downtime and no feature freeze.
TL;DR: Claude wrote the first version of a Rust Messages API in about a week. The hard part was proving it behaved exactly like production. Anthropic turned the live Python API into a verifier: it shadowed real traffic, located each difference without reading user data, and automatically sent agents to fix them. The result uses ~70% less CPU per request and cuts median time to first token by ~20%.
| Result | Change |
|---|---|
| CPU per request | ≈ 70% lower |
| Memory per request | > 80% lower |
| Median time to first token | ≈ 20% faster |
| Input parity with Python on production traffic | 24% → 99.6% |
| Downtime / feature freeze | None |
Many problems have a generator–verifier gap: it's often far easier to verify that a solution is correct than to come up with one. Sudoku is a classic example. Checking a solution is simple (just count the numbers in each row, column, and box), but finding that solution can take a long time.
Many ambitious Claude projects have relied on this gap. Formalizing proofs in mathematics or migrating large, well-tested codebases are tasks Claude can take on as long as it has a reliable way to verify its work.
But as Claude has become more capable, it has begun to take on projects in live systems, where generating the work is easier than verifying it. In these systems, users often rely on edge cases and quirks that fall outside the test suite, and it's hard to write a definition of "correct" that covers everything. Without a reliable way to check Claude's work, the migration of a live system is hard to trust, however quickly Claude can generate the code for it.
Anthropic ran into this problem when it migrated its Messages API from Python to Rust. This API is the primary way that customers, and Anthropic's own apps like Claude Code and Cowork, reach Claude. From early 2024 to fall 2026, API traffic grew roughly 1,800×, and Rust would let the company use far less CPU per request.
Claude wrote a first version of the API's core request path in about a week. But building trust in the migration meant verifying that the Rust API was at parity with the production API. That proved hard for three reasons:
The write-up describes how Anthropic turned the production Messages API itself into a verifier, and how that let the team test the new Rust version on production traffic, find where it differed, and automatically dispatch agents to fix those differences. The result is a Rust API that uses about 70% less CPU per request and cuts median time to first token by about 20%, shipped without ever taking the service offline or freezing feature development.
Anthropic built the Messages API in 2023 and wrote it in Python, which was widely used internally for much of its research code. At first, it was simple: the API passed requests to the model and sent back what the model wrote.
One engineer at the time called it "basically a request forwarder."
But as the Messages API became more capable and more deeply integrated with Anthropic's codebases, it developed shared dependencies on Python libraries owned by the research and inference teams, which made it hard to move. Moving to another language would have meant rebuilding logging, metrics, and tooling all over again.
That calculus gradually began to change. By late 2025, every Messages API request had to be:
As each reply arrived, the stream of tokens had to be sorted into text, thinking, and tool calls. Python added overhead to every one of those steps, each time it created an object, freed memory, or handed its work to the next task. Traffic eventually grew far beyond what the original Python service was built for, and the team needed to make the service much more efficient, quickly.
Full rewrites of large production systems are usually approached cautiously, for at least two reasons:
In 2024, after one Anthropic engineer suggested migrating to Go or Rust, another temporarily settled the question: "We are not rewriting the API in go or rust!"
For performance gains, the standard advice is to rewrite only the parts that slow the system down, so that's where the team started. It rewrote the code that parses a model's output in Rust and called it from Python. This cut the API's CPU usage by about 8–10%.
However, incremental solutions add complexity, and the gains have to justify that cost. These didn't. Each token now crossed between Python and Rust three times, which created new sources of overhead.
As Claude became more capable, the team began to question whether the usual reasons to avoid a full migration still held. The effort required was dropping fast: by May 2026, Claude was writing more than 80% of the code Anthropic merged.
The team wondered whether Claude could now help write code that empirically captured every behavior and fix in the production system. That raised a new question: how could they verify that the migrated behavior was correct?
Verification, not generation, had become the bottleneck.
To verify the migration, the team first had to define what "correct" meant. There are a few ways to do this:
Tests were the easiest place to start, since the team already had about 700 integration tests. But two problems limited how far those tests could be trusted for a migration this high-stakes.
1. The tests were coupled to the Python implementation. An integration test sends a request, then checks the reply and what was sent to other services. Anthropic's tests ran the Python API inside the test's process and mocked services like billing and rate limiting in Python's memory. So the tests had to change along with the code, and Claude helped with both. A "pass" could now mean the code was right, or that the test had been changed in a way that let wrong code through. This did happen: when the team audited the ported tests, it found more than 100 weakened assertions.
2. The tests were incomplete. The Messages API has dozens of features, far too many configurations to test exhaustively. Just 20 binary options make over a million combinations. At one second per test, that's 12 days of testing for one model, before varying the prompts at all. In practice, engineers test a subset that tries to approximate production, and that process inevitably misses cases. Some projects, like Bun, have an independent suite extensive enough to judge a rewrite. Many production services don't: what counts as correct depends as much on how they behave as on what's in their tests or documentation.
Production data is sometimes "the only true test" that new code behaves like the old code. Running requests through both old and new code and comparing the results is often called shadowing.
To understand what needed comparing, it helps to follow one request through the Messages API:
The migration covered both paths. Some differences were obvious, such as the Rust API rejecting a request that Python had accepted. Many were subtle. If the Rust API left out part of a prompt, for example, the request would still succeed and the model would still answer, just sometimes slightly differently. Differences the team found included a rejected field, a 1M limit read as 200K, a missing tool description, stripped newlines, and missing usage fields. One risk it had to design against was a request being counted twice.
In April, the Rust API passed about 98% of its tests, yet only about a quarter of inputs matched on production traffic. There were two reasons for the gap:
As fixes rolled out, the share of matching inputs rose from 24% to 99.6% by August.
Common shadowing tools assume that a request can safely run twice, or that the service is deterministic. Neither assumption held here:
So the team ran the model once and replayed its output to Rust.
With both versions working from the same model output, the team still had to compare every stage before and after the model call, and the results had to match exactly. In many systems, bad input causes an error somewhere down the stack. But Claude accepts almost any prompt, so even a small deviation can change its reply without triggering an error. Comparing each step on both sides of the model call let the team pin down any deviation that might change what a customer received.
Anthropic wanted to do all of this in a way that protected user privacy. That meant working without reading user requests or Claude's replies, so the team couldn't simply look at where the Rust and Python versions differed. Instead of looking at text, it recorded the shape of each difference: where in the service it happened and how big it was. Two techniques made this work.
Both versions handle a request through the same steps: accept or reject it, resolve its settings, build the prompt. Every step produces a result, such as an error or the pieces of the prompt, that could be compared step by step, and within the prompt, piece by piece. The first place they differed showed roughly where the migrated code diverged from production.
| Step | Python vs Rust |
|---|---|
| Accept or reject | ✅ Match |
| Resolve settings | ✅ Match |
| Build prompt | ❌ First difference. Piece 2: two keys in a different order, starting at byte 17 |
Simplified, with made-up values.
Once the team knew roughly where each difference was, it still needed a way to tell one bug from another. For each difference, it recorded where it began in the prompt and the length difference between the two versions. Combined with the step and prompt piece from checkpointing, this gave every bug a distinctive fingerprint: one bug tends to leave the same fingerprint on every request it affects. Grouping errors by fingerprint helped triage the fixes, and fixing one dominant fingerprint could reveal older ones it had been hiding.
The result was a shadowing system that produced a small record for each difference between the Rust and Python APIs. Here's an example, with made-up values:
step: build prompt ← where in the code
piece: 2 ← where in the prompt
first diff: byte 17 ← fingerprint
python: 190 bytes ← fingerprint
rust: 190 bytes ← fingerprint
The record contains no user text, and it could be handed to an agent to fix.
Every request that differed left a record in the logs, and a single bug could produce hundreds of thousands of nearly identical records. Rather than send each one to an agent, the team set up a pipeline:
To work through the many bugs, the team set up three verification loops. Each loop can catch what the one inside it misses.
When the work started in April, each agent got a record showing where the Rust and Python versions differed. Agents would guess the root cause from the code and open a pull request. Once the fix was reviewed and merged, they deployed it to staging, a preproduction copy of the Rust API running the same shadow comparison on test traffic, and checked whether the difference was gone. Because every hypothesis needed a review and a deployment, feedback took hours or days.
Agents needed a verification signal much sooner, so the team gave them their own workspace where they could test ideas quickly and fail safely. Each agent ran in a cloud sandbox with both codebases and fast local checks for both sides of the model call:
The main limitation was that agents saw only the fingerprint, never the request behind it. So each agent would:
The seam between the inner and outer loops turned out to be a good checkpoint for human review. Inside the sandbox, a wrong guess cost an agent only a few seconds and had no impact on users, so agents could iterate on their own. A fix could cross into the outer loop only after PR review. That let engineers focus on proposed fixes rather than guesses, and on questions the verifiers couldn't answer, such as whether a difference between the two APIs was a bug or a deliberate change.
Agents posted their fixes and evidence to their Slack threads for engineers to review. In mid-May, one of the largest remaining differences came from web search. The production API retrieved the web search tool's description from an internal service. The Rust API didn't call that service yet, so the description was missing from its prompts.
An agent proposed a shortcut: copy the text into files Rust could read. The prompts then matched, and the fix passed the local verifier. But an engineer rejected it, because it didn't solve the real problem. Rust would still need to call the service before launch, and at that point the workaround would be thrown away.
#rust-migration Engineer: asks the coordinating agent to explain its next target. Claude agents: trace the mismatch to web search, find it's already tracked, and open a fix that loads the description from text files. Second engineer: "We know we have to fetch that text before we ship, so this seems like throwaway code. Abandon that PR."
The verifier rewarded matching outputs, and the agent found the cheapest way to produce them.
A verifier can tell an agent whether the outputs matched, but not whether the fix is good enough to ship. That's why human review was an important gate.
In the inner loop, agents debugged differences and proposed fixes. At the seam, engineers reviewed those fixes, gave feedback, and approved them for deployment. The outer loop then compared Rust deployments with and without each fix.
To keep that comparison fair, the team logged facts about each compared request, but not its text, including which model and API features it used (prompt caching, tools, or extended thinking, for example). These details let agents compare requests of the same kind and ask how often a bug's fingerprint appeared on builds with and without the fix. That way, agents could monitor new builds for the bug.
The outer loop was designed to catch what the inner loop missed. The inner loop simulated production quickly but imperfectly: agents could test a hypothesis in seconds, but only on requests they had written themselves, and with a local verifier that wasn't always configured exactly like production.
So sometimes a fix passed in the sandbox while production still showed the difference. The agent assigned to that bug would either see the difference in the new build's records or be alerted by the coordinating agent. It then went back to the inner loop and used that evidence to form a new hypothesis.
The inner and outer loops fixed one difference at a time. The memory loop improved how agents made those fixes. The team didn't want engineers to make the same correction twice, so it recorded what came out of reviews and agents' own work, and applied it to every agent that followed.
Remembering decisions. When an engineer rejected the web search shortcut, the agent saved a note to memory explaining the decision, the reason for it, and the correct fix: have Rust call the service that supplies tool descriptions.
Building that call took the team weeks, and in the meantime the bug kept producing records. Some had new fingerprints, because the missing text fell at other positions in the prompt or belonged to another tool that used the same service. Agents checked the memory note, recognized the known bug, and linked those records to it instead of writing another workaround.
Turning corrections into rules. Other lessons became general rules for porting and writing Rust. After one agent guessed at Python's behavior (prompting an engineer to ask, "Did you make that up yourself?"), the engineer made it a rule to port exactly what Python did. Another agent then checked the existing code against that rule and found seven more places where the port had relied on a guess.
Mining review comments. In June, an agent went through about 60 of the team's review comments, grouped the recurring problems, and proposed rules, which an engineer edited and approved for CLAUDE.md.
Encoding lessons as permanent checks. The memory loop also produced checks that couldn't be forgotten:
It's increasingly feasible to migrate production systems with Claude, for better performance or security, without taking an API offline or slowing feature development. Now that writing new code is no longer the hard part, the work is building enough confidence that the new system behaves like the old one.
The usual approach to migration is a bit like rebuilding the Ship of Theseus, where the old ship is replaced plank by plank. It's generally possible to replace planks while the ship still sails, but changing too many at once means coming into dock.
To stretch the metaphor fully: Claude now makes it possible to build an identically functioning ship alongside the first, even as the first keeps sailing and having its planks replaced. Agents kept the new ship in step as the old one changed, and the team kept checking that the two behaved the same. Once they trusted that they did, they moved the passengers over a few at a time. The new ship sails faster and more efficiently than the old one.
Large software projects like migrations used to be hard to justify because they took too much effort and carried too much risk. If writing code is no longer the bottleneck, the main constraint becomes how quickly results can be verified. In general, ambition can grow as long as Claude has a way to verify correctness.
In math, Anthropic uses a proof assistant to verify that each step of a proof Claude wrote is valid. In software, tests or formal verification give similar confidence. When those checks aren't enough, a production system itself can be the verifier.
A verifier provides a signal Claude can act on, and that signal can be calibrated to show Claude where things went wrong. A proof assistant points to the failing step and a test names the failing case, but a production system usually offers no such signal by default. Much of the team's effort went into building one: checkpoints located each difference in the code, and fingerprints told one bug from another.
Together, these loops let Anthropic migrate the Messages API to Rust:
The team tried to put human judgment only into what counted as correct, and left it to Claude how to get there. Agents chose which hypotheses to test, how to reproduce each bug, and how to fix it. The verifiers judged the result. Simple loops around strong verifiers let the team keep moving productively over time: changes merged to the API's Rust code grew from under 100 per two-week period in April to more than 3,000 by August.
The engineers' role shifted as the system matured:
As Claude grew more intelligent, and as the team got better at working with it, Anthropic went from directing Claude to Claude directing itself, with humans relied on mainly for the important judgment calls.
| Partial rewrite (March 2026) | Full rewrite (September 2026) |
|---|
| Python | Does every step except receiving and parsing tokens | Hands over the request |
| Rust | Receives and parses tokens | Does every other step around the model |
| Language boundary | Each token crosses it three times | Crossed only at the hand-over |
| Source of correctness | Example | How much is written down | Signal the agent receives |
|---|
| A rule | Lean (proofs) | All of it | A step that doesn't follow |
| Examples | Bun's test suite | Part of it | A failing test |
| An existing system | Anthropic's Python service | None of it | A checker you build that flags where the two differ |
| Loop | Question it answers | How it checks | Speed |
|---|
| Inner | Does this edit fix the difference? | Local checks in a sandbox | Under a second per comparison |
| Outer | Is the difference gone in production? | Shadowed live traffic | Hours or days |
| Memory | Why does this keep happening? | People's corrections, turned into rules | Ongoing |
| Metric | Change | Period | Measured on |
|---|
| CPU per request | ≈ −70% | August → October | One region |
| Memory per request | > −80% | August → October | All of production |
| Median time to first token | ≈ −20% | ~September 7 → 21 | Customers' Claude Code requests |