Sulat.com / Writing on AIThursday, November 26, 2026
Agent Engineering/26 November 2026

Anthropic ported its Messages API to Rust, using live traffic to check Claude’s work

Anthropic says its Messages API now runs on Rust, with about 70% less CPU per request and a 20% lower median time to first token. Here's how it checked Claude's port, and how Cloudflare, Discord and Bun compare.

A glossy 3D Anthropic logo on a rusted steel dock with a cast-metal gear, two identical cargo ships behind it in a harbour at golden hour

At a glance

  • Anthropic says its Messages API, the route customers and its own Claude Code and Cowork apps use to reach Claude, now runs on Rust and uses about 70% less CPU per request.
  • Anthropic says the Rust port passed about 98% of its tests in April while only about a quarter of live inputs matched the Python API, so it turned the production API into the checker.
  • Anthropic ran the model once and replayed the reply to Rust, then compared every step before and after the model call, recording only the shape of each difference because it couldn't read customer requests.
  • Anthropic says agents fixed differences in three loops, a sandbox check in under a second, a production check on shadowed traffic, and a memory of rules, with engineers reviewing every fix before it shipped.
  • Anthropic says an engineer rejected one agent fix that made outputs match by copying text, because a verifier can say whether outputs match but not whether a fix is good enough to ship.

Anthropic says its Messages API, the route customers and its own Claude Code and Cowork apps use to reach Claude, now runs on Rust instead of Python. In an engineering post published on 25 November (US), the company reports about 70% less CPU per request and a median time to first token, the wait before the first word of a reply appears, that’s about 20% lower. It says it got there without taking the service offline or freezing feature development.

The reusable part is how Anthropic checked the port. Claude wrote a first version of the core request path in about a week, the company says, but trusting it took much longer. Anthropic ran the live Python API beside the Rust one, compared every step on production traffic, and sent agents after each difference. I covered the wider move in why Bun, GitHub, Ubuntu and Cloudflare moved to Rust; this one comes from the company that builds the model the API serves.

Anthropic’s post of 25 November linking its engineering write-up on the migration.

1,800x

API traffic growth, early 2024 to fall 2026

98%

of tests passed in April

99.6%

of live inputs matched by August

Why Anthropic moved

Anthropic built the Messages API in 2023 in Python, which its research teams already used. One engineer at the time called it “basically a request forwarder”, the post says. It then picked up shared dependencies on Python libraries owned by the research and inference teams, so a change of language meant rebuilding logging, metrics and tooling.

By late 2025 every request had to be validated, turned into the 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 at each of those steps, and traffic had grown roughly 1,800 times since early 2024.

We are not rewriting the API in go or rust!

An Anthropic engineer in 2024, as quoted in Anthropic’s post

Anthropic’s first answer was the standard one: rewrite only the slow part. In March 2026 it rewrote the code that parses a model’s output in Rust and called it from Python, which cut CPU use by about 8% to 10%. Each token then crossed between the two languages three times, and the company judged the gain too small for the added complexity.

What changed its mind was the cost of writing code. By May 2026 Claude was writing more than 80% of the code Anthropic merged, the company says, so a full rewrite no longer needed years of engineer time. Checking the result, not producing it, became the hard part.

Why 98% of tests passing wasn’t enough

Anthropic started with about 700 existing integration tests and found two problems. They ran the Python API inside the test’s own process and mocked services such as billing and rate limiting in Python’s memory, so the tests had to change along with the code, and Claude helped change both. An audit of the ported tests turned up more than 100 weakened assertions, which meant a pass could show the code was right or that the test had been loosened.

The tests were also incomplete. The Messages API has dozens of features, and Anthropic says 20 on/off options alone make over a million combinations, or 12 days of tests at one second each for a single model.

The gap showed up fast. The Rust API passed about 98% of its tests in April, yet only about a quarter of inputs matched Python on production traffic. Anthropic’s chart has the match rate starting at 24%, dropping to 6.5% in early May and reaching 99.6% by August; the comparison began on Anthropic’s own traffic and moved to a wider sample.

Anthropic Messages API Rust port: 98% of tests passed in April, but only 25% of live inputs matched the Python API
The Rust port passed about 98% of its tests in April, yet only about a quarter of production inputs matched Python.

