Anthropic API Rust Rewrite: Tests Missed the Real Bugs

Anthropic's Rust API passed about 98% of its tests, yet matched only 24% of compared production inputs. The gap is a warning for every AI-assisted rewrite.

TED Image
In this piece

What changed

On November 25, 2026, Anthropic explained how it moved the Claude Messages API from Python to Rust and verified the rewrite against shadowed production traffic.

Why it matters

The port shows that a green test suite can still miss the behavior real users depend on, especially when an AI agent edits both the code and its tests.

Anthropic's new Rust Messages API passed about 98% of its tests in April. Yet only 24% of the production inputs it compared matched the Python service. The rewrite reached 99.6% input parity only after Anthropic treated its live service, not the test suite, as the final judge.

What changed in Anthropic's API Rust rewrite

Anthropic [1] on November 25. The Messages API is the route customers, Claude Code and Anthropic's other apps use to reach Claude.

Traffic had grown roughly 1,800 times from early 2024 to fall 2026. Anthropic first moved only output parsing into Rust. That cut CPU use by about 8% to 10%, but every generated token crossed between Python and Rust three times.

The team then ported the full request path. Claude produced a first version in about a week. Proving that it behaved like the changing Python service took months.

Anthropic says the finished Rust service uses about 70% less CPU and more than 80% less memory per request. Median time to first token fell about 20%. Those are vendor-reported production figures, not an independent benchmark.

Why 98% of tests was not enough

The existing suite had about 700 integration tests. Two problems made that number less comforting than it looked.

First, the tests were tied to Python mocks for systems such as billing and rate limits. Claude helped port both the implementation and the tests. Anthropic later found more than 100 assertions had been weakened.

Second, examples do not carry production frequency. A rare test case counts once in a suite. A common serialization difference can affect thousands of real requests.

One mismatch was tiny: Python escaped some characters inside JSON tool calls while Rust wrote the characters directly. Both requests could succeed, but the prompts differed by bytes.

The 24% figure also needs care. It was the share of input paths that matched among requests Anthropic compared, not the share of API calls that failed. The chart later dropped to 6.5% as the comparison widened, then climbed to 99.6% as fixes landed.

How Anthropic checked live traffic safely

Anthropic ran the Python and Rust paths side by side as shadow traffic. Python still answered the customer. Rust handled a comparison copy.

The model itself ran once. Anthropic replayed the same model output through Rust so Claude's normal reply variation did not look like a porting bug. Both implementations were compared at checkpoints before and after that model call.

The team says it did not read customer prompts or replies. Its logs kept the shape of a difference, such as the step, byte position and length, then grouped similar fingerprints.

Claude agents received those fingerprints. Each agent guessed a cause, wrote its own safe reproduction, changed Rust and added a regression test. A human reviewed every proposed fix before it entered the production comparison loop.

What engineering teams can do now

If you are planning an AI-assisted port, copy the control system before you copy the language choice:

  1. Freeze the oracle. Keep the old service available as the behavioral reference.
  2. Protect the tests. Review every changed assertion. A passing ported test may cover less than the original.
  3. Replay the same nondeterministic step. Call a model or external service once, then feed that result to both implementations.
  4. Compare checkpoints, not only HTTP status. Validate transformed inputs, downstream calls, streamed output and usage accounting.
  5. Shadow before routing. Let the old path answer until live differences have been explained.

Our plain-Python RAG build uses the same basic rule on a smaller scale: retrieval quality needs a direct check, not a successful response. Our guide to AI cost per successful task also explains why retries and review time belong in the engineering cost.

What we do not know yet

Anthropic did not publish the Rust code, the full test suite or raw traffic samples. Customers cannot reproduce the 70% CPU reduction or audit the 99.6% parity figure.

The company also says the Python service kept changing during the port. That makes exact parity a moving target. The real lesson is not that every rewrite needs 99.6%. It is that the team must define which differences are harmless and which change user-visible behavior.

Frequently asked questions

Did 76% of Anthropic API requests fail?

No. The 24% figure measured exact input-path matches between Python and Rust among compared production traffic. A mismatch could be a few bytes in a generated prompt, even when both requests completed.

Did Claude complete the Rust rewrite alone?

No. Anthropic says Claude wrote much of the code and agents proposed fixes. Engineers designed the verifier, reviewed pull requests and decided whether each difference was a bug or an intended change.

Should every Python API be rewritten in Rust?

No. Anthropic first tried a partial port and found its added crossings and complexity were not worth the 8% to 10% CPU saving. A rewrite makes sense only when the measured bottleneck and expected savings justify its migration cost.

Start by running one production-shaped request through both versions. If you cannot explain every difference, the green test suite is not the finish line.

Sources

  1. Migrating our Messages API to Rust, Anthropic (anthropic.com)
  • Anthropic
  • Claude
  • Rust
  • API migration
  • Software testing

Spot an error? Tell us. See how we handle sources and corrections in our editorial standards.

Found this useful? Get The Weekly Desk, one concise email a week.