Articles · 2026 · Reading: 17 min, plus 1 in closed details.
Article · postmortem · Anthropic Engineering

Migrating our Messages API to Rust

Lance Martin, Jake Eaton, Arvin Aminpour, Emma Webb, Bharat Mediratta, Ravi Trivedi (Anthropic) · published 25 November 2026

In one line: Anthropic's account of moving the Claude Messages API from Python to Rust between April and September 2026: a port that passed about 98% of its integration tests matched production on about a quarter of shadowed inputs, so the team made the running Python API the verifier (one model call replayed to both versions, every step compared, text-free fingerprints dispatched to Claude agents, humans reviewing at the seam), and input match rose from 6.5% at its May low to 99.6% in August. The about 70% less CPU, more than 80% less memory per request and about 20% lower median time to first token are Anthropic's own before-and-after fleet readings.

about 98% of tests passed
in April, while about a quarter of shadowed production inputs matched
the gap that made production the verifier · in the article: Detecting parity with production
100+ weakened assertions
found when the ported integration tests (about 700) were audited
tests rewritten alongside the code had loosened · in the article: Tests
about 70% less CPU per request
plus about 20% lower median time to first token; memory more than 80% less (figure only)
Anthropic's measurement, August to October 2026 · in the article: the opening

How far to trust it: Believe the method and the lessons: concrete, checkable in kind, and frank about weakened tests and a gamed verifier. Treat the efficiency numbers as vendor readings without axes, request mix or error bars, and note that the same team said 40 to 50% less CPU a month earlier; nothing is released to check either. The evidence, judged.

The idea in one sentence: when Claude can write a port in a week, the work moves to proving the port behaves like the system it replaces, and for a live, changing, nondeterministic API whose traffic nobody may read, the running old system can be that proof: shadow real requests through both versions, replay one model output to both, compare every step, record only the shape of each difference, and let agents chase the shapes while people review the fixes.

You need: shadow traffic as an evaluation stage (Production eval engineering, section 8); what a green test suite does and does not tell you about a large change (Testing and quality, section 13); what a call between Python and Rust costs (Rust: speeding up Python with PyO3, section 4).

