deniz.in

Markets

Weather

Loading weather

· via Hacker News – Front Page (native)

Anthropic migrated its Messages API to Rust, with Claude writing most of the code

Anthropic rewrote its Messages API in Rust with Claude writing most of the code, using production traffic as a parity oracle to verify the migration. The result: about 70% less CPU per request and 20% faster time to first token.

Anthropic migrated its Messages API to Rust, with Claude writing most of the code

Anthropic has moved its Messages API from Python to Rust in a full rewrite of the service that has carried traffic to Claude since 2023. According to the company's engineering post, the new implementation uses about 70% less CPU per request and cuts median time to first token by roughly 20%, shipped without taking the service offline or freezing feature development.

The Messages API is Anthropic's primary endpoint — the way customers reach Claude, and the backbone of its own apps such as Claude Code and Cowork. Between early 2024 and fall 2026, traffic on the API grew roughly 1,800-fold, pushing the original Python service far beyond what it was built for.

Why Python stopped keeping up

Anthropic built the API in 2023, when it was little more than a passthrough to the model. As the product matured, every request came to require validation, conversion into a model prompt, tokenization, and screening by safety classifiers, and every response required its token stream to be sorted into text, thinking, and tool calls. Python added overhead at each step, on every object created and every handoff between tasks.

The API had also accumulated shared dependencies with Python libraries owned by Anthropic's research and inference teams, so a change of language meant rebuilding logging, metrics, and tooling from scratch.

An incremental attempt that didn't pay off

Before committing to a full migration, the team followed the standard advice and rewrote only the hot path: the code that parses model output was ported to Rust and called from Python. That trimmed CPU usage by 8 to 10 percent, but it forced each token to cross the language boundary three times, and Anthropic judged the added complexity greater than the gains.

Full rewrites of live systems are normally avoided because test suites rarely capture all production behavior and the effort is usually prohibitive. Anthropic's own history reflects that caution: in 2024, when an engineer proposed moving to Go or Rust, the suggestion was firmly rejected at the time in an internal exchange the post recounts.

What changed was the cost of writing the code. By May 2026, Claude was producing more than 80% of all code Anthropic merged, and it wrote a first version of the API's core request path in about a week. Verification, not generation, became the bottleneck.

Verifying a rewrite of a moving target

Anthropic frames the core difficulty as a gap between producing work and checking it. In domains like formal mathematics, verifying a solution is easier than finding one, which is why proof formalization suits Claude. Live systems invert the relationship: users depend on edge cases and quirks that fall outside the test suite, so a trustworthy definition of correct behavior is hard to write down.

Three factors made parity checking especially hard here. The Python API kept changing throughout the migration, so correct behavior was a moving target. Claude can respond nondeterministically to identical requests, so a difference between two outputs doesn't necessarily signal a bug. And Anthropic can't read customer requests, which made it difficult to see where the two implementations diverged.

The roughly 700 integration tests couldn't close the gap either. They were coupled to the Python implementation — running the old API in-process, with billing and rate limiting mocked in Python memory — so they had to be ported alongside the code. When Anthropic audited the ported tests, it found more than 100 weakened assertions, meaning a pass could reflect correct code or a test loosened enough to let wrong code through. Exhaustive coverage was also out of reach: twenty binary options produce over a million combinations, which at one second per test would take twelve days for a single model.

Production traffic as the oracle

Rule-based verification and independent test suites were both unavailable. Anthropic points to Bun's move from Zig to Rust as a case where an independent suite worked, since Bun's tests were written in TypeScript and could judge both implementations. With nothing equivalent, Anthropic used the production Messages API itself as the oracle, a technique known as shadowing: requests were replayed through the old and new implementations and the results compared. Divergences were detected on live traffic, and agents were automatically dispatched to fix them.

The Hacker News headline that carried the story to the front page added a claim with wider resonance: the migration was completed with no Rust developers on the team. Language expertise, in effect, came from the model, while correctness was established empirically against the system being replaced.

Why it matters

The performance case is straightforward. A 1,800-fold traffic increase made Python's per-request overhead untenable, and Rust delivered a 70% CPU reduction that incremental optimization could not approach — a concrete data point in the long-running debate over where performance-critical services belong.

The deeper signal concerns how rewrites get done. The traditional objection to rewriting a live system was that generation was expensive and verification imperfect. AI generation has collapsed the first cost, and Anthropic's answer to the second was not better tests but empirical parity against production traffic, with automated agents closing the gaps. If that pattern holds elsewhere, the practical barrier to moving a hot service to a more efficient language shifts from a shortage of experts and time to a single question: can equivalence be measured well enough? For teams running large Python services under growing load, that is a meaningfully different constraint.

  • #rust
  • #python
  • #anthropic
  • #api-migration
  • #performance

Related posts