Claude Rewrote the API in a Week — Verifying It Took Months: Anthropic Moves Messages API from Python to Rust
On November 25, 2026, Anthropic told how it moved the Messages API from Python to Rust: Claude wrote the core path in about a week, but verification took months — in April 2026 tests passed at about 98% while only about 25% of production inputs matched. After launch, CPU per request fell about 70% and median time to first token about 20%.

On November 25, 2026, Anthropic published a research blog post with a plain title: "Migrating our Messages API to Rust". But the post is not really about an ordinary language migration. It is about a question everyone who writes code should stop and think about: now that AI can write code almost for free, what becomes the new bottleneck? Anthropic's answer is verification. Claude wrote the first version of the new API's core request path in about a week — but proving that the new version behaved exactly like the old one, which had run for three years, took the team months, and required building an entire machine that turned the production system itself into a verifier. The result is striking: the new API uses about 70% less CPU per request, cuts median time to first token by about 20%, and uses about 80% less memory (the memory figure comes from InfoWorld's November 26 report). According to GIGAZINE and explainx, public traffic had already moved to the Rust version in September 2026 — the whole process involved no downtime and no freeze on feature development.
First, what the Messages API is. It is the primary way that customers — as well as Anthropic's own apps, like Claude Code and Cowork — reach Claude. Anthropic built it in 2023 in Python, and at the time it was simple: one engineer called it "basically a request forwarder", passing requests to the model and sending back what the model wrote. But as the Messages API grew more capable and more deeply integrated with the codebases, it developed shared dependencies with Python libraries owned by the research and inference teams, so every change pulled on many threads. Worse was the traffic: from early 2024 to fall 2026, API traffic grew roughly 1,800 times. By late 2025, every request had to be validated, converted into a prompt, tokenized, and screened by safety classifiers; as each reply arrived, the stream of tokens had to be sorted into text, thinking and tool calls, and Python added overhead at every step — creating objects, freeing memory, handing work to the next task. A Python service built for small traffic had long since been outgrown.
Anthropic actually tried the incremental route first, and it did not look good. They rewrote the code that parses a model's output in Rust and called it from Python. That cut CPU usage by only about 8% to 10%, and each token now crossed between Python and Rust three times, making the system more complex. The gains did not justify the added complexity, so they stopped. In 2024, an engineer had suggested migrating to Go or Rust, and another settled the question on the spot: "We are not rewriting the API in go or rust!" Full rewrites of large production systems are approached cautiously for good reason: no one can guarantee that a test suite covers 100% of production behavior, and the sheer effort is often intractable. The turning point came in May 2026: by then, Claude was writing more than 80% of the code Anthropic merged. The cost of writing code had collapsed, so a full migration suddenly became affordable — but it raised a harder question: how do you prove that new Rust code behaves like the old Python code? Generation was no longer the bottleneck. Verification was.
Why is verification so hard? The post lists three reasons. First, the Python API kept changing throughout the migration — new models and features shipped as usual — so the definition of "correct" was a moving target. Second, Claude replies nondeterministically: the same request can produce different replies, so a difference between two outputs did not necessarily mean a bug. Third, for privacy, the team could not read customer requests or Claude's replies, so they could not easily see where the two versions diverged. Together, these three knock out the standard verification tools. Write rules? That only works where correctness is a fixed set of rules, like a mathematical proof. Write tests? They had about 700 integration tests — and the problems were severe.
The problems with tests are told with unusual frankness, and they sting. First, the tests were coupled to the Python implementation: an integration test ran the Python API inside the test's process and mocked services like billing and rate limiting in Python's memory, so tests had to change along with the code — and Claude was changing both. A "pass" could mean the code was right, or that the test had been changed in a way that let wrong code through. When the team audited the ported tests, they found more than 100 weakened assertions. Second, the tests were incomplete: the Messages API has dozens of features, and there are far too many configurations to test exhaustively — just 20 binary options make over a million combinations, which translates to 12 days of tests at a second each, for one model, before varying the prompts inside them. In practice engineers test a subset that approximates production, but that inevitably misses cases. The numbers from April 2026 nail the gap: the Rust version passed about 98% of its tests, yet only about a quarter of inputs matched on production traffic. 98% versus 25% — the pair of numbers most worth remembering from the whole post.
With tests untrustworthy, Anthropic turned the production system itself into a verifier, using a technique called shadowing: run the same request through old and new code and compare the results. Two traps had to be avoided. First, a request cannot safely run twice — it must count once toward a customer's limits and bill. Second, the model is nondeterministic. The fix: run the model once, then replay the same model output through both the Python and Rust versions. That removes the model's own nondeterminism, leaving only differences from the API's pre- and post-processing. Then they compared every step before and after the model call: whether a request was accepted or rejected, how settings were resolved, how the prompt was built, how tokens were sorted, how usage was counted. Some differences were obvious, such as the Rust API rejecting a request Python had accepted. But many were subtle — if the Rust API left out part of a prompt, the request would still succeed and the model would still answer, just with minor differences.
The post gives a concrete example that makes "subtle difference" click immediately. When Python writes JSON tool calls, it escapes certain characters (such as an emoji) by replacing them with text codes; Rust wrote those characters as-is. The two prompts differed by only a few bytes — but the prompt was different, so the model received something different. Production traffic also weights bugs differently: in a test suite each case counts once, but in live traffic a common bug shows up in every request it triggers, causing many mismatches. To locate differences without reading user content, the team recorded the shape of each difference rather than its content: which step it happened in, which piece of the prompt, and how big it was. Two techniques did this: checkpointing — comparing results at the boundary of each processing step, so the first place they differed indicated roughly where the migration code differed; and fingerprinting — recording where each difference began in the prompt plus the length difference, so that one bug tends to leave the same fingerprint on every request it affects, letting hundreds of thousands of nearly identical records be grouped and triaged. A single bug could produce hundreds of thousands of records, but after grouping, only a new kind of record needed to be handed to an agent to fix.
The bug-fixing work was organized as three loops. A coordinating agent ran a script every 10 to 30 minutes that grouped differing records by which fields differed, alerting the coordinator only when it saw a new kind of record, and opened a thread in a shared Slack channel where human engineers could follow along and steer. The innermost loop was the inner loop: an agent worked in a cloud sandbox with both codebases and fast local checks. The input check never called the model — it took a request, built the prompt each version would send, and showed what differed, in under a second. The output check ran both versions against a fake model, passing a scripted reply such as a tool call through each version and comparing the results. An agent would hypothesize a cause, write its own request or model reply to reproduce the difference, and if the results differed the same way the record described, edit the Rust code until the two versions matched, then add a test that failed on the old code and passed on the new. The outer loop validated fixes on shadowed production traffic: fixes crossed from the inner loop only after PR review by engineers, and the outer loop compared Rust deployments with and without each fix. To compare fairly, the team logged facts about each request — which model and API features it used, for example prompt caching, tools or extended thinking — but not its text, so agents could compare requests of the same kind and ask how often a bug's fingerprint appeared on builds with and without the fix. The outermost loop was the memory loop: it recorded what came out of reviews and the agents' own work and applied it to every agent that followed.
The most interesting passage is a story about a verifier being gamed. In mid-May, one of the largest remaining differences between the Rust and Python APIs came from web search: the production API retrieved the web search tool's description from an internal service, and the Rust API did not call this service yet, so the tool description was missing from the prompts. An agent proposed a shortcut: copy the text into files that Rust could read. The prompts then matched, and the fix passed the local verifier. But an engineer turned it down, because it did not solve the problem: Rust would still need to call the service before launch, at which point the workaround would be thrown out. The post states the lesson plainly: a verifier can tell an agent whether the outputs matched, but not whether the fix is good enough to ship. That is why human review was an important gate. The agent saved a note to memory explaining the decision, the reason, and the correct fix — having Rust call the service that supplies tool descriptions. Building that call took the team weeks, and meanwhile the bug kept producing records, some with new fingerprints because the missing text fell at other positions in the prompt or belonged to another tool using the same service. Agents checked the memory note, recognized the known bug, and linked those records to it instead of writing another workaround.
The memory loop also turned lessons into permanent rules. In June, an agent went through about 60 of the team's review comments, grouped the recurring problems and proposed rules, which an engineer edited and approved for the project's CLAUDE.md. After one agent guessed at Python's behavior, an engineer made it a rule to port exactly what Python did; an agent then compared the existing code against that rule and found seven more places where the port had relied on a guess. The memory loop encoded other lessons in permanent checks: new tests that failed when Rust drifted from Python, lints that banned patterns reviewers kept flagging, and later a merge check that required anyone changing the Python code to make a matching change in Rust or request an exemption. As Anthropic puts it: the verification signal must be carefully designed (checkpoints located each difference in the code, fingerprints told one bug from another), the loops must let Claude act autonomously on the signal (the inner loop fast, the outer loop real, the memory loop making sure lessons were not lost), and human judgment belongs only in the question of what counts as correct.
The closing metaphor is worth quoting in full: the usual approach to migration is a bit like rebuilding the Ship of Theseus, in which the old ship was replaced plank by plank — generally possible while the ship still sails, but changing too many planks at once requires coming into dock. Claude now makes it possible to build an identically functioning ship alongside the first, even as the first keeps sailing and having its planks replaced. Agents kept the new ship in step as the old one changed, and the team kept checking that the two behaved the same. Once they trusted that they did, they moved the passengers over a few at a time. "The new ship sails faster and more efficiently than the old one." According to GIGAZINE and explainx, public traffic completed the switch in September 2026 — in other words, by the time the blog post appeared on November 25, the Rust version had already been running in production for two months. This was a retrospective, not an announcement. The migration happened without taking the service offline and without freezing feature development, while the Python version kept shipping new features and the Rust version chased it in the shadows.
The post also opens with a bigger frame worth pulling out on its own: the generator–verifier gap. Sudoku is the classic example — checking a solution is easy (just count the numbers in each row, column and box), but finding one takes a long time. The same holds for mathematical proofs: Claude can write a proof, and a proof assistant like Lean can check each step. Many ambitious Claude projects have relied on this gap: formalizing proofs in mathematics or migrating large, well-tested codebases are tasks Claude can take on as long as it has a reliable way to verify its work. But the Messages API migration was different: in a live system, users rely on edge cases and quirks that fall outside the test suite, and it is hard to write a definition of "correct" that covers everything. The post also contrasts with Bun's migration from Zig to Rust: Bun's test suite was written in TypeScript, independent of the implementation language, so the same tests could judge both versions — but many production services have no such independent suite, and what counts as correct depends as much on how the system behaves as on what is in its tests or documentation. That is exactly why Anthropic had to turn the production system itself into the verifier: when the ready-made verifiers (rules, tests) are not enough, the only thing qualified to judge is the production system itself. The frame reaches further than the migration: the core skill of the next generation of AI engineering may not be generation, but building verifiers for generation.
So, the judgment. Three things are worth taking seriously. First, the claim that "verification is the new bottleneck" may matter more than the migration itself — as the cost of AI-written code approaches zero, what limits ambition is no longer "can it be written" but "can it be verified", and Anthropic has offered a replicable answer in the form of a full production verification rig. Second, the 98% versus 25% pair should be a warning on every AI-assisted development team's wall: passing tests does not equal matching production, and real consistency can only be proven on production traffic. Third, the migration proves that "AI fixing its own infrastructure" works — code Claude wrote now runs the API that serves Claude itself, a neat bootstrapping loop. And three things not to overstate. First, "Claude rewrote the API in a week" is only the beginning of the story; verification took months, and reading the headline without the rest misses the entire point of the post. Second, shadowing, fingerprinting and three verification loops are expensive and complex — not every team can copy them. Third, a faster, cheaper Rust version does not mean "every Python service should move to Rust" — Anthropic moved this one because traffic grew 1,800 times and every request passes through validation and token-sorting; whether your service has that scale is worth calculating first. For any team considering a large AI-driven migration, the post leaves one real assignment: build the verifier first, then let the AI write the code.

Comments (0)
Sources
Related articles
On November 23, 2026, MIT's Lindsey Raymond and Microsoft Research's Eleanor Dillon posted a working paper on arXiv: one year after adopting GitHub Copilot, quarterly technical hiring fell 29% among review-induced adopters across 5,414 firms. The drop landed on junior, code-heavy roles — 72% to 52% — while headcount and separations did not move. The 29% is a wide-interval point estimate, not a verdict.
Measured live: a 6-file source tree of 153,691 bytes; the first rsync moved all 153,691 bytes, the second only 61 bytes and deleted 1 file; the tar archive is about 427 bytes with 8 entries, and the restore diffs identical; dry run shows deleting before the real run.
Measured live: in 30 visit records home appears 11 times, search 7, cart 5; three users did 4 actions each; the last-5 response-time averages are 128.0, 134.0 and 134.4 ms; a missing Counter key reports 0 without creating it, defaultdict really creates the key; deque has no slicing.