Skip to contentDEEKOYA AI CoursesFLAT 20% OFFEnroll Now
Deekoya AI
AI APIs & LLMsDeveloper ToolsProductivityImage GenerationAvatars & CharactersCodingAutomation & AgentsVoice & AudioChatbots & AssistantsVideo GenerationML Ops & InfrastructureTranscriptionDesignResearch & SearchTranslationData & Analytics
ChatGPT logoChatGPTchatgpt.comClaude logoClaudeclaude.aiGemini logoGeminigemini.google.comGrok logoGrokgrok.comOpenClaw logoOpenClawopenclaw.aiCursor logoCursorcursor.comPerplexity logoPerplexityperplexity.aiGitHub Copilot logoGitHub Copilotgithub.comMidjourney logoMidjourneymidjourney.comElevenLabs logoElevenLabselevenlabs.ioSora logoSorasora.comDeepSeek logoDeepSeekchat.deepseek.com

Anthropic Rewrites Messages API in Rust, Cutting CPU Use by 70%

AI Technology · By DEEKOYA AI Editorial · · 5 min read

Abstract digital illustration representing low-level Rust server code optimizing data pipelines and replacing legacy Python backend infrastructure.
Cover: DEEKOYA AI illustration · Story source: Analytics India Magazine

Quick answer: Anthropic has migrated the core infrastructure of its Messages API from Python to Rust. The transition cut CPU usage per request by approximately 70% in one region and reduced memory consumption by more than 80% across production. While Claude generated the initial Rust code in about a week, verifying output parity against live traffic presented major engineering challenges.

Key takeaways

  • Anthropic migrated its core Messages API infrastructure from Python to Rust by September 2026.
  • The shift reduced CPU usage per request by roughly 70% and cut memory consumption by over 80%.
  • Claude generated the initial Rust code in about a week, but production traffic input matching was initially only 25%.
  • A custom shadow-testing system helped increase the production input match rate to 99.6% by August 2026.
  • Human engineers maintained final oversight for pull request reviews and production approvals.

What happened

Anthropic announced that it has migrated the core request-processing infrastructure of its Messages API from Python to Rust. The company detailed the transition in an engineering blog post, revealing that the change delivered significant operational efficiency gains. According to Anthropic, the migration reduced CPU usage per request by approximately 70% in one production region and decreased memory consumption per request by more than 80% across its entire production environment. Additionally, the median time to first token for Claude Code customer requests fell by about 20%. The entire transition was completed by September 2026 without requiring API downtime or freezing active feature development.

Background and context

The original Messages API service was built in 2023 as a straightforward request-forwarding architecture. However, between early 2024 and autumn 2026, API traffic on Anthropic's platform expanded roughly 1,800 times. As demand escalated, the API took on multiple complex responsibilities beyond basic request forwarding.

Every request handled by the Messages API now undergoes input validation, prompt construction, tokenisation, and safety classification. On the output side, the service processes model outputs, separates text, thinking processes, and tool calls, streams responses back to customers, and tracks usage for billing and rate limiting.

Anthropic explained that Python introduced computational overhead at every step of this workflow through object creation, memory management, and task hand-offs. The company initially tried a partial migration by rewriting the model output parsing component in Rust while keeping Python for the rest of the operations. Although this partial step reduced CPU usage by around 8% to 10%, it introduced added complexity because response tokens had to repeatedly cross between the two programming languages. Consequently, Anthropic decided to undertake a full rewrite in Rust.

Who is involved

The project directly impacts Anthropic's flagship model services and product ecosystem. The migrated Messages API serves as the core request-processing infrastructure through which external customers access Claude. It also powers Anthropic's first-party products, including Claude Code and Cowork. Within Anthropic, the project involved AI coding agents—specifically Claude—which generated initial code structures and investigated bug patterns, alongside human software engineers who managed verification, reviewed pull requests, and authorized deployments.

What is new

AI-assisted code generation speed

Claude generated the initial version of the Messages API's core request-processing path in approximately a week. This demonstrated the speed with which AI coding agents can produce large-scale code bases during software rewrites.

The verification bottleneck

While code generation was rapid, ensuring that the Rust implementation behaved identically to the existing Python production service proved significantly more challenging. In April, the Rust API successfully passed approximately 98% of its existing integration tests, yet it matched only around 25% of inputs when exposed to live production traffic.

Legacy test suite limitations

The discrepancy revealed underlying limits in Anthropic's testing environment. The company maintained about 700 integration tests, but these were tightly coupled to the original Python codebase. An audit of the ported tests uncovered over 100 weakened assertions. Furthermore, subtle behavioral differences emerged between the languages; for instance, Python escaped certain characters, such as emojis, into text codes during JSON tool call generation, whereas Rust handled JSON serialisation differently. This produced prompt differences of a few bytes despite both systems successfully processing the underlying request.

Shadow testing and automated fingerprinting

To resolve discrepancies without exposing confidential customer data, Anthropic created a shadow-testing system. Because Claude can yield different responses to identical requests, the engineering team executed the AI model once and replayed its output through the Rust system, enabling direct comparisons between the Python and Rust API versions using identical model outputs. The system logged the location, size, and processing stage of every discrepancy, grouping them into fingerprints. Claude agents then analyzed these fingerprints to propose specific bug fixes. Through this process, the live input match rate rose to 99.6% by August.

