Home / Blog / Migrating our Messages API to Rust news update
Engineering

Migrating our Messages API to Rust news update

Anthropic shipped a Rust Messages API that uses about 70% less CPU per request and cuts the median time to first token by about 20% while staying online.

In short

Customers, Claude Code, and Cowork · About 70% less CPU per request · Shipped; the service stayed online · Test on production traffic, then fix gaps

By Dillip Chowdary • Nov 28, 2026 • Source: Anthropic Research

Migrating our Messages API to Rust news update
Image: Anthropic Research

At a glance

Who it is for
Customers, Claude Code, and Cowork
The number
About 70% less CPU per request
Available
Shipped; the service stayed online
What to do
Test on production traffic, then fix gaps
First token
Median time cut by about 20%
Traffic growth
Roughly 1,800 times by fall 2026

The source cuts off mid-sentence, so the article will use only the facts in that text.Paragraphs are in range, but the draft is over 1,000 words. I'll cut repeated facts and shorten the table.Anthropic's Rust Messages API uses about 70% less CPU per request and cuts median time to first token by about 20%, according to Anthropic Research's report.

Customers and Anthropic apps such as Claude Code and Cowork reach Claude through this API, which never went offline. A team doing a similar port can test on production traffic and send agents after each mismatch.

01Live systems and verifier gap

Many problems have a generator-verifier gap: checking a solution is often far easier than producing one, and Sudoku is the classic case, since counting the numbers in each row, column, and box is simple while finding the solution can take a long time. Claude has used that gap for formal proofs in mathematics and for migrations of large, well-tested codebases when a reliable check exists.

In live systems, generating the work is easier than verifying it: users rely on edge cases and quirks outside the test suite, so a migration is hard to trust however fast Claude generates the code. Anthropic met that limit moving the Messages API from Python to Rust. From early 2024 to fall 2026, traffic grew roughly 1,800 times, and Claude wrote a first version of the core request path in about a week.

Parity was hard: the Python API kept changing, Claude can answer the same request in different ways, and customer requests could not be read. The production API became the verifier: Rust was tested on production traffic, and agents were dispatched automatically to fix each difference. Anthropic never took the service offline and did not freeze feature development.

02Python service and traffic growth

Anthropic built the Messages API in 2023 and wrote it in Python, already widely used for internal research code. It passed requests to the model and sent back what the model wrote. One engineer at the time called it "basically a request forwarder."

Shared Python libraries owned by the research and inference teams made another language expensive, because logging, metrics, and tools would have to be built again. By late 2025 every request had to be validated, converted into the prompt, tokenized, and screened by safety classifiers. Each reply's tokens had to be sorted into text, thinking, and tool calls.

Python added overhead on every step, each time it created an object, freed memory, or handed work to the next task. Traffic grew far beyond what the initial Python service was built for. That load is the monthly average of API requests per day on Anthropic's own platform, including Anthropic's own use.

03Incremental port and full rewrite

Advertisement

Tech Pulse Daily

Get tomorrow's pulse first

Join engineers who read Tech Pulse before stand-up. Free, weekday mornings.

Full rewrites of large production systems are often approached cautiously, because tests do not cover every production behavior and because the effort can make the work intractable. In 2024, after one engineer suggested Go or Rust, another replied, "We are not rewriting the API in go or rust!" Anthropic took the usual advice and rewrote only the slow part.

The code that parses a model's output was rewritten in Rust and called from Python, which cut CPU usage by about 8% to 10%. Each reply token then crossed between Python and Rust three times, which was not worth the gain. By May 2026 Claude was writing more than 80% of the code Anthropic merged, and the effort was dropping fast, so Claude could help capture every behavior and fix, but verification, not generation, was the bottleneck.

04Correctness rules and test gaps

Anthropic had to define correct before the Rust port could be trusted. A fixed rule or a set of examples can do that, but neither was enough while new models and features kept shipping. The live Messages API was the oracle, and parity stayed a moving target.

Source of correctCheckFinding
Fixed ruleLean checks each step of a proofNot enough for this API
Example suiteBun moved from Zig to Rust; TypeScript tests judged bothAbout 700 tests, tied to Python
Live oracleThe running service, still changingParity was a moving target

About 700 integration tests were the easiest start, but they were coupled to Python. A test sends a request, checks the reply and what was sent to other services, runs the Python API in the test process, and mocks billing and rate limiting in Python memory. Claude helped change the tests and the code, and an audit found more than 100 weakened assertions, so a pass could mean correct code or a check that let wrong code through.

The tests were also incomplete. The API has dozens of features, and just 20 binary options make over a million combinations, or 12 days of tests at one second each for one model before prompts vary. A subset that tries to approximate production still misses cases, and unlike Bun many services have no independent suite large enough to judge a rewrite, so correct behavior depends on live use as well as tests or documentation.

05Production request path differences

Production data is sometimes "the only true test" that new code behaves like the old code. Shadowing compares old and new results on the same requests, and Anthropic ran it on the input and output paths. Filled dots mark differences between Python and Rust, and the hollow dot marks a risk that had to be prevented.

  1. Validate each request.
  2. Convert it into the prompt for inference and tokenize it.
  3. Screen the prompt with safety classifiers.
  4. Generate the reply one token at a time.
  5. Sort tokens into text, thinking, and tool calls, stream them to the customer, and count usage for limits and billing.

Some differences were obvious, such as the Rust API rejecting a request that Python had accepted. Many were subtle, including a case where the Rust API left out part of a prompt. Those gaps showed up when production traffic ran through both versions.

Note: A difference between two outputs did not necessarily mean a bug, because Claude can reply nondeterministically to the same request, and customer requests could not be read to locate the split.

Frequently asked questions

How much less CPU does Anthropic's Rust Messages API use?

The Rust Messages API uses about 70% less CPU per request. Median time to first token is about 20% lower, and Anthropic did not take the service offline to ship it.

How much did Messages API traffic grow?

From early 2024 to fall 2026, traffic grew roughly 1,800 times. Anthropic measures that load as the monthly average of API requests per day on its own platform, including its own use.

Why was the partial Rust rewrite not enough?

Rewriting the output parser in Rust and calling it from Python cut CPU use by about 8% to 10%. Each reply token then crossed between Python and Rust three times, and that complexity was not worth the gain.

Why could about 700 integration tests not prove the port?

The tests ran the Python API inside the test process and mocked billing and rate limiting in Python memory, and an audit found more than 100 weakened assertions. Just 20 binary options also make over a million combinations, or 12 days of one-second tests for one model before the prompts vary.

How did Anthropic check the Rust API against production?

Anthropic shadowed production traffic through the Python and Rust paths and automatically dispatched agents to fix each difference. A mismatch was not automatically a bug, because Claude can reply nondeterministically and customer requests could not be read.

Sources

Dillip Chowdary

Author

Dillip Chowdary

Writes Tech Bytes coverage of AI, engineering, and the tools that actually ship. Editor of Tech Pulse Daily.

Related on Tech Bytes

Advertisement

5-min tech signal

Weekday briefing for engineers who skip the noise.

No spam · Unsubscribe anytime

Advertisement

✈️ CareerPilot

Your AI job-search copilot

Match your resume against live Ashby, Greenhouse & Lever openings — fit scores, job-specific resume optimization and email alerts.

Find matching jobs →

Free Tools

Browse all tools →