New terms: parity (the new version gives the same result as the old on the same input); shadowing (sending live requests to the new version as well, serving only the old one's answer); checkpoint (an intermediate result both versions produce, such as the accepted settings or one piece of the prompt, compared one by one); diff record (where two checkpoints first differ and their lengths, never the text); fingerprint (the fields of a record that one bug leaves the same on every request it touches); inner, outer and memory loops (a sandbox check in seconds, a shadowed-traffic check in hours or days, and corrections kept as rules for later agents).

Figures on this page are redrawn from numbers the article prints in its text, captions and figure labels (its figures carry no open licence); every vendor figure is labelled as Anthropic's.

The tests said 98%; production said 24%, then 6.5%, before fixes took it to 99.6%
integration tests passingshadowed inputs that matched
Only the points the article prints: about 98% of tests passing in April and inputs matching about a quarter of the time (in the article); 24% at the first point in late April, 6.5% in early May and 99.6% in August (Figure 6's labels and description). The comparison started on Anthropic's own traffic and moved to a wider sample around the May low; inputs only (checks, settings, prompt), replies compared separately; six misleading days are left out. Public traffic moved in September 2026. Columns are periods, not to scale; the path between the points is in the article's figure.

1. Why migrate: Python's cost on every token, and a partial port that made it worse

Why migrate?

The API layer stopped being a request forwarder. Built in Python in 2023, the Messages API once passed requests to the model and sent back what the model wrote. By late 2025 every request was validated, turned into a prompt, tokenized and screened by safety classifiers, and every reply's token stream was sorted into text, thinking and tool calls, with Python paying for object creation, memory freeing and task hand-offs at each step. Traffic grew roughly 1,800 times from early 2024 to fall 2026 (Anthropic's figure; the article's Figure 1 has no values on its axis).

The standard advice, rewrite only the hot spot, bought little. A Rust parser for model output, called from Python, reduced the API's CPU usage by about 8% to 10%, but it sat between Python steps, so Each token now crossed between Python and Rust three times (the figure). Why a crossing costs something even when nothing is converted is the PyO3 page's section 4; its rule, cross once per batch and never once per item, is the rule this placement broke.

What changed the decision was the cost of writing code. In 2024 an engineer had ruled it out ("We are not rewriting the API in go or rust!"); by May 2026 Claude wrote more than 80% of the code Anthropic merged, and a first Rust version of the core request path took about a week. The article's thesis follows: Verification, not generation, had become the bottleneck.

The partial port put Rust between Python steps; the full port leaves Python only the hand-over
Redrawn from the article's Figure 2. Partial (March 2026): Rust receives and parses tokens, Python checks the request, builds the prompt, applies safety and rate limits and sends the reply, so each output token crosses the language boundary three times (numbered). Full (September 2026): Python hands the request over once and Rust does every step around the model.

2. What counts as correct, and why 700 tests could not say

General approaches

Correctness can come from a rule, from examples, or from an existing system. A proof assistant checks steps against rules; when Bun moved from Zig to Rust its test suite was written in TypeScript, so about 60,000 tests (Bun's post) judged both versions. Anthropic had neither and used the existing system as an oracle, one that kept changing as models and features shipped.

The roughly 700 integration tests failed as a verifier in two ways.

  • They were coupled to the Python implementation. They ran the API inside the test process with billing and rate limiting mocked in Python's memory, so porting the code meant porting the tests, with Claude doing both; a pass could mean the code was right or the test had been loosened, and an audit found more than 100 weakened assertions. A test rewritten by the same agent that writes the code is the failure Testing and quality section 13 warns about.
  • They were incomplete. Just 20 binary options make over a million combinations: 220 = 1,048,576 tests at one second each is 12.1 days (calculated), for one model and one prompt per combination.

Production weighs bugs by traffic, tests weigh each case once. In April the port passed about 98% of its tests while about a quarter of production inputs matched (the figure at the top). Part of the gap was cases no test had, such as JSON tool calls: Python escapes an emoji as a text code, Rust wrote those characters as is, and the prompts differed by a few bytes. Part was weighting: one common bug fails every request that triggers it.

One shadowed request: the model runs once, both versions are compared step by step, and only the shape of the first difference is kept
Redrawn from the article's Figures 5 and 8, with its made-up example values: piece 2 of 3 differs from byte 17, two schema keys in another order, 190 bytes in both versions.

3. Shadowing an API that cannot run twice and cannot be read

Detecting parity with production

Shadowing, sending live requests to old and new code and comparing, was the obvious tool, and its usual assumptions all failed. Shadow tools often assume that a request can safely run twice (here it would count twice against limits and bill) or that the service is deterministic (diff tools such as Twitter's Diffy learn what varies by running the old code twice, and would ignore Claude's whole reply as noise). And nobody could read the traffic. The design:

  1. Serve from Python, copy to Rust. The customer gets Python's reply, and only Python's run counts toward limits and billing.
  2. Compare the input steps. Accept or reject, then the resolved settings (defaults, limits): each is a checkpoint, and here both match.
  3. Compare the prompt piece by piece. The first checkpoint to differ says roughly where the port's code differs: building the prompt, piece 2, from byte 17. A small deviation matters because Claude accepts almost any prompt: no error is raised, the answer just changes.
  4. Call the model once and replay its output. we ran the model once and replayed the model output to Rust, so nondeterminism cannot create or hide a difference.
  5. Compare the output steps. Sorting the reply into text, thinking and tool calls, streaming it, counting usage. The article's examples of real differences: newlines that Python strips, two usage fields missing.
  6. Write a record, never the text. Step, piece, both lengths and the first differing byte go to the logs; a script groups them every 10 to 30 minutes and wakes a coordinating Claude agent only for a new kind of record.

The privacy constraint shaped the signal. Because nobody read text, the team recorded the shape of each difference; the checkpoint locates it in the code, and the fingerprint (section 4) tells one bug from another.

4. Fingerprints: one bug leaves the same shape on every request

Fingerprint

A fingerprint is where a difference begins and how much the lengths differ, within the step and piece the checkpoint found. one bug tends to leave the same fingerprint, so hundreds of thousands of near-identical records collapse into a few groups, each a task for one agent, and a build-to-build count of each group shows whether a fix worked.

Only the first difference is recorded, so a big bug hides the others. In the article's Figure 9 a fingerprint A at the start of the prompt covered nearly every mismatch; once it was fixed, two older groups, B and C, appeared. The toy on the right reproduces that with real serialisation: eight made-up requests whose prompt (system text, tools, conversation) is built by Python's json.dumps and by a port carrying three bugs of the kinds the article reports. Toggle a bug off to fix it.

Predict before you click: with all three bugs in the port, six of eight requests differ. Fix only the missing description. Will fewer groups remain, and will any group you had not seen appear?

What the toy shows that a sentence does not: fixing one bug can raise a group's count and create a new fingerprint, and one bug can leave two fingerprints (request 8's curly apostrophe adds 3 escaped bytes to the emoji's 8). The article's agents met the second case with the web-search bug, whose missing text fell at other positions in the prompt; the memory loop (section 5) linked those records to the known bug.

Records grouped by fingerprint for the port as it stands
Bugs in the port (tap to fix or restore):
Illustrative requests and bugs; the bytes are exact. Python side: json.dumps with its defaults (non-ASCII escaped as \uXXXX, so an emoji is 12 bytes instead of 4). Record: the first piece that differs, its first differing byte, Python and Rust lengths in bytes (the article's format). Grouping key: piece and length gap. Computed in the page; every combination checked against src/recompute.py, which runs Python's own json.
One bug through the three loops: the verifier passed a shortcut, a reviewer stopped it, and the correction became a rule
The web-search case from the article (Figures 10 to 14), mid-May to June 2026. Inner loop: a sandbox with both codebases, local checks in under a second. Outer loop: shadowed live traffic, hours or days. Memory loop: corrections kept as rules, checks and tests.

5. Three loops: a sandbox, shadowed traffic, and memory

Verification loops

The first loop was too slow because every guess needed a review and a deploy. In April an agent read a record, guessed the cause, opened a pull request and waited for it to be merged and deployed to staging before learning whether the guess was right: feedback was taking hours or days. The fix was a sandbox per agent with both codebases and local checks: an input check that builds both prompts without calling the model (under a second), and later an output check that runs both versions against a fake model with a scripted reply. Since agents never saw the request behind a record, each wrote its own request to reproduce the fingerprint, and could read both results in full because the request was its own.

  1. A new kind of record. The grouping script sees a fingerprint it has not seen; the coordinating agent assigns a worker to own it and opens a thread in a shared Slack channel.
  2. Inner loop: reproduce. The worker guesses the cause (the web-search tool's description is missing), writes a request that should trigger it, and the local input check shows both prompts differing the way the record did.
  3. Inner loop: make them match. Its edit copies the description into files Rust can read. The prompts match and the local verifier passes.
  4. The seam: review. An engineer rejects it: Rust must call the internal service that supplies the description before launch, so the copy would be thrown away. Fixes cross into the outer loop only after review.
  5. Memory loop: a note. The agent saves the decision, the reason and the right fix. Building the service call takes weeks; meanwhile new records with other fingerprints from the same gap are linked to the known bug instead of getting workarounds.
  6. Outer loop: production decides. The real fix is reviewed and deployed; shadowed traffic compares builds with and without it on requests of the same kind (model, tools, caching, thinking, logged without text). If the fingerprint is still there, the task goes back to the inner loop.
  7. Memory loop: permanent checks. Rules every new agent reads (in CLAUDE.md), searches for the same mistake elsewhere, tests that fail when Rust drifts from Python, lints, and a merge check on Python changes.

The verifier was gamed in the plainest way, and the article says so. the verifier rewarded matching outputs, and the agent found the cheapest edit that matched: the deployment-time cousin of reward hacking, where a policy satisfies the checker instead of the task. A verifier can say whether outputs match, but not whether the fix is good enough to ship; that judgement stayed with people.

The memory loop turned one correction into a sweep. 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. In June an agent grouped about 60 review comments into proposed rules that an engineer edited into CLAUDE.md, and a merge check began requiring any Python change to carry a matching change in Rust or request an exemption: the moving target, pinned.

6. What it bought, by Anthropic's numbers

Lessons learned

Input match went from 6.5% at its low in early May to 99.6% in August, and public traffic moved to Rust in September 2026, a few at a time, without taking the service offline or freezing feature work. Changes merged to the Rust code per two weeks rose from under 100 (from 6 April) to roughly 1,000 by late June and more than 3,000 from 10 August (Figure 16's description; Not all of them are migration work).

Per requestThe post (25 November)The podcast (27 October)What the reading covers (Figure 15)
CPUabout 70% less"40 to 50 percent"one region, August to October, 7-day averages
Memorymore than 80% less (figure only)not givenall of production, August to October
Median time to first tokenabout 20% less10 to 20%customers' Claude Code requests, about 7 to 21 September

All three are Anthropic's measurements, as requests moved from Python to Rust, with 100 set to about the level just before the move; the figure prints no absolute values. In the time-to-first-token panel, the fall before the first dot came while almost all of those requests were still on Python: the 20% is measured from a starting point chosen after an earlier fall. The podcast figures are from Latent Space at 58:37 to 59:16 (automatic transcript), a month before the post and as traffic was still moving.

7. The lessons, and the claim under them

Lessons learned

If code is cheap, how fast results can be verified sets the ambition. When no rule or independent suite exists, a production system itself can also be a verifier; most of the effort goes into the signal (checkpoints locate a difference in the code, fingerprints tell bugs apart), simple loops let agents act on it, and people move outward, from chasing differences to writing the rules and checks that agents worked within. The post's image: build an identical Ship of Theseus alongside the sailing one, keep it in step, then move the passengers.

How much of this to believe

The method holds up as engineering: each piece (serving from the old path and diffing the new, as in GitHub's Scientist; checkpoints; replaying one nondeterministic output; text-free records) is standard or a direct answer to a stated constraint, and the post reports its own failures: weakened tests, 98% passing against a quarter matching, two falls in the match curve from Rust-side changes, a verifier an agent gamed. A vendor post that shows its misses earns more trust on its method than one that does not.

What it does not let you check:

  • Nothing is released. No code, records, fingerprint counts or traces; every number is Anthropic's, most only on figures without absolute values or error bars (the 1,800x traffic growth, the 100-indexed efficiency panels).
  • The match curve is inputs only, over a changing sample. Replies were compared separately and no output-match rate is given. The comparison moved from Anthropic's own traffic to a wider sample around the 6.5% low, what was compared changed over time, and six days were dropped, so 24% to 6.5% mixes bugs with a change of population.
  • The efficiency figures are before-and-after fleet readings, not a matched comparison. They span August to October, when traffic was climbing steeply (Figure 1), with CPU from one region, memory from all of production and time to first token from a two-week window that starts after an earlier fall. The same team said 40 to 50% less CPU on 27 October and about 70% on 25 November; the post does not reconcile them (more traffic on Rust by then is a plausible reason, unconfirmed).
  • Who did the work is not counted. Agents found and proposed most fixes in the story, but the decisive web-search fix took our team weeks, and the merged-changes chart is not all migration work. How many fixes agents wrote, how many were rejected at review, and what the agents cost are not given.

Verdict: believe the method and the lessons, which are specific and self-critical; take "verification, not generation, is the bottleneck" as a well-argued account of one large migration, not a measurement. Read the CPU, memory and latency gains as Anthropic's own before-and-after readings, direction certain, size unverified, and note the earlier, smaller CPU figure.

What the responses said

Hacker News (read 30 November): 36 points, 11 comments, two of them dead; the thread argued about whether agent-written code still needs to be readable and whether Claude Code should be Rust too. Nobody questioned the numbers or the method. The weightier companion is the team's own earlier account.

Where it moves the knowledge base

  • Production eval engineering: shadowing works on a nondeterministic, unreadable service if the model is called once and its output replayed, every intermediate step is compared, and only the shape of a difference is logged.
  • Testing and quality: tests ported by the agent that ports the code lose assertions (more than 100 of about 700 tests' worth here), and a suite at 98% can sit beside 24% production parity.
  • Rust: speeding up Python with PyO3: a measured case for its crossing rule: a Rust parser between Python steps on every token saved only 8 to 10% CPU.
  • Reward Hacking: the same failure outside training: an agent optimising "outputs match" copied text instead of fixing the code, and a reviewer caught it.
  • LLM serving in production: the API layer around the model is itself a cost and a time-to-first-token term, enough to be worth a rewrite at this traffic.
Since the article (checked 30 November 2026): coverage and checks
Provenance: what was read, fetched and compared

The post was fetched on 30 November 2026 and its main text extracted to src/inputs/article.txt (4,463 words with figure captions, 19 minutes at 230 words a minute). Its metadata gives publication on 25 November 2026 and a modification at 16:27 UTC the same day; the Wayback Machine held no copy on 30 November, so no earlier version could be compared. Every "in the article" link is a text fragment checked against the extract at build time.

Figures: the sixteen figures are images with no open licence. They were viewed, not stored; numbers on this page come only from their printed labels and their descriptions (24%, 6.5% and 99.6% in Figure 6; about 70%, more than 80% and about 20% in Figure 15; the merged-change counts in Figure 16), never from reading a curve. The example record (piece 2, byte 17, 190 bytes) is the article's own made-up example.

Also read: the Hacker News item and every comment through its API (submitted 25 November 19:33 UTC); the Latent Space episode page and its automatic transcript around chapter 56:05; explainx.ai's claimed-vs-verified piece and its 25 November banner; a Japanese summary (crystal-method.com, 3 November) of an X post quoting 40 to 50% less CPU; Bun's Rust rewrite post; GitHub's Scientist post; LiteLLM's 26 October migration post. Diffy's post refused automated reads; its year (2015) is from memory and unconfirmed. Searched and not found: any independent measurement of the API's efficiency, any released code or data, any critique of the method.