Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 3 min read

Anthropic rewrote its Messages API in Rust. The tests said 98%. Production said 25%.

The gap between passing tests and matching production Anthropic published a detailed write-up on 25 November 2026 about migrating its Messages API from Python to Rust. The API is the main way customers, Claude Code and

The gap between passing tests and matching production

Anthropic published a detailed write-up on 25 November 2026 about migrating its Messages API from Python to Rust. The API is the main way customers, Claude Code and Cowork reach Claude, and traffic grew roughly 1,800 times from early 2024 to fall 2026. The Python service was creaking under validation, tokenisation, safety screening and streaming on every request, so Rust was the obvious move.

Claude wrote the first version of the core request path in about a week. Generation was not the bottleneck. Verification was.

Verdict: Writing the new code was the easy part. Proving it behaved the same as the old code was the real work. When your tests pass and production disagrees, production is right.

The tests said 98%. Production said 25%.

In April, the Rust version passed about 98% of its roughly 700 integration tests. Yet only about a quarter of real production inputs matched. Two reasons explain the gap.

First, the tests were coupled to the Python implementation. They ran the Python API inside the test process and mocked services like billing and rate limiting in Python memory. When the tests were ported, they changed along with the code, so a pass could mean the code was right or that the test had been changed to let wrong code through. An audit found more than 100 weakened assertions in the ported tests.

Second, the tests were incomplete. The API has dozens of features and far too many configurations to test exhaustively: just 20 binary options make over a million combinations.

Mismatches were often subtle. Python escapes certain characters in JSON tool calls, an emoji for example, replacing them with text codes, while Rust wrote them as is, so the prompts differed by a few bytes. And production weights bugs differently: in a suite each case counts once, but in live traffic one common bug mismatches on every request it touches.

Production became the verifier

Anthropic turned the production API itself into the verifier, shadowing live traffic through both versions. Two hard constraints applied: a request could only count once toward a customer's limits and bill, and nobody could read customer requests or Claude's replies, for privacy.

So instead of comparing text, they compared the shape of each difference. Checkpointing compared every step of request handling, piece by piece, so the first place the versions differed pointed at roughly where the code differed. A fingerprint, where the difference began plus the length difference, grouped identical bugs for triage. Because Claude is nondeterministic, the model ran once and its output was replayed to Rust.

Three loops closed the gap

Each differing request left a small record in the logs. A script grouped them every 10 to 30 minutes and alerted a coordinating Claude agent only on a new kind of record. The coordinator assigned a worker agent to each kind, with a shared Slack thread where human engineers could follow along and steer. Agents fixed issues in a fast inner loop, a cloud sandbox with both codebases and local checks that compared the prompts each version would build in under a second, without calling the model. Fixes were validated in a slower outer loop against production traffic, and mistakes were recorded in a memory loop so agents learned from them over time. The seam between the inner and outer loops was a checkpoint for human review: inside the sandbox a wrong guess cost seconds and harmed nothing.

The result

The Rust API now uses about 70% less CPU per request and cuts median time to first token by about 20%, with no downtime and no feature freeze. The performance gain is real, but the verification machinery that made the migration trustworthy is the interesting part.

What to steal

  • Treat production as the oracle when your tests cannot define correct. A green suite is a claim, not proof.
  • Audit ported tests for weakened assertions before trusting them to judge a rewrite. Anthropic found more than 100.
  • Compare shapes, not raw text, when privacy rules out reading traffic.
  • Give agents fast verification loops, or slow feedback turns them into guessers.
  • Keep a memory of past mistakes, so each fix makes the next one cheaper.

Read the full write-up from Anthropic: Migrating our Messages API to Rust.

Quick poll

What would you verify first before trusting a rewrite like this?

  • The test suite
  • Production shadowing
  • An assertions audit
  • Nothing, ship it

Vote in the comments.

If you found this interesting, I write about engineering leadership in the age of AI agents every week in The AI-Native Engineering Leader, what actually works for engineering leaders building with AI agents, and what to skip.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.