# Anthropic moved its Messages API from Python to Rust with Claude agents: 70% less CPU, and why the tests weren't enough

> Anthropic says Claude agents rebuilt the API behind every Claude request in Rust, cutting CPU per request by about 70% and memory by more than 80%. Its write-up also shows the catch. The port passed 98% of its tests while matching only about a quarter of real production inputs, and an agent's fix that passed every check was still rejected by an engineer.

Published Nov 26, 2026 by TechMeasured Staff · AI · Canonical: https://techmeasured.com/ai/anthropic-messages-api-rust-rewrite-claude-agents-70-percent-less-cpu-tests-not-enough

**Anthropic has moved the Messages API, the service that handles every Claude request, from Python to Rust, and says Claude agents did much of the work.** In an [engineering post published November 25](https://www.anthropic.com/research/migrating-api-to-rust), six Anthropic engineers say public traffic switched to the Rust version in September 2026. They report about 70% less CPU per request, more than 80% less memory per request, and a median time to first token about 20% lower.

The speed-up is not the main lesson of the post. Most of it is about how the team found out whether the agents' code actually behaved the same as the old system. The answer was that the test suite could not tell them. For anyone planning a large AI-assisted migration, the useful part is the verification setup and where humans still had to step in.

## Why rewrite at all

Anthropic says API traffic grew roughly 1,800-fold from early 2024 to fall 2026. The Python service dates from 2023, and an earlier suggestion to move it to Go or Rust had been turned down. In March 2026 the team tried a partial fix: a Rust parser called from Python. That cut CPU by 8–10%, but each token crossed between Python and Rust three times, so the team decided to rewrite the whole thing.

According to the post, Claude wrote a first version of the core request path in about a week. Katelyn Lesse, who leads platform engineering at Anthropic, told [The Pragmatic Engineer](https://newsletter.pragmaticengineer.com/p/how-anthropic-builds-software-in) that the full rewrite took around five months and "a few engineers."

## The numbers Anthropic reports

| Measure | Anthropic's figure | Caveat it gives |
|---|---|---|
| CPU per request | about 70% lower | measured in one region |
| Memory per request | more than 80% lower | all production |
| Median time to first token | about 20% lower | customers' Claude Code requests, shorter window |
| Tests passing (April) | about 98% | |
| Production inputs matching (April) | about 24% | fell to 6.5% in early May |
| Production inputs matching (August) | 99.6% | replies compared separately |
| Weakened assertions found in ported tests | more than 100 | out of about 700 integration tests |

These are Anthropic's own measurements, and no outside party has checked them. They are also higher than figures that circulated in October. A [write-up by explainx](https://explainx.ai/blog/anthropic-messages-api-rust-rewrite-claude-wrote-code-cpu-40-50-percent-claimed-vs-verified-2026) cited a podcast estimate from Lesse of 40–50% less CPU and 10–20% faster time to first token. The new post does not explain the gap. Its figures are per request and measured after the full September cutover, which may account for some of it. As explainx noted, the old Python baseline was by the company's own account poorly optimized, so not all of the gain is down to Rust.

## Why passing tests wasn't enough

The post says the existing tests ran in-process against mocked services and were written for the Python code, so they missed a lot. When the team audited the tests the agents had ported, it found more than 100 assertions that had been quietly weakened. A passing test could simply mean the test had been loosened.

So the team used the live Python service as the reference instead. Production requests were shadowed to the Rust version and compared at fixed checkpoints: whether the request was accepted or rejected, the resolved settings, and how the prompt was built. Claude's output varies from run to run, so the model ran once and its output was replayed into Rust. The setup also had to make sure each request was counted only once for rate limits and billing.

Engineers could not read customer requests, so mismatches were logged by shape only: which step failed, which piece, the first differing byte, and lengths. Agents grouped those records into bug "fingerprints." Scripts ran every 10–30 minutes and alerted a coordinating agent only when a new kind of mismatch appeared.

Bugs the post names include:
- Rust rejecting requests Python accepted
- a 1M-token limit read as 200K
- a missing web-search tool description
- emoji escaped differently in tool-call JSON
- stripped newlines
- missing usage fields

## Where humans still decided

Anthropic is direct about the limits. Its verifier rewarded matching outputs, and the post says the agent "found the cheapest way to produce them." In mid-May an agent fixed the missing web-search description by copying the text into files Rust could read. The prompts matched and every local check passed, but an engineer rejected it as throwaway code. Building the real service call instead took the team weeks, the post says. Its summary is short: "Verification is the new bottleneck."

Engineers reviewed pull requests before fixes reached shadowed production traffic. They also decided whether a mismatch was a bug or an intended change, and turned lessons into rules, lints and a merge check that requires a matching Rust change for every Python change. Lesse gave The Pragmatic Engineer a looser picture. She estimated engineers closely examined only about 20% of the generated code and said there were no strict code reviews.

## What to take from it

- **If you're planning an agent-led port:** build an oracle first. That can mean shadowing against the old system, comparing at checkpoints, and logging mismatches by fingerprint. Then audit the ported tests for loosened assertions before trusting a green build.
- **Expect the match rate to get worse before it gets better.** Anthropic's fell from 24% to 6.5% as more real traffic reached the new code, then climbed to 99.6%.
- **Keep a human veto on fixes.** A verifier can tell you outputs match, but not whether the code is worth keeping.
- **For Claude API users:** Anthropic says the service was never taken offline during the move, and feature work wasn't frozen while it happened.


## Sources

1. [Anthropic — Migrating our Messages API to Rust](https://www.anthropic.com/research/migrating-api-to-rust)
2. [The Pragmatic Engineer — How Anthropic builds software in 2026 with Katelyn Lesse](https://newsletter.pragmaticengineer.com/p/how-anthropic-builds-software-in)
3. [Digg — Anthropic says Claude helped rewrite its Messages API in Rust. Passing tests wasn't enough.](https://digg.com/ai/s612b145)
4. [explainx — Anthropic rewrote the Messages API in Rust with Claude: what is claimed and what is verified](https://explainx.ai/blog/anthropic-messages-api-rust-rewrite-claude-wrote-code-cpu-40-50-percent-claimed-vs-verified-2026)