Production traffic exposed cases the tests never covered. When Python writes JSON tool calls, it replaces certain characters, an emoji for example, with text codes; Rust wrote them as they were, so the two prompts differed by a few bytes. Production also weights bugs differently. A test counts a bug once, but live traffic counts it in every request that triggers it, so one common bug can cause a huge number of mismatches.

How the live API became the checker

Running requests through old and new code and comparing the results is called shadowing. Anthropic says the usual shadowing tools assume a request can safely run twice and that the service gives the same answer each time. Neither holds for the Messages API: a request must count once toward a customer’s limits and bill, and Claude can reply differently to the same input.

So Anthropic ran the model once and replayed its output to Rust, then compared every stage before and after the model call. That matters because Claude accepts almost any prompt. A small deviation doesn’t cause an error; it quietly changes the reply.

Anthropic's shadow test runs the model once, replays the reply to the Rust API, then compares every step before and after the model call
The model runs once per request, and Rust gets the same reply replayed, so nobody is billed twice.

Anthropic says it couldn’t read customer requests or Claude’s replies, so it recorded the shape of each difference instead. Two techniques did the work.

  • Checkpointing. Both versions handle a request in the same steps: accept or reject it, resolve its settings, build the prompt. Anthropic compared the result of each step, and the prompt piece by piece. The first place they differ shows roughly where the Rust code departs from production.
  • Fingerprints. Anthropic recorded where in the prompt a difference starts and how far the lengths differ. One bug tends to leave the same fingerprint on every request it affects, so hundreds of thousands of near-identical records collapse into one bug. Fixing the biggest fingerprint can reveal older ones hiding behind it.

The output of that system is a small record with no customer text in it. Here’s Anthropic’s example, which it says uses made-up values:

Code
step:        build prompt     ← where in the code
piece:       2                ← where in the prompt
first diff:  byte 17          ← fingerprint
python:      190 bytes        ← fingerprint
rust:        190 bytes        ← fingerprint

Three loops of agents

A single bug could produce hundreds of thousands of records, so Anthropic didn’t send each one to an agent. A script ran every 10 to 30 minutes, grouped records by which fields differed, and alerted a coordinating Claude agent only when it saw a new kind. The coordinator gave each new kind to a worker agent and opened a thread in a shared Slack channel where engineers could follow along and steer.

The inner loop is the fast one. In April, agents guessed a root cause from a record, opened a pull request and waited for a deployment to staging, so feedback took hours or days. Anthropic moved them into cloud sandboxes holding both codebases, with local checks. The input check builds the prompt each version would send and shows the difference without calling the model, so it takes under a second. Anthropic later added an output check that runs both versions against a fake model with a scripted reply, such as a tool call.

Because agents only saw fingerprints, each one wrote its own request to try to reproduce a difference. If both versions matched, the guess was wrong. If they differed the way the record said, the agent edited the Rust until they matched and added a test that failed on the old code. Fixes crossed into the next loop only after human review of the pull request.

The outer loop is the slow one. Once a fix was deployed, shadowed live traffic showed whether its fingerprint disappeared. Anthropic logged non-text facts about each request, such as the model and features used (prompt caching, tools, extended thinking), so agents could compare requests of the same kind on builds with and without the fix.

Three nested loops in Anthropic's Rust migration: sandbox checks in seconds, production traffic in days, and memory rules for every agent
Each loop catches what the one inside it misses: sandbox, then production traffic, then saved rules.

The memory loop is where the lessons stuck. In mid-May one of the largest remaining differences came from web search. Production fetched the search tool’s description from an internal service that Rust didn’t call yet, so the text was missing from prompts. An agent copied the text into files Rust could read, the prompts matched and the local check passed. An engineer rejected the fix: Rust would have to call the service before launch, and the shortcut would be thrown away.

Anthropic’s reading is that the verifier rewarded matching outputs, and the agent found the cheapest way to produce them. The agent saved a note in memory with the decision and the right fix. Building that service call took weeks; in the meantime, other agents recognised related records, some with new fingerprints, and linked them to the known bug instead of writing another workaround.

Other corrections became rules. After an agent guessed at Python’s behaviour, an engineer made it a rule to port exactly what Python did, and an agent then found seven more places where the port had relied on a guess. In June an agent grouped about 60 review comments into proposed rules, which an engineer edited and approved for CLAUDE.md. Some lessons became permanent checks: tests that fail when Rust drifts from Python, lints that ban patterns reviewers kept flagging, and a merge check that makes anyone changing the Python code make a matching Rust change or ask for an exemption.

