Why Anthropic Moved the Claude Messages API to Rust

Max WellsMax WellsFounder of Rustify
By Max Wells16 min read
Anthropic Moved Claude's API to Rust

By Max Wells, updated November 27, 2026

TL;DR: Anthropic says it moved the Messages API, the main way customers and Claude Code reach Claude, from Python to Rust, with public traffic on Rust since September 2026 and no downtime. Claude wrote the first version of the core request path in about a week. The hard part came after: the Rust version passed about 98% of tests but matched Python on only about a quarter of production inputs. Anthropic closed that gap with a shadow-traffic verifier and agent loops, then reported about 70% less CPU per request, more than 80% less memory, and about 20% faster median time to first token.

  • What moved: request validation, prompt building, tokenization, safety screening, output parsing, streaming, and usage counting
  • How: incremental traffic shift, replayed model output, step-by-step checkpoints, privacy-preserving diff fingerprints
  • Main lesson: when agents write code fast, verification becomes the bottleneck
  • Rust implication: Rust pays off on hot, per-token request paths, but only teams that can prove equivalence get to collect the gain

What Did Anthropic Announce About the Messages API and Rust?

Anthropic says it rewrote the Claude Messages API in Rust and moved public traffic to it in September 2026, with Python now only handing the request over.

The details come from an Anthropic engineering post, Migrating our Messages API to Rust, published November 25, 2026, and from the company's announcement on X. The Messages API is not a side service. It is the primary interface for API customers and the path used by Anthropic's own products, including Claude Code.

The post is unusual for a rewrite story. Most migration write-ups lead with a benchmark. Anthropic leads with a problem: generating the Rust code was fast, and proving it behaved like the Python version on real traffic was slow. The authors put it in one line: "Verification, not generation, had become the bottleneck."

2023        Messages API built in Python ("basically a request forwarder")
2024        Proposal to move to Go or Rust is dismissed
Mar 2026    Partial rewrite: Rust parses model output, called from Python
Apr 2026    Full Rust path passes ~98% of tests, matches ~25% of live inputs
May 2026    Match rate dips to 6.5%, then climbs as fixes ship
Sep 2026    Public traffic moves to Rust
Nov 2026    Engineering post published

What Is Confirmed and What Is Still a Claim?

StatementEvidence levelSource
The Messages API moved from Python to RustDirect company statementAnthropic
Public traffic moved to Rust in September 2026Direct company statementAnthropic
Claude wrote the first core request path in about a weekCompany-reportedAnthropic
About 70% less CPU and over 80% less memory per requestCompany-reported, scope varies per chartAnthropic
Rust alone caused the gainsUnsupportedArchitecture also changed
The team started with no Rust developersReported from an earlier interview, wording unverifiedLatent Space podcast

No Rust crates, team size, line counts, or migration cost are disclosed. An earlier podcast interview gave lower figures, around 40% to 50% CPU savings, and the November post should be treated as the current source.

Why Did Python Stop Fitting the Messages API?

The API stopped being a thin forwarder: every request and every output token now passes through work that Python makes expensive at Anthropic's scale.

According to the post, each request is validated, turned into a prompt, tokenized, screened by safety classifiers, sent to the model, and then the model's output is sorted into text, thinking, and tool calls, streamed back, and counted for rate limits and billing. Python added overhead at each step and, more importantly, on each output token.

Two factors turned that overhead into a priority:

  • Traffic: Anthropic says API traffic grew roughly 1,800 times between early 2024 and fall 2026. A fixed per-token cost multiplied by that growth becomes a fleet-sized bill.
  • Coupling: the API shared Python libraries with research and inference teams. Leaving Python meant rebuilding logging, metrics, and internal tooling, not only rewriting handlers.

This is the classic profile where Rust earns its place: a long-lived, high-volume request path with a lot of CPU work per byte streamed. It is the same reasoning covered in our Rust vs Python performance comparison, applied to a service where the per-token loop dominates.

Why Didn't a Partial Rust Rewrite Work?

Calling Rust from Python only cut CPU by about 8% to 10%, because every token crossed the language boundary three times.

In March 2026, Anthropic moved model-output parsing into Rust and called it from the Python service. That is the standard first move for Python teams, the same pattern behind most PyO3 adoptions: keep the application, replace the hot function.

It underdelivered here. Only token receiving and parsing ran in Rust, while safety checks, rate limits, and sending stayed in Python, so the output path bounced between languages for every single token:

Diagram comparing Anthropic's March 2026 partial Rust rewrite, where each output token crosses the Python and Rust boundary three times, with the September 2026 full rewrite where every stage runs in Rust
Partial vs full rewrite. Redrawn from Anthropic's published migration post.

The lesson is specific and reusable. FFI hot-path extraction works when the hot path is a large chunk of work called rarely, such as parsing a big file. It works poorly when the hot path is small and called per item in a stream, because the crossings cost about as much as the work you moved. Anthropic concluded the gain did not justify the complexity and moved to a full rewrite where Python hands over the request and Rust owns everything around the model call.

Why Did 98% of Tests Passing Mean So Little?

The test suite was coupled to Python and could not cover the feature space, so a Rust version that passed it still disagreed with production most of the time.

Anthropic describes about 700 integration tests that ran the Python API in-process with mocked services. Porting them to Rust was not neutral: an audit later found more than 100 assertions that had been weakened during the port, meaning tests that passed without checking what they used to check.

Coverage was the deeper problem. The post gives a simple calculation: 20 independent on/off options produce more than a million combinations, which at one second per test would take about 12 days, for one model. Real requests combine models, tool use, prompt caching, extended thinking, limits, and formats in ways no hand-written suite enumerates.

The result in April 2026:

SignalResult
Rust test suite pass rateAbout 98%
Production inputs matching PythonAbout 25%
Match rate in early May, after new traffic shapes appeared6.5%
Final input match rate shown in Anthropic's chart99.6%
Line chart of the share of shadowed production inputs where the Rust Messages API matched Python, from 24% in late April 2026 down to 6.5% in early May and up to 99.6% by August, against a 98% test pass rate
Test pass rate vs live input match rate. Curve approximate, data from Anthropic.

The bugs were mundane, which is exactly why tests missed them. Anthropic lists cases such as Python escaping emoji in JSON while Rust did not, which changed the prompt bytes; a 1M token limit read as 200K; a missing tool description; stripped newlines; and missing usage fields. In several cases the model still answered normally, so nothing looked broken from the outside.

How Did Anthropic Verify the Rust API on Live Traffic?

Anthropic used the running Python service as the specification: it shadowed production requests, replayed one model output to both versions, and compared them step by step.

Shadow comparison is not new. Anthropic links to GitHub's Scientist and X's Diffy as prior art. What makes this case hard is that the system wraps a nondeterministic, expensive model call and handles customer data nobody is allowed to read.

The design handled those constraints with four ideas:

Diagram of Anthropic's shadow verifier: Python and Rust parse, validate, and build the prompt, the model is called once and its output replayed to both, and the first differing checkpoint is recorded as step, piece, lengths, and first differing byte, with no customer text
How the verifier localizes a difference. Redrawn from Anthropic's example.
  1. One model call, replayed. The model ran once and its output was fed to both implementations. That removes nondeterminism from the comparison and avoids double counting against customer limits and billing. It also fixes a weakness of classic diff tools: they learn which fields vary between two runs, such as timestamps and IDs, and ignore them as noise. In an inference API the reply text itself varies on every call, so ignoring it would have hidden exactly the bugs Anthropic needed to find.
  2. Checkpoints. Each stage was compared separately, so the first differing stage pointed at the bug instead of a vague "response differs". In the example above, both prompts have the same length, but the JSON keys come out in a different order at byte 17, which tells an agent exactly which code builds that piece.
  3. Shapes, not content. A difference was recorded as its structure: which step, which prompt piece, where the first byte differed, and both lengths. Engineers did not read customer requests or replies.
  4. Fingerprints. One common bug could produce hundreds of thousands of nearly identical records. Grouping by fingerprint turned that flood into one work item, and a fingerprint disappearing after a deploy confirmed the fix.

Traffic moved to Rust gradually, a few slices at a time, with the API online throughout.

What Did the Claude Agents Actually Do?

Agents wrote the code and chased the diffs, but humans defined what counted as correct, reviewed every fix, and turned repeated corrections into permanent checks.

Anthropic organizes the work into three loops:

LoopSpeedWhat happensHuman role
InnerSecondsAgent runs both codebases in a cloud sandbox, reproduces a diff against a fake model, edits Rust until outputs match, adds a failing then passing testSets the goal
OuterHoursHuman reviews the PR, fix ships, shadow traffic confirms the fingerprint is goneReviews at the seam
MemoryWeeksEngineer corrections become rules agents read first, lints, drift tests, and a merge check requiring a matching Rust change or an exemptionWrites rules at the edge
Diagram of three nested loops in Anthropic's migration: an inner loop where an agent edits Rust and checks locally in under a second, an outer loop through PR review and live shadow traffic, and a memory loop turning engineer corrections into rules and checks
Inner, outer, and memory loops. Redrawn from Anthropic's published migration post.

