Skip to content
Anthropic — AI — News

Anthropic Moves Claude’s Messages API to Rust, Cutting CPU Use by About 70%

Claude agents helped rebuild the service while engineers used live traffic to verify that the new code matched production.

Table of Contents

Anthropic has moved Claude's Messages API from Python to Rust, reducing CPU use per request by about 70% while keeping the service online and continuing feature development. The migration rebuilt the software that prepares requests for Claude and processes its replies, with teams of Claude agents helping find and repair differences between the two implementations.

The Messages API is the main route through which customers, Claude Code, and Cowork reach Claude. Public traffic moved to Rust in September 2026. Anthropic detailed the migration in an engineering report and announced the results on X.

Claude produced a first version of the core request path in about a week. Establishing that it behaved like the existing service took considerably more work. Engineers turned the production Python API into a reference system, then built verification tools that let agents investigate mismatches without reading customer requests or replies.

Why a Partial Rust Rewrite Was Not Enough

When Anthropic built the Messages API in 2023, its job was largely to pass requests to a model and return the output. By late 2025, each request required validation, prompt construction, tokenization, and safety screening. On the way back, the service had to separate a stream of tokens into text, thinking, and tool calls while tracking usage for billing and rate limits.

Python added overhead as it created objects, released memory, and passed work between tasks. Meanwhile, API traffic grew roughly 1,800-fold from early 2024 to fall 2026. The traffic measure includes Anthropic's own use of its platform.

Monthly average of API requests per day, Jan 2024 to Oct 2026
Monthly average of API requests per day, Jan 2024 to Oct 2026 | Anthropic

Moving the entire service was complicated by shared dependencies with Python libraries maintained by research and inference teams. A rewrite also meant rebuilding supporting infrastructure, including logging, metrics, and tools.

Anthropic first tried a narrower change: rewriting the model-output parser in Rust and calling it from Python. That reduced CPU usage by about 8% to 10%, but each reply token now crossed the Python–Rust boundary three times. The team judged the savings insufficient for the added complexity and pursued a full migration of the request path around the model.

After the incremental rewrite, each token crossed between Python and Rust three times
After the incremental rewrite, each token crossed between Python and Rust three times | Anthropic

AI-assisted development changed the effort involved. Anthropic reports that, by May 2026, Claude was writing more than 80% of the code the company merged. The central engineering problem for this project became checking the replacement rather than generating it, especially while the Python service continued acquiring new features.

Tests Passed, but Production Behaved Differently

Software migrations can be checked against explicit rules, a shared test suite, or an existing implementation. Anthropic used its running Python service as the reference because its integration tests could not independently establish that the Rust version preserved production behavior.

Three common sources of correctness
Three common sources of correctness | Anthropic

The team already had about 700 integration tests, but they ran the Python API inside the test process and mocked services such as billing and rate limiting in Python's memory. Those tests had to be ported alongside the implementation, with Claude helping change both. An audit found more than 100 weakened assertions in the ported tests, allowing some differences to pass unnoticed.

Coverage posed a separate problem. Just 20 on-or-off options create more than a million combinations, before varying models or prompt contents. A test suite samples that space rather than reproducing every combination customers actually use.

A ported test may check less than the original, and tests cover only combinations someone thought of
A ported test may check less than the original, and tests cover only combinations someone thought of | Anthropic

In April, the Rust implementation passed about 98% of its tests, yet only about a quarter of inputs matched when compared against production. One subtle cause was JSON formatting: Python escaped certain characters, including emoji in tool calls, while Rust emitted them directly. The resulting prompts differed by a few bytes even when both versions accepted the request.

Anthropic's input-matching chart begins near 24%, falls to 6.5% in early May, and eventually reaches 99.6%. The comparison began with internal traffic before expanding to a wider sample; its scope changed over time, and six misleading days were excluded. Replies were checked separately.

Share of inputs that matched, late April to August
Share of inputs that matched, late April to August | Anthropic

Comparing Live Traffic Without Reading Customer Content

The team used shadowing: passing production requests through old and new code and comparing their behavior. Running Claude independently through both paths would not work, because the model can produce different replies to identical inputs. It also risked counting requests twice toward customer limits and billing.

