The Pulse
Anthropic moves Messages API from Python to Rust
Anthropic says the Rust version of its Messages API uses about 70% less CPU per request and reduces median time to first token by about 20%. The company used the existing Python service to check the rewrite against live traffic, with Claude agents helping find and fix differences.

Anthropic has moved its Messages API from Python to Rust, using its existing service to check the rewrite against live traffic. In an engineering post, the company says the Rust API uses about 70% less CPU per request and reduces median time to first token by about 20%. Anthropic's chart for CPU covers one region, and the time-to-first-token figure is for customers' Claude Code requests over a shorter period.
Published on Nov. 25, the account describes how Claude agents helped identify and fix differences between the old and new implementations. Claude wrote a first version of the API's core request path in about a week, but verifying its behavior against the production service was harder, according to Anthropic.
Why the API changed
The API is the primary route customers and Anthropic's own applications, including Claude Code and Cowork, use to reach Claude. The company says API traffic grew roughly 1,800 times from early 2024 to fall 2026.
Anthropic built the original Messages API in Python in 2023. By late 2025, each request had to be validated, turned into a prompt, tokenized and screened by safety classifiers; replies also had to be sorted into text, thinking and tool calls.
The company initially rewrote the code that parses model output in Rust while retaining the rest in Python. Anthropic says that reduced API CPU usage by about 8% to 10%, but the gain did not justify the added complexity. Each reply token crossed between the two languages three times, adding overhead.
As Claude became more capable, the company considered a full migration. By May 2026, Claude was writing more than 80% of the code Anthropic merged, the company says.
Testing the rewrite
Anthropic had about 700 integration tests, but they were tied to the Python implementation and did not cover every configuration encountered in production. Claude helped change both the code and the tests, creating a risk that a passing test would reflect a weakened check rather than correct behavior.
An audit of the ported tests found more than 100 weakened assertions, according to the company. It also found a gap between the test results and live traffic: the Rust API passed about 98% of its tests in April, but only about a quarter of inputs matched the Python service.
For example, Python escaped certain characters in JSON tool calls, while Rust wrote them as they were. That left prompts differing by a few bytes. A common bug could also produce many mismatches in live traffic, while a test case would count only once.
Using the live service as a check
The team used the production Python API as a reference, running requests through the old and new code and comparing their behavior. The comparison covered both the input path, which prepares requests for the model, and the output path, which processes replies and counts usage for limits and billing.
Some differences were conspicuous, such as Rust rejecting a request that Python accepted. Others were less obvious: a request could succeed even if the Rust version omitted part of a prompt.
The company could not read customer requests, making it harder to see where the implementations diverged. The Python API also continued changing during the migration, and Claude could respond differently to the same request, so a difference in output was not necessarily a bug.
Anthropic used the comparisons to find differences and automatically dispatch agents to fix them. The company says it shipped the Rust API without taking the service offline or freezing feature development.
Sources
- Original source Anthropic “Migrating our Messages API to Rust” anthropic.com
Companies in this story
Related stories
- DMM and Algomatic Dynamics launch router for 60 or more AI models
- Anthropic rolls out beta to install Claude artifacts as desktop apps
- Anthropic opens zero-retention safeguards for Claude in public beta
- Anthropic mathematician claims Claude helped prove Riemann hypothesis
- Claude puts MCP server skills in beta and makes Tasks and Elicitation generally available