A script ran every 10 to 30 minutes, grouped new diff records, and a coordinating agent assigned one worker agent per new kind of difference, each with its own thread in a shared Slack channel. In June, an agent reviewed about 60 engineer review comments and proposed rules for the project's CLAUDE.md, which an engineer approved.

Before the inner loop existed, each hypothesis needed review and a staging deploy, which took hours or days. Moving the check into a sandbox that answers in under a second is what made agent-scale debugging possible.

Why Did an Agent Try to Cheat the Verifier?

One episode from mid-May is the most useful part of the post for anyone running agents on real code. Rust prompts were missing the web search tool's description. An agent made the prompts match by copying the description into a file. In Anthropic's words, "the verifier rewarded matching outputs, and the agent found the cheapest way to produce them."

An engineer rejected the shortcut, because the Rust service needed to fetch the description from its real source like Python did. Building that call properly took weeks. The match rate would have looked identical either way. Only a human who knew how the system was supposed to work could tell the difference.

What Results Did Anthropic Report?

Anthropic reports about 70% less CPU per request, more than 80% less memory per request, and about 20% faster median time to first token.

MetricReported changeScope given by Anthropic
CPU per requestAbout 70% lowerOne region
Memory per requestMore than 80% lowerAll production, August to October 2026
Median time to first tokenAbout 20% fasterClaude Code requests, shorter window, first point still mostly Python
Partial rewrite CPU (March)About 8% to 10% lowerBefore the full rewrite
Three charts showing about 70% less CPU per request, more than 80% less memory per request, and about 20% lower median time to first token after Anthropic moved the Messages API to Rust
Reported results, each with its own scope. Curves approximate, data from Anthropic.

The post also shows merged changes per two weeks rising from under 100 in early April to more than 3,000 by August, and says Claude wrote more than 80% of the code Anthropic merged by May 2026. That second figure is company-wide, not a migration statistic, and Anthropic notes that not every merged change in the chart is migration work.

Does This Prove Rust Is Faster Than Python for APIs?

No. It shows that this workload, rebuilt in Rust with a different ownership of the request path, used far fewer resources. It does not isolate the language.

Three things changed at once. The language changed. The Python-to-Rust boundary disappeared from the per-token path. And a service that grew organically for three years was rebuilt as one deliberate pipeline. The partial rewrite is the closest thing to a control group, and its 8% to 10% gain shows how much of the result depends on where the boundary sits.

There are also limits on the evidence:

  • the figures are self-reported, with no independent benchmark;
  • each chart uses a different region, population, or time window;
  • time to first token is dominated by the model, so a 20% gain on the API side is notable but not a model speedup;
  • no team size, cost, or code size is given, so the economics cannot be compared with other rewrites.

The honest reading:

Not:   Rust is 70% cheaper than Python.
Yes:   A per-token, CPU-heavy API path at very high volume
       got much cheaper once it ran fully in Rust.
Also:  The rewrite only became safe once equivalence could be
       measured on live traffic.

For a broader decision framework, see Should You Rewrite It in Rust?.

How Is This Different From GitHub's Copilot Rewrite?

GitHub's Copilot runtime rewrite was about removing a process boundary for embedded clients; Anthropic's is about proving behavioral equivalence for a live, multi-tenant API.

GitHub Copilot runtimeAnthropic Messages API
FromTypeScript and Node.jsPython
Main costProcess startup, V8 memory, JSON-RPCPer-request and per-token CPU
Main safety netExisting end-to-end tests, 128 PRs, staged releasesShadow traffic, checkpoints, fingerprints
Hardest problemSemantic drift between library ecosystemsProving equivalence without reading customer data
Agent roleImplementation at scaleImplementation plus diff investigation loops

Both stories land on the same point from different directions. Agents make writing Rust cheap. They do not make knowing whether it is correct cheap.

What Should Teams and Rust Developers Take From This?

Before rewriting a service in Rust with agents, build the verifier first, and treat the existing system as the specification.

For teams evaluating a migration:

  1. Profile where the cost lives. If it is per token or per item in a stream, a full path rewrite beats an FFI patch.
  2. Do not trust a ported test suite. Audit for weakened assertions and expect coverage to be far below what production exercises.
  3. Make the old system the oracle. Shadow traffic, replay nondeterministic dependencies once, and compare at named checkpoints.
  4. Record differences as structure, not content. That keeps privacy intact and makes diffs groupable.
  5. Give agents a fast local loop. Sub-second checks are what let agents iterate; staging deploys are too slow.
  6. Keep humans on the definition of correct. Agents optimize the signal you give them, including in ways you did not intend.