Instead, Anthropic ran the model once and replayed its output to Rust. Engineers compared the processing stages before and after that model call, allowing them to isolate changes in the API rather than differences generated by Claude itself.

The checks needed to be exact. A malformed request might trigger an obvious error, but an altered prompt could still produce a plausible answer. Merely checking that both implementations returned successful responses would miss those changes.

Comparing at checkpoints
Comparing at checkpoints | Anthropic

To protect customer privacy, engineers recorded the structure of a mismatch rather than its text. Checkpoints identified the first processing step that differed, then narrowed it to a piece of the prompt. A record could show that the two pieces were each 190 bytes long but first diverged at byte 17, without revealing either piece's contents.

Those positions and length differences helped form a fingerprint for each bug. Grouping records by fingerprint let the team distinguish recurring problems instead of treating every affected request as a separate investigation. Fixing an early difference could also expose other mismatches farther along the prompt.

Fingerprints from one kind of request
Fingerprints from one kind of request | Anthropic

A script grouped records every 10 to 30 minutes and alerted a coordinating Claude agent when a new kind appeared. The coordinator assigned a worker agent to investigate and opened a Slack thread where engineers could follow the work and intervene.

How Agents Tested Fixes and Engineers Controlled Deployment

Anthropic organized the work into three linked processes: a fast sandbox loop for reproducing and fixing differences, a slower production loop for checking deployed changes, and a memory loop that carried lessons into later investigations.

Verification loops
Verification loops | Anthropic

Each worker ran in a cloud sandbox containing both codebases. Because it could not inspect the customer request behind a fingerprint, it hypothesized a cause and wrote a synthetic request or reply to reproduce it. The agent could read these self-generated examples in full.

The local input check compared the prompts both implementations would build without calling the model, taking less than a second. An output check used a fake model with a scripted reply. Once an agent reproduced the recorded difference, it edited Rust until the versions matched and added a regression test.

Inner loop
Inner loop | Anthropic

Human review separated experimentation from deployment. That gate caught fixes that satisfied the comparison but did not meet engineering requirements. In one case, Rust was missing a web search tool description that Python fetched from an internal service. An agent copied the description into text files, making the prompts match, but an engineer rejected the workaround because Rust still needed the service integration before launch.

Agents trace a web search mismatch across Slack threads and an engineer rejects the proposed fix
Agents trace a web search mismatch across Slack threads and an engineer rejects the proposed fix | Anthropic

After review and deployment, agents checked whether a fingerprint disappeared from shadowed traffic. They compared requests using the same models and API features, such as prompt caching, tools, or extended thinking, without logging their text. If a difference persisted, the investigation returned to the sandbox. Local checks were fast, but production could expose configurations those checks missed.

Outer loop
Outer loop | Anthropic

The memory loop preserved review decisions so later agents would not repeat rejected approaches. While engineers built the web search integration, agents used a saved note to recognize related fingerprints as the same known problem rather than propose more workarounds.

Other corrections became general porting rules, tests, and lints. After an engineer required agents to reproduce Python's actual behavior rather than guess, an agent found seven more places with the same mistake. A later merge check required Python changes to have matching Rust changes or an exemption, helping keep both implementations aligned during ongoing development.

Memory loop
Memory loop | Anthropic

Anthropic's performance measurements show about 70% lower CPU use per request in one region and more than 80% lower memory use per request across production. Median time to first token, the wait before a response starts arriving, fell about 20% for customers' Claude Code requests over a shorter measurement period.

CPU, memory and median time to first token as requests moved from Python to Rust
CPU, memory and median time to first token as requests moved from Python to Rust | Anthropic

Development activity also increased during the migration. Changes merged into the API's Rust code rose from fewer than 100 per two-week period in April to roughly 1,000 by late June and more than 3,000 in the period beginning August 10. That count includes work beyond the migration.

Changes merged to the Rust code per two-week period
Changes merged to the Rust code per two-week period | Anthropic

As the system matured, engineers spent less time chasing individual differences and more time defining rules, improving checks, and reviewing proposed fixes. Agents handled hypothesis testing and reproduction within those boundaries, while production comparisons determined whether the changes actually removed the mismatches.

Comments

Latest