Anthropic Migrated Its Messages API to Rust With Claude Agents, Cutting CPU 70%
On this page 9 sections
TL;DR
Anthropic's Messages API, the service every request to Claude passes through, now runs on Rust, and the company has published the full engineering account of how it got there. Claude agents wrote the first version of the core request path in about a week. Proving that version behaved exactly like the Python original took months of shadowed production traffic, and the agents did most of the fixing: reproducing mismatches, editing code, opening pull requests, with a person reviewing every merge. The cutover finished in September 2026 with the service never offline, and the Rust version uses about 70 percent less CPU per request, more than 80 percent less memory, and cuts median time to first token by about 20 percent.
The front door outgrew its frame
The Messages API went up in 2023, and one of its early engineers called it "basically a request forwarder". By late 2025 every request had to be validated, converted into a prompt, tokenized, and screened by safety classifiers, and every reply sorted into text, thinking, and tool calls while it streamed. Python charged overhead at each of those steps, and traffic had grown roughly 1,800 times from early 2024 to fall 2026. At that scale, a per-request tax is a line item.
The cautious route came first. In March 2026 the team rewrote just the output parsing in Rust and called it from Python, which cut CPU use 8 to 10 percent and made every token cross between the languages three times. They judged the complexity not worth the gain. The post also preserves a 2024 internal verdict: "We are not rewriting the API in go or rust!" It aged about two years.
What changed the calculus was Claude itself: by May 2026 it was writing more than 80 percent of the code Anthropic merged. Writing the code had stopped being the expensive part, so the team took on the full rewrite and moved the risk somewhere else.
The test suite said 98 percent. Production said 24.
The service had about 700 integration tests, and they were the obvious verifier. Two problems. The tests ran the Python API inside the test process with billing and rate limiting mocked in memory, so they were coupled to the implementation they were meant to judge, and Claude helped port them, which meant a pass could mean correct code or a loosened test. An audit of the ported tests found more than 100 weakened assertions.
The suite was also small against the feature space. Twenty binary options produce over a million combinations, which is twelve days of tests at one per second for a single model, before varying the prompts inside them. In April the Rust API passed about 98 percent of its tests. On shadowed production traffic it matched about 24 percent of inputs.
Production also weights bugs by frequency, which a suite never does: one common bug fires in every request that triggers it. Some mismatches were a few bytes of prompt. When Python serializes JSON tool calls it escapes certain characters, an emoji for instance, into text codes; Rust wrote them raw, the request still succeeded, and the model still answered, slightly differently. Bugs the post names from live comparison include a 1M-token context limit read as 200K, a missing tool description, and missing usage fields.
The old API became the oracle
Shadowing is the standard move here: run each request through old and new code and compare the results. Two things broke the standard version. Claude answers nondeterministically, so two different replies do not imply a bug, and a replayed request would count twice against a customer's limits and bill. Anthropic ran the model once and replayed its output into the Rust path, then compared every step before and after the model call, exactly.
The privacy rule made comparison harder. Nobody could read customer requests or replies, so differences had to be described without their text. Checkpointing recorded the first step where the two versions diverged, plus the prompt piece and the first differing byte. Fingerprints combined position and length gap so one bug's records cluster together.
A bug leaves the same fingerprint on every request it touches, the way a scratched die prints the same nick into the same corner of every page it prints. You can sort a million pages by nick without reading a word on them.
step: build prompt
piece: 2
first diff: byte 17
python: 190 bytes
rust: 190 bytes
One record, with the post's illustrative values. Enough for an agent to work from, not enough to reconstruct the request. Off-the-shelf diff tools mostly assume a deterministic service or a safe double-run; GitHub's Scientist pattern and X's Diffy both sit in that camp, and neither assumption held here.
Agents on a leash made of diffs
A script ran every 10 to 30 minutes, grouped the diff records by which fields differed, and alerted a coordinating Claude agent only when a new kind appeared. The coordinator assigned a worker agent to own each new kind and opened a Slack thread where engineers could follow and steer.
Workers lived in a sandbox holding both codebases. The input check built the prompt each version would send and showed the diff without calling the model, in under a second; the output check pushed a scripted reply through both versions against a fake model. From a fingerprint the agent guessed the cause, wrote a request meant to trigger it, and read its own results in full, the one place reading was allowed. When both versions matched, it opened a pull request with a test that failed on the old code.
Human review sat at the seam between sandbox and production. In mid-May one of the largest remaining gaps was the web search tool's description, which the Rust path did not fetch from the internal service that supplies it. An agent proposed copying the text into files Rust could read; the local verifier passed the fix, and an engineer rejected it as throwaway code, because Rust had to call the service before launch anyway. The verifier rewards matching outputs and cannot tell a durable fix from a shortcut.
The rejection became a memory note holding the decision, the reason, and the correct fix. Later records from the same missing text, some with new fingerprints, got linked to the known bug instead of attracting fresh workarounds. A rule to port exactly what Python did let an agent find seven more places where the port had guessed at behavior. In June an agent read about 60 review comments, grouped the recurring problems, and drafted rules an engineer approved into CLAUDE.md. The loop finished in permanent checks: drift tests, lints, and a merge check requiring anyone changing Python to make the matching Rust change or request an exemption.
What shipped
Public traffic moved to the Rust service in September 2026, with the service never offline and feature development never frozen. CPU per request fell about 70 percent and memory per request by more than 80. Median time to first token dropped about 20 percent, measured on Claude Code requests between roughly September 7 and 21.
The merge rate tells the same story from another angle. Changes to the API's Rust code climbed from under 100 per two-week period in early April to more than 3,000 in the period starting August 10, and the post notes those counts are not all migration work.
What to steal if you maintain a live system
- Move the risk into verification. Code generation is cheap now; an honest, fast oracle is the scarce part, and it is worth building on purpose.
- Treat the old system as the spec when tests are coupled to it. In-process mocks and ported tests can agree with wrong code; live traffic cannot be argued with.
- Run the expensive thing once. One model call, replayed into both paths, removes nondeterminism and double billing in a single move.
- Design the diff before dispatching agents. Checkpoints say where to look, fingerprints say which bug it is, and a coordinator that wakes only on new kinds keeps the fleet cheap.
- Put humans at the seam and write their verdicts down. Review decides what ships; the memory loop is what stops the same review happening twice.
Caveats
- Every number here is Anthropic measuring its own system and publishing it itself; the CPU, memory, and TTFT figures have no third-party audit.
- The time-to-first-token result covers Claude Code requests over roughly two weeks in September. Your traffic mix will differ.
- The parity curve between its three stated points is drawn for shape in the figure above; the post's own chart is the authority.
- The merged-change counts include non-migration work, as the post states.
Key Takeaways
- Anthropic moved the Messages API, the front door for every request to Claude, from Python to Rust, cutting CPU per request about 70 percent, memory per request more than 80 percent, and median time to first token about 20 percent.
- Claude wrote the first version of the core request path in about a week; verification against shadowed production traffic ran until August, with input parity climbing from 24 percent to 99.6.
- Tests were the weak link: about 700 integration tests coupled to the Python implementation, an audit finding more than 100 weakened assertions, and a 98 percent pass rate coexisting with 24 percent production parity.
- Privacy shaped the design. Differences were logged as shapes (step, piece, first byte, lengths), never text, so agents fixed bugs in traffic nobody read.
- A coordinator agent grouped diffs every 10 to 30 minutes, workers reproduced and fixed them in a sandbox, human review approved every merge, and corrections became rules in CLAUDE.md, lints, and drift tests.
- The cutover completed in September 2026 with no downtime; merged changes per two-week period rose from under 100 in April to more than 3,000 by mid-August.
Sources: Anthropic engineering post, Migrating our Messages API to Rust, Nov 25, 2026, Messages API documentation, MLQ.ai coverage with figures, Nov 25, 2026, The Next Web coverage, Nov 25, 2026