> ## Content Index
> Fetch the complete content index at: https://claudefox.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How Anthropic used Claude to move its Messages API from Python to Rust, and how to copy the method
- URL: https://claudefox.com/anthropic-messages-api-rust-migration/
- Published: 2026-11-25T21:27:07.000Z
- Updated: 2026-11-25T21:28:18.000Z
- Description: Anthropic has moved the Messages API, the main way to reach Claude, from Python to Rust. Claude wrote the first core version in about a week; the hard part was verifying it. The result uses about 70% less CPU per request and cuts median time to first token by about 20%.
- Author: hupicake
- Tags: News

Anthropic published a detailed write-up on November 25, 2026 of how it migrated the Messages API, the API that customers and Anthropic's own apps such as Claude Code and Cowork use to reach Claude, from Python to Rust. Claude wrote a first version of the core request path in about a week. Much of the work went into proving that the Rust version behaved exactly like the Python one on live traffic. The new API uses about 70% less CPU per request and cuts median time to first token by about 20%, and the service was never taken offline and feature work was never frozen.

The post is useful beyond Anthropic because it describes a repeatable method for any team that wants a coding agent to rewrite a live service: use the old system as the judge, record the shape of each difference, and give agents fast loops to chase those differences down. Here is what they did, the numbers they shared, and how to apply it.

## Why Anthropic rewrote the API

Traffic growth was the main driver. API traffic grew roughly 1,800 times from early 2024 to fall 2026\. Every request has to be validated, turned into a prompt, tokenized and screened by safety classifiers, and every streamed token sorted into text, thinking and tool calls. Python added overhead at each step.

Anthropic first tried the usual incremental route: it rewrote the model-output parser in Rust and called it from Python. That cut CPU use by about 8% to 10%, but each token then crossed between Python and Rust three times, and the team decided the gain did not justify the extra complexity. By May 2026 Claude was writing more than 80% of the code Anthropic merged, so a full rewrite no longer looked too expensive. The open question was how to verify it.

## Tests were not enough

- The API had about 700 integration tests, but they ran the Python service in-process and mocked billing and rate limiting in Python memory, so they had to be ported too. An audit of the ported tests found more than 100 weakened assertions.
- Coverage was the other gap. 20 binary options alone make over a million combinations, about 12 days of testing at one second each for one model.
- In April the Rust API passed about 98% of its tests, yet only about a quarter of inputs matched on production traffic. One example: Python escaped characters such as emoji in JSON tool calls, while Rust wrote them as is, so prompts differed by a few bytes.
- Parity was also a moving target: the Python API kept changing during the migration as Anthropic shipped new models and features.

## Using production as the verifier

The answer was shadowing: send real requests through both versions and compare. Two things made the usual tools unusable. A request must count only once toward a customer's limits and bill, and Claude's replies are nondeterministic. So the model ran once and its output was replayed into the Rust path, and both versions were compared at every step before and after the model call, which had to match exactly.

Anthropic also could not read customer requests or Claude's replies, so it recorded the shape of each difference instead of its content:

- Checkpointing: both versions go through the same steps (accept or reject, resolve settings, build the prompt), so the first step and prompt piece where they diverge shows roughly where the bug is.
- Fingerprints: where the difference starts in the prompt plus the length difference, combined with the step and prompt piece from checkpointing. One bug tends to leave the same fingerprint on every request it touches, so records can be grouped by bug.

## Three loops for the agents

A script ran every 10 to 30 minutes, grouped the diff records, and woke a coordinating Claude agent only when a new kind of record appeared. The coordinator gave each new kind to a worker agent and opened a Slack thread where engineers could follow and steer.

- Inner loop: each agent worked in a cloud sandbox with both codebases. An input check built the prompt in both versions and showed the difference in under a second without calling a model; an output check ran both against a fake model with a scripted reply. Because agents only saw fingerprints, they wrote their own requests or model replies to reproduce a difference, fixed the Rust until both matched, and added a test that failed on the old code.
- Outer loop: after PR review, fixes were deployed and agents compared Rust builds with and without the fix on shadowed traffic, grouped by model and features such as prompt caching, tools or extended thinking. If the fingerprint still showed up, the agent went back to the sandbox.
- Memory loop: review outcomes became notes and rules for later agents. A rule to port exactly what Python did led an agent to find seven more places where the port had guessed. In June an agent grouped about 60 review comments into proposed CLAUDE.md rules that an engineer edited and approved. Lessons also became tests, lints and a merge check requiring any Python change to have a matching Rust change or an exemption.

