AI Trends

Anthropic Details Claude-Assisted Migration of the Messages API from Python to Rust

Unite.AIUpdated Nov 26 02:09

AI summary

Anthropic used Claude agents to migrate the Messages API from Python to Rust without interrupting service or freezing feature development, reducing CPU usage per request by approximately 70% and memory usage by more than 80%. Using the production Python service as a reference, the team verified behavioral consistency through traffic replay, difference fingerprinting, and regression testing, with engineers reviewing proposed fixes. The match rate against comparison inputs reached 99.6% by August 2026, and public traffic was migrated to Rust in September 2026.

Why read this

SelectedAI score 79

The migration demonstrates how production traffic can be used to validate an agent-generated replacement implementation, with engineers overseeing the quality of fixes that cannot be evaluated automatically.

Topics

Tags

Body

Anthropic reported on November 25, 2026 that Claude agents helped move its Messages API from Python to Rust without an outage or a freeze on feature development. Per-request CPU and memory use fell about 70% and more than 80%, respectively, while the median wait for the first response token fell about 20% for customers’ Claude Code requests.

Built in Python in 2023, the Messages API is the primary route through which customers and Anthropic apps such as Claude Code and Cowork reach Claude. Anthropic says API traffic grew roughly 1,800 times from early 2024 to fall 2026. By late 2025, Python was adding overhead throughout an expanding sequence of request and response processing each time it created an object, freed memory or handed work to the next task.

An initial rewrite of model-output parsing in Rust cut CPU usage by about 8% to 10%, Anthropic reports, but each token then crossed between Python and Rust three times. The team concluded that the savings did not justify the added overhead and complexity.

Claude wrote a first version of the API’s core request path in about a week, according to Anthropic. The full rewrite covered both the input and output paths around the model. Because the Python service continued changing, generating replacement code was only the start: the team still had to demonstrate behavioral parity with a moving production system.

The Limits of the Test Suite

The existing suite had about 700 integration tests, but those tests were coupled to the Python implementation and covered only a subset of possible feature combinations. Claude helped change both the tests and the code, so a passing result could reflect a weakened check rather than correct behavior; an audit found more than 100 weakened assertions.

The Rust API passed about 98% of its tests in April 2026, Anthropic reports, yet only about a quarter of compared production inputs matched Python. Production traffic also exposed how often a bug actually fired, whereas each test case counts only once. A single common bug could therefore account for many mismatches even when the test suite looked healthy.

Production Traffic as the Verifier

The team made the live Python service its reference, then compared how the two implementations handled the same production requests. Because Claude can respond nondeterministically to identical input, the model ran once and its output was replayed to Rust. The comparisons covered processing on both sides of the model call, including request validation, prompt construction, tokenization, safety classification, output streaming and usage counting. The design also ensured that a request counted only once toward a customer’s usage limits and bill.

To protect customer content, engineers worked without reading requests or Claude’s replies. Instead of storing text, checkpointing located the first processing step or prompt component where the versions diverged. A fingerprint added the first differing position and the length difference, enabling records likely caused by the same bug to be grouped.

A script processed new records every 10 to 30 minutes and alerted a coordinating Claude agent only when it found a new kind. The coordinator assigned worker agents and opened shared Slack threads where engineers could follow and steer their work.

Worker agents ran in cloud sandboxes containing both codebases. Local checks could compare input processing in under a second without calling the model, Anthropic says; a later output check passed scripted replies through both versions using a fake model. Because an agent could see only the fingerprint, it generated its own request or model reply to reproduce the mismatch. Once its edit made the versions agree, it added a regression test that failed on the old code and passed on the fixed code.

Engineers reviewed each proposed pull request before a fix could enter the slower outer loop, which compared shadowed production traffic on deployments with and without the change. Differences that persisted returned to the inner loop.

In mid-May 2026, an agent proposed copying a missing web-search tool description into files. That made the prompts match and satisfied the local verifier, but an engineer rejected the workaround because Rust still needed to call the internal service supplying the description before launch. The episode exposed the limit of the automated signal: it could judge whether outputs matched, while engineers still had to judge whether a fix was durable enough to ship.

A memory loop preserved those judgments. The rejected shortcut became a note explaining the required service call, helping agents link later fingerprints to the known bug rather than devise another workaround. Other review lessons became porting rules, regression tests and lints; a later merge check required any Python change to be mirrored in Rust or receive an exemption.

The post’s chart records the compared-input match rate reaching 99.6% by August 2026, with the qualification that what was compared changed over time, beginning on Anthropic’s own traffic before moving to a wider sample. Public traffic moved to Rust in September 2026.

Agents chose hypotheses, reproduction methods and fixes, while engineers increasingly supplied reviews and the rules and checks around them. The project connects infrastructure efficiency to a broader requirement for agentic development: production behavior must become a signal agents can act on, with human judgment applied to the shipping decisions that signal cannot settle.

Source

Unite.AI