Anthropic moves Claude's API from Python to Rust, cutting CPU use 70%
In short
- What it is: the Messages API is the service that takes a customer's request, hands it to Claude and streams the reply back. Anthropic's engineering team says it moved this service from Python to Rust, a faster programming language, in a post dated 25 November 2026.
- The hard part: checking that the new version behaves exactly like the old one. Claude's replies differ from run to run, the Python API kept changing during the move, and Anthropic could not read customer requests.
- How they checked: they compared the two versions on live traffic, recorded only the shape of each difference, and had Claude agents fix the differences, with engineers reviewing each fix.
- The result, Anthropic's own measurement: about 70% less CPU per request and about 20% lower median time to first token, with no downtime and no freeze on new features.
~1,800x API traffic growth, early 2024 to fall 2026; ~70% less CPU per request on Rust; ~20% lower median time to first token; ~25% inputs matching on live traffic in April; ~98% tests passing in April
Why move at all
Anthropic built the Messages API in 2023 in Python, which its research teams already used. At first it was, in one engineer's words, "basically a request forwarder". By late 2025 every request had to be validated, turned into a prompt, split into tokens and screened by safety classifiers. Anthropic says Python added overhead at each step, and traffic had grown roughly 1,800 times from early 2024 to fall 2026.
The team first rewrote only the code that parses a model's 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 judged the gain not worth the complexity.
What changed was the cost of writing code. The post says Claude wrote more than 80% of the code Anthropic merged by May 2026, and that Claude wrote a first version of the API's core request path in about a week. The bottleneck had moved: writing the Rust was quick, but proving it matched the Python was not.
Why the usual checks were not enough
Tests. The team had about 700 integration tests. They were tied to the Python code, so they had to be rewritten for Rust, and Claude helped with that. A pass could then mean the code was right or that the test had been loosened. An audit of the ported tests found more than 100 weakened assertions.
Live traffic. Anthropic's Rust API passed about 98% of its tests in April, yet only about a quarter of inputs matched Python's on production traffic. One example: Python writes an emoji in a tool call as a text code, while Rust wrote it as is, so the prompts differed by a few bytes. In live traffic one common bug shows up in every request that triggers it.
Running the same request through old and new code is called shadowing. Anthropic could not use the standard tools, for three reasons given in the post:
- a request must count only once toward a customer's limits and bill;
- Claude can answer the same input differently, so a different reply does not prove a bug;
- Anthropic could not read customer requests, so it could not easily see where the two versions diverged.
Its answers: run the model once and replay that output to Rust, then compare every step before and after the model call. To see where the versions differed without reading any text, it recorded two things:
- Checkpoints: the first step or prompt piece where the two versions differ.
- Fingerprints: where in the prompt the difference starts and how many bytes it adds or removes. One bug tends to leave the same fingerprint on every request it touches, so bugs can be grouped.
Three loops of agents
One bug could produce hundreds of thousands of near-identical records. A script ran every 10 to 30 minutes, grouped them, and alerted a coordinating Claude agent only for a new kind of record. That agent gave each new kind to a worker agent and opened a Slack thread where engineers could follow and steer.
April 2026: Agents guess a cause from each difference record and open a pull request; feedback takes hours or days. Rust passes about 98% of tests but only about a quarter of production inputs match. Mid-May 2026: An agent patches a missing web search tool description by copying the text into files Rust can read. The prompts match, but an engineer rejects it: Rust must call the internal service before launch. June 2026: An agent groups about 60 review comments into proposed rules, which an engineer edits and approves for the team's CLAUDE.md file. September 2026: Public traffic moves to Rust.
The loops, in order:
- Inner loop: each agent works in a cloud sandbox with both codebases and fast local checks. The input check builds each version's prompt without calling the model, so it takes under a second.
- Outer loop: after engineer review, a fix is deployed and agents check how often its fingerprint appears on builds with and without it. If it persists, the task goes back to the inner loop.
- Memory loop: corrections become rules for later agents, searches for the same mistake, and tests.
The web search case shows why people stayed in the loop: the verifier rewarded matching outputs, and the agent found the cheapest way to match. As the post puts it, a verifier cannot say whether a fix is good enough to ship.
The memory loop saved the reasoning behind that rejection, so later records were linked to the known bug instead of getting new workarounds. A rule to port exactly what Python did led an agent to find seven more places where the port had relied on a guess. Anthropic also added a merge check that makes anyone changing the Python code make a matching Rust change or ask for an exemption.
What changed in production
Anthropic's Figure 15 tracks CPU and memory per request and median time to first token as requests moved from Python to Rust. The post's text gives two numbers.
These are Anthropic's own measurements on its own system, and the caption says memory is measured across all of production. We found no outside test.
The generator–verifier gap
The post opens with an idea it calls the generator–verifier gap: it is often far easier to check a solution than to find one. Sudoku is the example: checking a grid is quick, finding the solution can take long. Claude can take on big projects when it has a reliable check, such as a proof assistant for maths.
A live system has no such check, because users depend on quirks that no test suite lists. Anthropic's answer was to make the production API itself the checker. Its main lesson: verification, not writing code, is now the bottleneck.
Terms in plain English
- Rust, Python: two programming languages. Rust compiles to fast machine code and manages memory itself; Python is easier to write but slower for this kind of work (our wording).
- Token: a small chunk of text a model reads or writes, so a reply streams out one token at a time.
- Time to first token: the wait before the first part of a reply arrives.
- Shadowing: sending the same live request to the old and new versions and comparing what each does.
- Fingerprint: Anthropic's name for a short record of where and by how much two versions differ, without showing any text.
Where things stand
The post says public traffic moved to Rust in September 2026. It closes by saying that migrating production systems with Claude is increasingly feasible, and that the open question is how to build enough confidence that the new system behaves like the old. It does not give a dollar saving, the size of the codebase or the number of bugs found, and the CPU and speed figures are Anthropic's own.
Sources
- Migrating our Messages API to Rust, Anthropic Engineering, 25 November 2026
Sources
More from AI Research Labs
- NVIDIA announces Nemotron 4 open models, Super due early 2027
- NVIDIA introduces cuPlasma, a GPU library for fusion plasma simulation
- NVIDIA releases CodonFM 5B, an open 5-billion-parameter mRNA model
- Cursor is now Grok Build, the AI coding app of SpaceX's Grok team
- Belfort Labs releases Bel-0, an AI chatbot that works on encrypted prompts