Claude rewrote its own API in Rust: the testing trick that made it safe

Anthropic moved its Messages API from Python to Rust, with Claude doing most of the implementation, and reports about 70% less CPU per request. The more useful lesson is how they checked it. They mirrored live requests to both versions, compared the outputs and moved traffic over gradually. Use the same approach for any AI-assisted rewrite.

Key takeaways

  • Anthropic reports about 70% less CPU per request and about 20% faster median time to first token
  • According to the team, Claude wrote most of the code and engineers owned the architecture and verification
  • Passing tests wasn't treated as proof. Live traffic was shadowed and compared
  • These figures cover the API layer, not model speed, and haven't been independently verified

What Anthropic rebuilt

The Messages API is the service behind every Claude API call. Anthropic replaced its Python version with a Rust version, building a complete replacement rather than migrating one endpoint at a time. Anthropic engineer Katelyn Lesse said on the Latent Space podcast in October that Claude did most of the implementation, while people handled the architecture, planning and verification. The team started with no Rust developers.

The results

In its research post, Anthropic reports about 70% less CPU per request and about 20% faster median time to first token. Earlier estimates from the podcast were lower, at 40–50% less CPU and 10–20% faster. One write-up notes that the old Python system was inefficient, so some of the gain may come from restructuring rather than from Rust alone.

The shadow-testing method

Think of opening a new kitchen. For a few weeks, every order is cooked twice. The old kitchen serves the customer, the new kitchen cooks the same dish quietly, and someone compares the plates. You switch only when they match.

Anthropic did the same with software:

  • Mirror production requests to the new Rust system without affecting users.
  • Compare outputs from both versions automatically.
  • Watch for drift: static analysis flagged new Python changes so the Rust version kept up.
  • Move traffic gradually once the outputs matched.

How to use this in your own rewrite

Picture a fintech team in London with a slow, ten-year-old billing service. Claude Code can draft the new version quickly, but speed is only safe with the same controls: shadow real traffic, compare results, and cut over in stages with a quick way back. Keep architecture and sign-off with your senior engineers.

 

Frequently asked questions

Trending question: Can AI rewrite my legacy code in a new language?

It can draft most of it, as Anthropic's own Rust migration shows. Engineers still need to own the architecture and verify the result with real traffic before switching.

Trending question: Is Rust faster than Python for APIs?

Often, for CPU-heavy services. Anthropic reports about 70% less CPU per request after its move, though some of that may come from restructuring, so measure your own workload.

What is shadow traffic testing?

It means sending copies of real requests to a new system without affecting users, then comparing its answers with the old system's before switching over.

Did Claude really write most of Anthropic's new API?

According to Anthropic engineer Katelyn Lesse, yes. Claude did most of the implementation, and people handled the design, planning and verification.

  • bm
    Writen by Anirban Das
logo