fix(agent): strip x-stainless headers from OAuth Anthropic requests to prevent 429 - #70054
Closed
x7peeps wants to merge 1 commit into
Closed
fix(agent): strip x-stainless headers from OAuth Anthropic requests to prevent 429#70054x7peeps wants to merge 1 commit into
x7peeps wants to merge 1 commit into
Conversation
… to prevent 429 Fix NousResearch#70039 Anthropic's Python SDK automatically injects x-stainless-* headers (language, runtime, OS, package version) into every request. Anthropic's infrastructure uses these headers as a fingerprint to differentiate "Claude Code CLI" (which uses axios) from "third-party SDK" requests. When a subscription OAuth token is used through Hermes, the presence of these SDK headers causes Anthropic to apply stricter rate-limit tiers, resulting in persistent HTTP 429 errors — even when the User-Agent, x-app, and anthropic-beta headers match Claude Code's fingerprint exactly. Fix: For OAuth token auth, route requests through a custom httpx.Client with a request event hook that strips all x-stainless-* headers before they go on the wire. This makes the HTTP request indistinguishable from the genuine Claude Code CLI's traffic, allowing subscription tokens to work through the native adapter. The pattern mirrors the existing Azure Entra ID bearer hook (_build_anthropic_client_with_bearer_hook) already in the codebase.
This was referenced Jul 27, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Fixes #70039: Anthropic subscription OAuth token gets generic 429 through Hermes, while the genuine Claude Code binary works with the same token.
Root Cause Analysis
The Anthropic Python SDK automatically injects x-stainless-* headers into every request (x-stainless-lang, x-stainless-runtime, x-stainless-package-version, x-stainless-arch, x-stainless-os).
Claude Code CLI uses axios (Node.js) to send requests without these headers. Anthropic infrastructure uses these SDK headers as a fingerprint to distinguish Claude Code official client from third-party SDK requests, and applies stricter rate-limit tiers for subscription OAuth tokens.
Even when the User-Agent, x-app, and anthropic-beta headers match Claude Code fingerprint exactly, the presence of x-stainless-* headers causes Anthropic to classify the request as third-party SDK traffic, persistently returning HTTP 429 for subscription tokens.
Fix
In the build_anthropic_client OAuth token branch, route requests through a custom httpx.Client with a request event hook that strips all x-stainless-* headers before they go on the wire.
This makes the HTTP request indistinguishable from the genuine Claude Code CLI traffic, allowing subscription tokens to work through the native adapter.
The pattern mirrors the existing Azure Entra ID bearer hook (_build_anthropic_client_with_bearer_hook) already in the codebase.
Changes:
Verification
Closes #70039