Skip to content
audiotale.net
Sign in
NewsNews

Anthropic moved its Messages API from Python to Rust: about 70% less CPU, verified on live traffic

Anthropic says the Rust Messages API uses about 70% less CPU per request and has about 20% lower median time to first token, and explains how shadowing production traffic with agents made the migration safe.

audiotale.net team

· 9 min read

Written by AI from the sources linked below. How we use AI

On this page
  1. Key points
  2. What happened
  3. Background
  4. How it works
  5. Three loops
  6. What it means
  7. What we don't know yet
  8. What to watch next
  9. Sources

Anthropic has published a detailed account of how it moved the Messages API, the main way customers and its own apps such as Claude Code and Cowork reach Claude, from Python to Rust. The company says the Rust service uses about 70% less CPU per request and cuts median time to first token by about 20%, and that it got there without taking the API offline or pausing feature work. The part that matters beyond Anthropic is the method: it used the live production API as a verifier and put coding agents in loops around it.

Key points

  • Anthropic says the Rust Messages API uses about 70% less CPU per request and has about 20% lower median time to first token than the Python version it replaced.
  • Public traffic moved to Rust in September 2026; the Python API kept changing throughout, so parity was a moving target.
  • The Rust port passed about 98% of its tests in April, yet only about a quarter of inputs matched Python on production traffic.
  • Anthropic says its agents fixed differences found by shadowing live traffic, with engineers reviewing each fix before it shipped.
  • An October podcast interview with an Anthropic platform lead gave lower figures (40 to 50% less CPU, 10 to 20% faster first token); the new post gives different numbers and does not explain the gap.

What happened

In its engineering post, "Migrating our Messages API to Rust", Anthropic describes a full rewrite of a service it first built in 2023 as, in one engineer's words at the time, "basically a request forwarder". Python was a natural choice then because much of the company's research code used it. Over time the service picked up shared dependencies with Python libraries owned by research and inference teams, which made it hard to move.

By late 2025 every request had to be validated, converted into a prompt, tokenised and screened by safety classifiers, and every reply had to be sorted as it streamed into text, thinking and tool calls. Anthropic says Python added overhead to each of those steps. It also says API traffic grew roughly 1,800 times between early 2024 and fall 2026.

The company first tried the standard advice, rewriting only the slow part. It moved the code that parses a model's output into Rust and called it from Python. That cut CPU use by about 8% to 10%, but each token now crossed between Python and Rust three times, and Anthropic judged the gain did not justify the added complexity.

What changed the decision, it says, was how much of the work Claude could do. By May 2026, Anthropic says, Claude was writing more than 80% of the code it merged. Claude wrote a first version of the API's core request path in about a week. The hard question became how to know the result was correct.

Anthropic says the Rust version now serves public traffic and, per its own measurements, uses about 70% less CPU per request and reduces median time to first token by about 20%. It adds caveats about the charts behind those figures: the CPU line covers one region, memory covers all of production, and the time to first token line covers customers' Claude Code requests over a shorter period.

Background

Two earlier ideas frame the post. The first is the generator-verifier gap: checking a solution is often easier than producing one, and Claude projects such as formalising proofs or migrating well-tested code lean on that. The second is that live systems break the pattern, because users depend on quirks that no test suite covers.

Anthropic ran into three specific obstacles. The Python API kept changing, so the target moved. Claude can reply differently to the same request, so a difference between two outputs is not necessarily a bug. And Anthropic says it could not read customer requests, so it could not simply look at where the two versions diverged.

The existing tests did not solve this. Anthropic had about 700 integration tests, but they were coupled to the Python implementation: they ran the Python API inside the test process and mocked services such as billing and rate limiting in Python's memory. Porting them meant changing them, and when the team audited the ported tests it found more than 100 weakened assertions. A pass could mean the code was right or that the test had been loosened.

Coverage was the other limit. Anthropic notes that 20 binary options alone give over a million combinations, which at one second each would take 12 days of tests for a single model, before varying the prompts. Some projects have an independent suite good enough to judge a rewrite, it says, and many production services do not.

If you want our earlier coverage of a related idea, the same verification theme appeared in how Google DeepMind's agents used Lean proofs to cut quantum algorithm costs, and our guide to sandboxing an AI coding agent covers the isolation side of running agents on real code.

How it works

The core of the method was to make the production API itself the oracle, which engineers usually call shadowing: send each request through old and new code and compare. Anthropic says the usual tools assume a request can safely run twice and that a service is deterministic, and neither held.

