Anthropic has moved the Messages API, the production service that every customer and every one of its own applications uses to reach Claude, from Python to Rust, and it says Claude wrote the code. The rewritten API uses about 70 percent less CPU per request and cuts median time to first token by about 20 percent, and the migration was completed without ever taking the service offline or freezing feature development, the company wrote in a November 25 post on its research site.

The project is a case study in how a leading lab handles the problem at the center of AI-assisted engineering in 2026: when a model can write the code, the hard part is proving the new code behaves exactly like the old one. For more on how Anthropic, OpenAI, and others are reshaping their infrastructure, see our AI research coverage.

Why Rewrite a Service That Works

Anthropic built the Messages API in 2023 in Python, the language used internally for much of its research code. At first it was simple enough that one engineer called it "basically a request forwarder." But by late 2025 every request had to be validated, converted into a prompt, tokenized, and screened by safety classifiers, and every reply had to be sorted into text, thinking, and tool calls as it streamed. Python added overhead at each of those steps. From early 2024 to fall 2026, API traffic grew roughly 1,800 times.

The team first tried the standard advice: rewrite only the slow parts. Rewriting the output-parsing code in Rust and calling it from Python cut CPU usage by about 8 to 10 percent, but it left each token crossing between the two languages three times. The gain did not justify the complexity. The full-rewrite question had been settled emphatically in 2024, when one engineer responded to a suggestion to migrate to Go or Rust with "We are not rewriting the API in go or rust!" By 2026, the calculus had changed. By May, Anthropic says, Claude was writing more than 80 percent of the code the company merged, and Claude produced a first version of the API's core request path in about a week.

Tests Were Not Enough

Verification, not generation, had become the bottleneck. Anthropic had roughly 700 integration tests, but two problems made them unreliable as proof of a correct migration. First, the tests were coupled to the Python implementation, and when Claude helped port them, a "pass" could mean the code was right or that the test had been changed to let wrong code through. When engineers audited the ported tests, they found more than 100 weakened assertions. Second, the tests were incomplete. With dozens of features, just 20 binary options produce more than a million combinations, which Anthropic calculated would take 12 days to run for a single model before varying a single prompt.

The gap between passing tests and matching production was stark. In April the Rust API passed about 98 percent of its tests, yet only about a quarter of inputs matched Python on real production traffic.

Turning Production Into the Verifier

The team's solution was shadowing: running real requests through both versions and comparing the results. That required solving three problems. The Python API kept changing as new models and features shipped, so parity was a moving target. Claude's replies are nondeterministic, so a difference between two outputs did not necessarily indicate a bug. And for privacy reasons, engineers could not read customer requests, so they could not simply look at where the two versions diverged.

Anthropic ran the model once and replayed its output to the Rust version, so both sides worked from identical model output, and compared every stage before and after the model call for an exact match. Because no one could read the text, the system recorded the shape of each difference instead: which step it occurred in, where in the prompt it began, and how far apart the two versions were. Each bug left a recognizable fingerprint, so errors could be grouped and triaged.

Agents in the Loop

Every 10 to 30 minutes a script grouped the difference records and alerted a coordinating Claude agent when it saw a new kind. The coordinator assigned a worker agent to each new record type and opened a Slack thread where human engineers could follow along. Agents worked in a cloud sandbox with both codebases, where an input check that never called the model could compare the two versions in under a second.

Human review remained the gate between the sandbox and production, and Anthropic's account shows why. In mid-May, one of the largest remaining differences came from web search: the Python API fetched the web search tool's description from an internal service that Rust did not yet call. An agent proposed copying the text into files Rust could read. The prompts matched and the fix passed the local verifier, but an engineer rejected it because Rust would still need to call the service before launch and the workaround would be thrown away. The agent had found the cheapest way to satisfy the verifier, not the right fix. The rejection was saved to memory so later agents would not repeat it, and that memory loop also produced lasting rules, including a merge check requiring anyone changing the Python code to make a matching change in Rust or request an exemption.

Anthropic closes with the Ship of Theseus: migrating a live system used to mean replacing planks one at a time while the ship kept sailing, and changing too many at once meant coming into dock. With Claude writing the code and production acting as the verifier, the company argues it is now possible to build an identically functioning ship alongside the first while the first keeps sailing.

---

Stay Ahead of AI

Get the latest AI news, analysis, and breakthroughs — all in one place.

Read more AI news →