hn.today

Anthropic migrated Messages API to Rust with no Rust developers

anthropic.com8 points0 comments
Screenshot of Anthropic migrated Messages API to Rust with no Rust developers

Anthropic replaced the Python core of its Messages API with Rust despite having no Rust developers, using Claude to generate most of the implementation. The API serves customers and Anthropic products, and traffic had grown roughly 1,800-fold from early 2024 to fall 2026. Python’s overhead had become costly across request validation, prompt construction, tokenization, safety checks, and streaming responses. An initial partial rewrite cut CPU use by 8-10%, but added complexity as tokens repeatedly crossed between Python and Rust. A full migration promised greater efficiency, yet correctness was difficult to establish: the Python service continued to change, model responses were nondeterministic, and customer requests could not be inspected.

The team treated the live Python API as a verifier, shadowing production traffic and comparing the old and new systems. Existing tests were not enough: roughly 700 integration tests were tied to Python, more than 100 assertions had been weakened during porting, and the suite missed many real-world combinations. Although Rust passed about 98% of tests, only around a quarter of production inputs initially matched. Anthropic built automated comparison and repair loops that identified discrepancies and dispatched Claude agents to fix them, then repeated the checks as the service evolved. The match rate ultimately reached 99.6%. The migration was deployed without taking the service offline or pausing feature work, reducing CPU per request by about 70% and median time to first token by roughly 20%.

Read on anthropic.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.