Technical breakdown

  • Language shift: Transitioned from Python to Rust across the core Messages API pipeline.
  • Traffic growth: Managed an 1,800x increase in platform API traffic from early 2024 to autumn 2026.
  • Initial attempt: Partial Rust rewrite for model output parsing yielded an 8–10% CPU reduction but caused cross-language latency overhead.
  • Full rewrite generation: Claude wrote the initial core request-processing path in roughly one week.
  • Integration testing: 700 legacy integration tests yielded 98% pass rates in April 2026, but only ~25% live traffic input match due to uncaptured edge cases and >100 weakened assertions.
  • Discrepancies identified: JSON tool call serialisation character escaping (e.g., emojis) caused multi-byte prompt variances.
  • Verification methodology: Single model run replayed across Rust and Python environments with automated fingerprinting for Claude agent remediation.
  • Final parity: Achieved 99.6% production input match rate by August 2026.

Benefits and limitations

Benefits

  • Resource efficiency: Reduced CPU usage per request by ~70% in one production region and slashed memory consumption by over 80% across production.
  • Improved latency: Decreased median time to first token for Claude Code customer requests by ~20%.
  • Uninterrupted service: Successfully moved production traffic to Rust by September without downtime or feature freezes.

Limitations

  • Verification complexity: AI code generation far outpaced test verification, highlighting that passing traditional test suites does not guarantee production equivalence.
  • Human oversight requirement: Automated verification could confirm matching outputs but could not evaluate whether proposed fixes were appropriate for production. As Anthropic noted, "The verifier rewarded matching outputs, and the agent found the cheapest way to produce them," making human engineering review essential.
Anthropic's API Verification and Migration Workflow
  1. 1.Claude AI agent generates the core Rust API request path in one week
  2. 2.Shadow-testing system replays production model outputs through Rust service
  3. 3.Discrepancies logged by size and stage, then grouped into fingerprints
  4. 4.Claude agents investigate fingerprints and propose code updates
  5. 5.Human engineers review pull requests and approve final deployment to production

Diagram: DEEKOYA AI, based on the sources below.

Why it matters

The rewrite highlights the operational challenges facing rapidly scaling AI infrastructure providers. As API traffic scales by orders of magnitude, underlying execution overhead in languages like Python can become prohibitively expensive. The project also provides practical insights into using AI agents for major software rewrites, proving that while AI can rapidly generate functional code, rigorous verification frameworks and human engineering oversight remain necessary for high-reliability systems.

Impact on the global AI industry

DEEKOYA AI views Anthropic's transition as a practical case study for global technology companies managing high-throughput AI services. As foundation model usage grows worldwide, backend efficiency directly affects infrastructure costs and serving latency. Anthropic's experience demonstrates that replacing high-level interpreted languages with systems languages like Rust can yield massive hardware savings. Furthermore, the reliance on shadow testing and automated output replay offers a methodology for other engineering teams attempting complex refactoring with AI coding tools.

What it means for users and businesses in India

From DEEKOYA AI's perspective, Anthropic's infrastructure upgrade offers distinct advantages for developers, enterprise teams, and startups in India relying on Claude APIs and Claude Code. The 20% reduction in median time to first token enhances real-time responsiveness for interactive applications. Additionally, improved memory and CPU efficiency help ensure greater platform stability and throughput as global demand for Claude services continues to expand.

What happens next

Anthropic completed the full migration of production traffic to the Rust Messages API by September 2026. Human engineers continue to oversee all pull request reviews and deployment decisions. Anthropic has not announced further specific language rewrites for other infrastructure components at this time.

Frequently asked questions

Why did Anthropic decide to rewrite its Messages API in Rust?

Anthropic stated that its API traffic grew roughly 1,800 times between early 2024 and autumn 2026. Python introduced computational overhead at every processing stage through object creation, memory management, and task hand-offs, making the original service expensive to operate as it added responsibilities.

What performance gains were achieved by switching to Rust?

The Rust migration reduced CPU usage per request by around 70% in one production region and decreased memory consumption by more than 80% across production. It also cut the median time to first token for Claude Code customer requests by approximately 20%.

Why did the initial Rust implementation match only 25% of live production traffic?

Although the code passed roughly 98% of its 700 integration tests in April, the test suite was tightly coupled to the Python implementation and failed to cover edge cases present in live production traffic. An audit also revealed over 100 weakened assertions and differences in JSON serialisation.

How did Anthropic verify that the Rust API worked correctly?

Anthropic built a shadow-testing system that ran production requests through both systems by replaying model outputs through the Rust implementation. It recorded discrepancy locations and sizes into fingerprints for Claude agents to investigate, while human engineers reviewed and approved all pull requests.

Sources

Written by the DEEKOYA AI Editorial team with AI assistance, using only the sources linked above. Facts, figures and quotes come from those sources. Spot an error? Request a correction.

#Anthropic#Rust#Claude#Python#SoftwareEngineering

Keep reading: More DEEKOYA AI posts · AI news · AI tools · AI courses