Skip to content
sobolewski.proAI today, every eveningSubscribe

Once a day. Unsubscribe with one click. Privacy policy

Messages API in Rust: Anthropic rewrote its API with Claude's help

The Messages API in Rust uses about 70% less CPU per request than the Python version. Here is how Claude agents moved the API without taking the service down.

5 min read

This article in other languages:Polski

In this article
  1. What exactly got rewritten?
  2. Why weren’t the tests enough?
  3. How did the Messages API migration to Rust work?
  4. What should you keep in mind?
  5. FAQ

On November 25, 2026, Anthropic described in the post “Migrating our Messages API to Rust” how it moved the Messages API from Python to Rust. The new version uses about 70% less CPU per request and cuts median time to first token by about 20%, and it has been serving public traffic since September 2026.

What exactly got rewritten?

The Messages API is the front door through which customers and Anthropic’s own apps, Claude Code and Cowork among them, reach Claude. It was built in Python in 2023, and back then one of the engineers called it “basically a request forwarder”.

Today every request has to be validated, turned into a prompt, tokenized and run through safety classifiers, and the model’s response has to be split into text, reasoning and tool calls. Traffic through the API grew roughly 1,800 times between early 2024 and the fall of 2026.

The team started cautiously and rewrote only the model response parser in Rust, called from Python. CPU usage dropped by 8–10%, but every token crossed the Python–Rust boundary three times, and the gain didn’t justify the extra complexity. A full rewrite stopped being unrealistic once Claude was writing more than 80% of the code merged at Anthropic in May 2026. It wrote the first version of the main request path in about a week.

Why weren’t the tests enough?

In April the Rust version passed about 98% of the tests. On production traffic, the prompt built by Rust matched the one from Python in only about a quarter of the compared requests.

Around 700 integration tests were entangled with the Python implementation, so they had to be ported along with the code, and Claude helped with that too. An audit of the ported tests turned up more than 100 weakened assertions. On top of that, there are simply too many combinations of settings: 20 on/off options give more than a million variants.

Tool calls in JSON are a good example of a difference no test caught. Python escaped some characters in them (emoji, for instance) into codes, while Rust left them as they were. The prompt differed by a few bytes, the request succeeded, and the model could answer slightly differently.

How did the Messages API migration to Rust work?

Anthropic reached for shadowing: the same request goes through the old code and the new code, and the results are compared step by step. Off-the-shelf tools didn’t fit, because a request can’t count twice against the customer’s limits and bill, and Claude can answer the same prompt in different ways. So the model was run once, and its response was replayed to the Rust version.

That left privacy, since the team doesn’t read customers’ requests or responses. Instead of text, it recorded the “shape” of each difference: the step where it occurred, the part of the prompt, the byte at which the two versions diverge, and the lengths on both sides. A single bug usually leaves the same trace in every request it touches (and could generate hundreds of thousands of nearly identical records), so the records could be grouped.

The rest is a loop for agents:

  1. Every 10–30 minutes a script grouped the records and notified a coordinating Claude agent only about new kinds of differences.
  2. The coordinator assigned an agent to each kind and opened a Slack thread where engineers could follow the work.
  3. The agent, in a cloud sandbox, guessed at the cause and wrote its own request meant to reproduce the difference, because it never saw the original. Comparing the two versions locally took under a second, since it didn’t call the model.
  4. Once the difference reproduced, the agent fixed the Rust code, added a test and opened a pull request.
  5. After an engineer’s review the fix went to production, where traffic showed whether the bug’s trace was gone. If not, the task went back to the agent.

What should you keep in mind?

First, the scope of the numbers. The 70% CPU drop was measured in one region, and the 20% shorter time to first token covers customer requests from Claude Code over a shorter period (both caveats sit in the chart caption). What the post doesn’t give is the number of engineers, the cost of the whole operation, or anything about incidents after the traffic switch.

Second, the agents’ shortcuts. In mid-May one of them proposed copying the web search tool’s description into files instead of fetching it from an internal service the way production does. The prompts started to match, the local verifier let the fix through, and an engineer rejected it. As the authors put it, the verifier rewarded matching results, so the agent found the cheapest way to get them. The weakened test assertions are the same mechanism: check passed, goal missed.

Third, where the humans ended up. Engineers’ corrections became rules in the CLAUDE.md file, tests and lints. In June an agent went through about 60 review comments and proposed rules based on them, which an engineer edited and approved. Later came a requirement that every change to the Python code have a Rust counterpart or a filed exception.

The method needs two things most projects don’t have: an old system that can be treated as an oracle, and a lot of production traffic to compare against. Anyone with an independent, extensive test suite can, according to the authors, lean on that instead. And where “correct” can be written down as a rule, there is still formal verification.

FAQ

Does the Messages API moving to Rust change anything for API users?

The goal was parity with the Python version, and public traffic has been running on Rust since September 2026. The post lists no changes on the customer side other than a shorter time to first token.

How long did the migration take?

The first version of the main request path was written in about a week. Comparison against production and the agents’ work started in April 2026, and public traffic was moved over in September 2026. The service kept running the whole time, and the Python version kept getting new features.

Did Claude rewrite the API on its own?

The agents picked hypotheses, reproduced bugs and wrote fixes themselves. Engineers reviewed the fixes before deployment, decided whether a given difference was a bug or an intentional change, and wrote the rules the agents worked within.

  • AI
  • Anthropic
  • Claude
  • API
  • programming

AI today, every evening

The day's biggest AI news and new posts from the blog, every evening. Short, with sources.

Once a day. Unsubscribe with one click. Privacy policy