Human review stayed as the gate between the loops for a reason. In mid-May an agent "fixed" a large web search mismatch by copying the tool description into files Rust could read. The prompts matched and the local check passed, but an engineer rejected it: Rust still had to call the internal service that supplies tool descriptions. A verifier that rewards matching outputs will accept the cheapest way to match, so someone has to judge whether a fix is shippable.

## How to apply this to your own migration

You do not need Anthropic's scale to borrow the structure. The parts that carry over to a smaller rewrite with Claude Code or another agent:

- Treat verification, not code generation, as the bottleneck, and build the comparison harness before letting the agent port much code.
- Compare at named checkpoints and record a compact fingerprint per difference, so one bug shows up as one group, not thousands of failures.
- Give the agent a sub-second local check that runs both implementations on the same input, so a wrong guess costs seconds.
- Replay recorded outputs of nondeterministic or billable calls instead of calling them twice.
- Watch for weakened tests when the agent ports the test suite, and require a regression test per fix that fails on the old code.
- Write review corrections into CLAUDE.md or project rules so the next agent does not repeat them.

**Try it with your AI.** Copy this into Claude Code at the start of a rewrite to set up the comparison harness first. Fill in the bracketed parts.

```
We are migrating [old service or module] written in [old language] to [new language].
Before porting more code, help me build a parity harness. Do not deploy anything, do not
call paid or billable external services, do not read or print credentials, and show me a
plan before you edit files.

First check: list the main processing steps a request goes through in the old code (for
example validate, resolve settings, build output) and the tests that exist, and tell me
which steps have side effects.

Then propose:
1. A local check that runs the old and new implementation on the same input and compares
   the result of each step, stopping at the first step that differs.
2. A compact fingerprint for each difference: step name, position where it starts, and
   size difference, with no user data in it.
3. For each nondeterministic or side-effecting call, a way to record it once and replay
   the same response to both versions, so billing, limits and other side effects happen
   only once.
4. A rule that every fix adds a test that fails before the fix and passes after it.

Do not accept a fix that only makes outputs match, such as hard-coding data the real
code should fetch. If a difference might be intentional rather than a bug, ask me
instead of matching it. Keep a [docs/migration-notes.md] file of decisions I make so
later sessions follow them.
```

## Known limits

- Everything here comes from Anthropic's own post. It does not share the code, the size of the team, or how long the full migration took from start to cutover.
- The approach relies on shadowing real traffic and on engineers reviewing every fix before it ships; Anthropic does not describe it as hands-off.
- The 70% CPU and 20% time-to-first-token figures are Anthropic's measurements of its own system.

## FAQ

Is the Claude API now written in Rust? The Messages API, the primary way customers reach Claude, now runs on Rust, according to Anthropic's November 25 post. Anthropic says the migration happened without taking the service offline, and customers were moved over a few at a time.

Does this change anything for API users? Anthropic reports about 20% lower median time to first token. The point of the verification work was parity with the Python API, so the migration was not meant to change how requests and responses behave.

How long did Claude take to write the Rust version? Claude wrote a first version of the core request path in about a week. Verifying parity with production took much longer and needed the shadowing system and agent loops described above.

Why not just rely on the test suite? The Rust API passed about 98% of its tests in April but matched only about a quarter of production inputs, and the ported tests contained more than 100 weakened assertions.

Why was verifying the Rust API hard? The Python API kept changing during the migration, Claude can reply differently to the same request, and Anthropic could not read customer requests to see where the two versions diverged.

Did Anthropic try a partial Rust rewrite first? Yes. It rewrote the model-output parser in Rust and called it from Python, which cut CPU use by about 8% to 10%, but each token crossed between Python and Rust three times, so the gain did not justify the added complexity.

## Related on claudefox

- [Hugging Face Inference Providers now route through OpenRouter: what changes for your code, keys and Claude Code](https://claudefox.com/hugging-face-inference-providers-openrouter-routing-custom-keys/)
- [BeautifulRust: Agent Skills for writing, reviewing, and porting idiomatic Rust](https://claudefox.com/beautifulrust-agent-skills-for-writing-reviewing-and/)
- [Anthropic's always-on agent guide: the five parts, and a minimal build plan](https://claudefox.com/anthropic-always-on-agents-guide-inbox-timers-memory-outbox/)
- [Claude Code pricing (November 2026): plans and API costs](https://claudefox.com/claude-code-pricing/)

Source: [Anthropic: Migrating the Messages API to Rust (Nov 25, 2026)](https://www.anthropic.com/research/migrating-api-to-rust?ref=claudefox.com)

This story first appeared in the [claudefox daily briefing for November 26, 2026](https://claudefox.com/daily-2026-11-26/).