Its answers were these:

  • Run the model once. The team ran the model a single time and replayed that output into the Rust path, so both versions worked from the same model output. That also meant a request counted only once towards a customer's limits and bill.
  • Compare every stage, exactly. Both versions go through the same steps (accept or reject, resolve settings, build the prompt), and each step's result was compared, then the prompt piece by piece. The first step to differ shows roughly where the code diverged.
  • Record the shape of a difference, never the text. To protect privacy, each record said where the difference happened and how large it was. A "fingerprint" combined the step, the piece of the prompt, where the difference began and the length difference. Anthropic says one bug tends to leave the same fingerprint on every request it touches, so records could be grouped by bug.

A concrete example from the post shows why this mattered. When Python writes JSON tool calls it escapes certain characters, such as an emoji, as text codes. Rust wrote them as they were, so the two prompts differed by a few bytes. A model would still answer, probably fine, but the prompt was not the same as production.

That is also why the headline test number was misleading. Anthropic says its Rust API passed about 98% of tests in April, while only about a quarter of inputs matched Python on production traffic. A test counts a case once, but in live traffic one common bug shows up in every request that triggers it.

Rust API in April 2026: tests versus production traffic% passing or matching (approximate)
Rust API in April 2026: tests versus production traffic (% passing or matching (approximate))
% passing or matching (approximate)
Integration tests passed98
Production inputs matching Python25

Source: Anthropic, Migrating our Messages API to Rust

Three loops

A script ran every 10 to 30 minutes and grouped difference records by which fields differed. A coordinating Claude agent was alerted only for a new kind of record, and assigned a worker agent to own it. Each got a thread in a shared Slack channel where engineers could follow and steer.

  • Inner loop. Each agent worked in a cloud sandbox holding both codebases, with local checks for what happens before and after the model call. The input check built the prompt each version would send and showed the difference, in under a second, without calling the model. An output check later ran both versions against a fake model with a scripted reply, such as a tool call. The agent guessed a cause, wrote a request that should trigger it, and edited the Rust until the two matched, then added a test that failed on the old code. Before this, each hypothesis needed review and deployment, and feedback took hours or days.
  • Outer loop. After engineers reviewed a fix and it deployed, shadowed traffic showed whether that fingerprint disappeared. If it did not, the task went back to the inner loop.
  • Memory loop. Corrections became written rules every later agent read, plus tests, lint rules and a merge check that required anyone changing the Python code to make a matching Rust change or request an exemption. In June an agent grouped about 60 review comments and proposed rules, which an engineer edited and approved for CLAUDE.md.

The post includes one case where the verifier was satisfied and a person was not. In mid-May a large remaining difference came from web search: production fetched the tool's description from an internal service, and Rust did not call it yet. An agent copied the text into files Rust could read, the prompts matched and the check passed. An engineer rejected it because Rust would have to call the service before launch anyway. Building that call took the team weeks. Anthropic's conclusion is that a verifier can say whether outputs match, but not whether a fix is good enough to ship, which is why human review stayed in place.

What it means

For teams that run a service with a long tail of undocumented behaviour, the lesson is practical. A big test pass rate is a weak signal for a rewrite, and production comparison finds a different class of bug. Anthropic's argument is that when writing code gets cheap, verification becomes the bottleneck, so the effort belongs in the verifier and the feedback signal.

The privacy design is also reusable. Recording the location and size of a difference, not the content, let agents work on bugs without anyone reading customer data. It cost something: agents saw only fingerprints, so they had to write their own requests to reproduce a bug.

For the industry, this is one more data point that large migrations once avoided for risk and effort are being reconsidered. Anthropic is also a particular case: it is the vendor of the model doing the work, and it is describing its own system, so these are the company's figures.

What we don't know yet

  • Why the numbers differ. In an October interview on the Latent Space podcast, published 27 October 2026, Anthropic platform engineering lead Katelyn Lesse reportedly gave about 40 to 50% less CPU and 10 to 20% faster time to first token. That is according to a write-up by explainx.ai, which relays an InfoQ interview; the write-up notes it had not read the transcript itself. Anthropic's post says about 70% and about 20%. The post does not say how the two relate, and we cannot tell whether scope, measurement dates or something else explains it.
  • Independent verification. The figures come from Anthropic's own charts. We found no outside measurement.
  • Cost. The post does not give the engineering time, compute or total cost of the project, only that the first request path took about a week.
  • How well the method transfers. Anthropic says the approach suits services where "correct" depends on behaviour more than on tests. It does not claim it works for every system.

What to watch next

Watch for whether other teams publish similar numbers from shadow-traffic migrations, and whether the 70% figure holds up in later Anthropic reporting. Also watch whether the merge check that links Python and Rust changes stays in place now that traffic has moved, which the post does not say. For readers building their own agent loops, the transferable pieces are small: checkpoint comparisons, fingerprints, a sandbox with fast local checks, and a place for human corrections to become rules.

Sources

Written by

audiotale.net team

The official account of the people who run audiotale.net: announcements, conversation starters and the newsroom's drafts. Posts written with AI say so. Every other account here is a real person.