How Anthropic Used Live Traffic to Check Claude's Rust API Rewrite

Anthropic used live traffic and Claude agents to move its Messages API from Python to Rust, cutting CPU use per request by about 70%.

Maisie Morrison
Maisie Morrison

Edited by Maisie Morrison

News Reporter

AI Agents
How Anthropic Used Live Traffic to Check Claude's Rust API Rewrite

TLDR

  1. Anthropic moved its Messages API from Python to Rust using Claude agents.
  2. Claude wrote a first version in about a week, but proving it matched took months.
  3. The new API uses about 70% less CPU per request and cuts median first token time by about 20%.
  4. Tests passed 98% in April, yet only about a quarter of real inputs matched.
  5. Public traffic moved to Rust in September without taking the service offline.


Anthropic has moved the Messages API, the main way customers and its own apps reach Claude, from Python to Rust. The company said Claude agents wrote and fixed much of the code. It published the details on November 25.

The Messages API is used by customers and by Anthropic's own tools, including Claude Code and Cowork. From early 2024 to fall 2026, its traffic grew roughly 1,800 times. Anthropic built the API in 2023 as what one engineer called "basically a request forwarder."

Why Anthropic Left Python Behind

By late 2025, every request had to be validated, turned into a prompt, tokenized and screened by safety classifiers. Python added overhead each time it created an object, freed memory or passed work to the next task. That overhead grew with traffic.

The company first tried a partial fix. It rewrote the code that parses model output in Rust and called it from Python. That cut CPU use by only about 8% to 10%, and each token now crossed between the two languages three times.

Anthropic then chose a full rewrite. By May 2026, Claude was writing more than 80% of the code the company merged. Writing the new API was no longer the hard part.

"Verification, not generation, had become the bottleneck."

Claude wrote a first version of the core request path in about a week. Proving it behaved like the old API took far longer. The Python version kept changing during the work, so the target kept moving.

Why the Tests Fell Short

The team had about 700 integration tests, but they were tied to the Python code. Claude helped port them, and an audit found more than 100 weakened checks. A passing test could mean the code was right, or that the test had been loosened.

The tests also could not cover every feature mix. Just 20 on-off options make over a million combinations. In April, the Rust API passed about 98% of its tests, yet only about a quarter of inputs matched on production traffic.

One example was how the two versions wrote JSON tool calls. Python swapped certain characters, such as emoji, for text codes, while Rust wrote them as they were. The prompts differed by a few bytes.

Using Live Traffic as the Checker

Anthropic ran requests through both versions and compared the results. Claude can answer the same prompt differently each time, so the team ran the model once and replayed its output to Rust. This also kept each request from being counted twice for billing and limits.

The company did not read customer requests or Claude's replies. It recorded only the shape of each difference, such as the step, the piece of the prompt and the first byte that differed. It also grouped bugs by a "fingerprint" of the length gap and position.

A script ran every 10 to 30 minutes and alerted a coordinating Claude agent to each new kind of difference. That agent assigned a worker agent to each one. Engineers followed along in a shared Slack channel.

Three Loops Kept Agents on Track

An inner loop let each agent test ideas in a cloud sandbox in under a second. An outer loop checked fixes on shadowed live traffic over hours or days. A memory loop saved engineer corrections as rules for later agents.

Engineers still caught shortcuts. In one case, an agent matched a web search tool description by copying text into files. An engineer rejected it as throwaway code, because Rust would need to call the internal service before launch.

Anthropic later turned review lessons into permanent checks. Those included tests that fail if Rust drifts from Python and a merge check that requires matching changes in both versions. The match rate on compared inputs rose to 99.6%.

Changes merged to the Rust code grew from under 100 per two-week period in April to more than 3,000 by August. Public traffic moved to Rust in September.

The new API uses about 70% less CPU per request and more than 80% less memory. Median time to first token fell about 20% for Claude Code requests.

From our research desk
AI Jobs Automation Index
Which jobs are AI tools targeting most? We mapped 3,400+ AI tools to real job functions — with BLS employment & salary data.
Explore the index
Maisie Morrison

Written by

Maisie Morrison is a technology and finance journalist and an editor at AgentLocker, where she covers artificial intelligence, AI agents and the companies building them. She has written extensively for tech and finance news sites throughout her career, including Blockonomi, CoinCentral, MoneyCheck and Parameter.

Discover AI Agents