fix(anthropic): strip context-1m beta on OAuth path#17442
Closed
SkylineAtDayAndNight wants to merge 2 commits into
Closed
fix(anthropic): strip context-1m beta on OAuth path#17442SkylineAtDayAndNight wants to merge 2 commits into
SkylineAtDayAndNight wants to merge 2 commits into
Conversation
…er subscriptions
Consumer Claude subscriptions (Pro/Max via OAuth) reject the
context-1m-2025-08-07 beta with HTTP 400 ("long context beta is not yet
available for this subscription") even on models that don't use 1M
context (e.g. Haiku 4.5). The header is rejected pre-routing, so requests
fail before reaching the model at all, blocking all OAuth users on
consumer-tier subscriptions regardless of which model they pick.
Strip context-1m-2025-08-07 from the OAuth path. Direct API-key callers
(console.anthropic.com) keep full _COMMON_BETAS — their gating policy
accepts the header as a no-op as documented in the comment block at
lines 220-233 of agent/anthropic_adapter.py.
Repro (with macOS keychain holding Claude Code OAuth):
hermes chat -q "hi" --provider anthropic \
--model claude-haiku-4-5-20251001
# → HTTP 400 "long context beta is not yet available for this subscription"
After fix: request reaches the routing layer, where the actual
subscription gating (e.g. extra-usage credits) surfaces a clear
user-facing message instead of the cryptic beta rejection.
d95bbcd to
16327db
Compare
…-beta # Conflicts: # tests/agent/test_anthropic_adapter.py
Author
|
Superseded by #17752 (merged 2026-04-29) which addresses the same consumer-subscription issue with reactive recovery — keeps 1M context for capable subscriptions and only strips the beta after a 400 rejection. Closing. |
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.
Summary
Consumer Claude subscriptions (Pro/Max via OAuth) reject the
context-1m-2025-08-07beta with HTTP 400 ("long context beta is not yet available for this subscription") even on models that don't use 1M context (e.g. Haiku 4.5). The header is rejected pre-routing, so requests fail before reaching the model at all — every Hermes user authenticating via the macOS keychain Claude Code OAuth path is blocked regardless of which model they pick.Repro
Root cause
agent/anthropic_adapter.py:234defines_COMMON_BETASwithcontext-1m-2025-08-07included unconditionally. The OAuth branch at line ~471 takescommon_betas + _OAUTH_ONLY_BETAS, never strips 1m, and sends it on every request.The existing comment block at lines 220-233 documents the header as "harmless no-op on endpoints where 1M is GA" — true for
console.anthropic.comAPI-key callers, but consumer-tier OAuth subscriptions enforce a stricter beta allowlist and reject unrecognized betas pre-routing.Fix
Mirror the
_requires_bearer_authpath's existing precedent for stripping incompatible betas — but for the OAuth branch, only strip_CONTEXT_1M_BETA:Direct API-key callers (
elsebranch) keep the full_COMMON_BETAS— their gating policy accepts the header as a no-op.Test plan
TestBuildAnthropicClient::test_oauth_strips_context_1m_beta— assertscontext-1m-2025-08-07absent from OAuth request headers, OAuth-only betas still presentpytest tests/agent/test_anthropic_adapter.py::TestBuildAnthropicClient -v→ 6/6 passpytest tests/agent/test_anthropic_adapter.py→ identical pre-existing failure set vsmain(19 unrelated keychain-mocking failures, 0 new failures introduced)hermes chat -q "..." --provider anthropic --model claude-haiku-4-5-20251001— error changes from"long context beta is not yet available for this subscription"to"Third-party apps now draw from your extra usage...", confirming the request now passes the beta-allowlist gate and reaches the actual subscription/usage layerScope notes (deliberately out)
model.context_1m: true) once we know whether any subscription tier actually unlocks 1M via OAuth.TestResolveAnthropicToken/TestReadClaudeCodeCredentials/TestRunOauthSetupTokenmock env vars andPath.home, but never mock_read_claude_code_credentials_from_keychain, so on developer machines with Claude Code logged in the subprocess returns a real token and tests fail. Happy to file a separate PR mocking the keychain read if maintainers want.