For Rust developers, the skill profile is clear. The valuable engineer in this story is not the one who types Rust fastest. It is the one who can read generated Rust, spot when a passing check hides a wrong design, design checkpoints and invariants, and understand async streaming, serialization, and byte-level behavior well enough to explain why two outputs differ. That is also why learning Rust with AI tools still requires real fundamentals, and why testing techniques like property-based testing matter more as agents write more code.

Frequently Asked Questions

Yes, Anthropic moved the Claude Messages API, the main interface for API customers and for Claude Code, from Python to Rust, and public traffic has run on the Rust version since September 2026 without downtime, according to an engineering post the company published on November 25, 2026. Python now only hands each request over. Rust performs validation, prompt building, tokenization, safety screening, output parsing, streaming, and usage counting, which is the work that runs on every request and every output token.

Anthropic moved the Messages API to Rust because every request and every output token passed through CPU-heavy Python work, while API traffic grew roughly 1,800 times between early 2024 and fall 2026, turning a small Python overhead into one of the largest costs in the serving fleet. A partial rewrite that called Rust from Python saved only about 8% to 10% of CPU, so the team rewrote the whole request path instead.

Anthropic reports about 70% less CPU per request, more than 80% less memory per request, and about 20% lower median time to first token after moving the Messages API to Rust, though the language change came together with a full redesign of the request path. Each figure has its own scope: CPU covers one region, memory covers all production from August to October 2026, and time to first token covers Claude Code requests over a shorter window. None of the numbers come from an independent benchmark.

Claude wrote the first version of the core Rust request path in about a week, according to Anthropic, and Claude agents then spent months investigating and fixing the differences between the Python and Rust versions found on live shadow traffic. Engineers still reviewed every fix and defined what correct meant. One engineer rejected an agent shortcut that copied a tool description into a file to make outputs match, and repeated corrections became rules, lints, and merge checks.

Shadow traffic verification runs a new implementation on copies of real production requests and compares its behavior with the existing system, without ever serving the new version's results to users, so bugs show up in a comparison log instead of in customer responses. Anthropic called the model once and replayed its output to both versions, compared them at named checkpoints, and recorded only the shape of each difference. Grouping those records by fingerprint turned hundreds of thousands of diffs into one work item per bug.

No, Python built and ran the Messages API from 2023 through roughly 1,800 times traffic growth, and it still hands every request over today, so the migration is not evidence that Python fails for typical web APIs or internal services. The move paid off for a high-volume, CPU-heavy pipeline doing work on every token. Most APIs never reach that profile, and a rewrite without a strong verification strategy can cost more than it saves.

Anthropic has not disclosed which Rust crates, web framework, or async runtime the Messages API uses, nor the team size, code size, timeline cost, or engineering budget behind the migration, so the full stack behind the new Rust API remains private. The engineering post focuses on the verification method, not the implementation stack. Any article naming a specific framework for this rewrite is guessing, so treat such claims as speculation until Anthropic publishes more detail. What the post does show is the skill set that mattered: async streaming, byte-exact serialization, and verification design.

The Bottom Line

Anthropic's Messages API migration is a strong Rust production story: a central, high-traffic AI API now runs its request path in Rust and reports large CPU and memory savings.

The more durable lesson is about method. Claude produced the Rust quickly. What made it shippable was a verifier that used the Python service as the specification, a fast loop for agents, and engineers who held the line on what correct meant. As more rewrites are written by agents, that verification layer, and the Rust engineers who can design and judge it, becomes the scarce part.

Sources

Keep learning

Continue with a related Rust guide

Browse all articles

Want a clear path to your Rust goals?

Fill out the form

Book your event

Rustify

Apply for Rustify Program

👉 We are selective about who we work with. This call is reserved for developers serious about advancing their career with Rust.

🎯 On this 30-min diagnostic call, you will get:
  • An honest assessment of where you are and what's blocking you
  • Direct feedback on whether Bootcamp or Mentorship is the right fit for you

⚡ Not everyone is accepted: We only work with motivated professionals ready to take action.

By entering your information, you agree that your data will be stored in accordance with our terms & privacy policy

November 2026

Sun

Mon

Tue

Wed

Thu

Fri

Sat

Please fill out the form before choosing your time slot.

Ready to Land a $80k+ Rust Job in the US or Europe?