What changed in production

MeasureAnthropic’s reported changeScope Anthropic gives
CPU per requestAbout 70% lowerOne region, August to October
Memory per requestMore than 80% lowerAll of production, August to October
Median time to first tokenAbout 20% lowerCustomers’ Claude Code requests, roughly 7 to 21 September
Anthropic’s charts index each measure to 100 at the level just before the move, so the post gives relative changes, not absolute CPU or cost.

Public traffic moved to Rust in September 2026. Anthropic says the fall in first-token time before the chart’s first marker came while almost all of those requests were still on Python. Merged changes to the Rust code rose from under 100 per two weeks in April to roughly 1,000 by late June, then to more than 3,000 in the fortnight starting 10 August, though Anthropic says not all of that is migration work.

Anthropic says its Rust Messages API uses about 70% less CPU per request and cuts median time to first token by about 20%
Anthropic reports about 70% less CPU per request and about 20% faster median first token on Rust.

How it compares with other Rust moves

Anthropic isn’t the first company to move a hot service to Rust, and the reasons differ. Each figure below is the company’s own.

ProjectThe moveReported resultWhat the source credits
Anthropic Messages APIPython to Rust; public traffic moved September 2026About 70% less CPU per request; median first token about 20% lowerLess per-request overhead, checked on shadowed live traffic
Cloudflare PingoraNGINX and Lua proxy to Rust, September 2022About 70% less CPU and 67% less memory; over 1 trillion requests a daySharing connections across threads, so fewer new connections
Cloudflare FL2FL1, built on NGINX and LuaJIT, to Rust, September 2025Less than half the CPU, much less than half the memory, sites 10 ms faster at the medianOne codebase, with each request running only the modules it needs
Discord Read StatesGo to Rust, February 2020Go’s garbage collector caused latency spikes about every two minutes; cache raised to 8 million Read StatesNo garbage collector
BunZig to Rust in 11 days, about US$165,000 at API pricing128 bugs fixed that reproduced in Bun 1.3.14, per Jarred SumnerThe existing test suite as judge
GitHub Copilot runtimeTypeScript on Node to Rust in 14.5 weeksOne turn 18 times faster; memory for ten clients down 91%, per Stephen ToubAn embeddable runtime, with end-to-end tests
Six Rust moves, six different reasons: CPU, memory, garbage collection and embedding.

What sets Anthropic’s account apart is the checker. Discord’s 2020 launch relied on load testing and a single canary node, where it found a few missing edge cases before rolling out to the fleet. Bun had a test suite written in TypeScript that could judge both versions; Anthropic cites Bun’s move as the example, and Sumner has disclosed that Anthropic acquired Bun in December 2025. Anthropic had about 700 tests tied to its Python code, so it made production the oracle. It also says the common shadowing tools, GitHub’s Scientist and Twitter’s Diffy among them, didn’t fit a service that bills each request once and answers differently each time.

Anthropic’s examples of differences include a rejected field, a 1M limit read as 200K, a missing tool description, stripped newlines and missing usage fields. Those are logic gaps, not memory bugs, and Microsoft’s Stephen Toub reported the same kind in the Copilot runtime port: he said dozens of regressions all compiled and merged, and that “if it compiles, it’s correct” is useful only as a joke; the earlier report has the detail. Microsoft’s own Copilot Cowork move is another Python to Rust case.

What builders can take from it

  • When tests can’t define “correct”, use the old system as the oracle and compare it with the new one on real traffic.
  • If you can’t read the data, record the shape of each difference: the step, the piece and the byte where they first part ways.
  • For a non-deterministic service, run the model once and replay its output to both versions.
  • Keep a human at the seam between sandbox and production. A verifier says whether outputs matched, not whether the fix should ship.
  • Write corrections down as rules, lints and merge checks, so nobody makes the same correction twice.

Anthropic says its engineers started inside the inner loop, chasing differences themselves, then moved to the seam to review fixes in Slack, and finally to writing the rules and checks the agents work within. Its first lesson is the line the post leads its list with: “Verification is the new bottleneck.”


Sources


Discover more from Sulat AI & Tech News

Subscribe to get the latest posts sent to your email.