fix: always apply Anthropic beta headers wrapper for OAuth token support#289
Open
BingqingLyu wants to merge 1 commit intomainfrom
Open
fix: always apply Anthropic beta headers wrapper for OAuth token support#289BingqingLyu wants to merge 1 commit intomainfrom
BingqingLyu wants to merge 1 commit intomainfrom
Conversation
The `createAnthropicBetaHeadersWrapper` was only applied when `resolveAnthropicBetas` returned non-empty (i.e., when `context1m` or `anthropicBeta` was set in agent extra params). When `context-1m` was configured via model-level headers instead of extra params, the wrapper was never applied, so the critical `oauth-2025-04-20` beta was never injected for OAuth tokens (`sk-ant-oat-*`). This caused Anthropic to reject all requests with HTTP 401 "OAuth authentication is currently not supported." Now the wrapper is always applied for Anthropic providers, ensuring OAuth token detection and beta injection runs unconditionally. Fixes openclaw#41444 Related: openclaw#19769, openclaw#19789 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
createAnthropicBetaHeadersWrapperfor Anthropic providers, not just whenresolveAnthropicBetas()returns non-emptyoauth-2025-04-20beta is injected for OAuth tokens (sk-ant-oat-*) even whencontext1mis configured via model-levelheadersinstead of agent extra paramsProblem
When
context-1m-2025-08-07is set inmodels.providers.anthropic.models[].headers(model-level) rather than inagents.defaults.models[].params.context1m(extra params),resolveAnthropicBetas()returnsundefined, socreateAnthropicBetaHeadersWrapperis never applied. The pi-ai SDK detects thesk-ant-oatprefix and usesAuthorization: Bearer, but without the requiredoauth-2025-04-20beta header, Anthropic rejects with:The fix from openclaw#19789 correctly handles this inside the wrapper, but the wrapper was gated behind a non-empty betas check that prevented it from running.
Changes
extra-params.ts: Always apply the beta headers wrapper forprovider === "anthropic", passing an empty array when no explicit betas are configured. The wrapper's internal OAuth detection then runs unconditionally.pi-embedded-runner-extraparams.test.ts: Updated existing test and added new test for OAuth tokens withoutcontext1mconfigured.Test plan
sk-ant-oattokens even withoutcontext1mFixes openclaw#41444
Related: openclaw#19769, openclaw#19789
🤖 Generated with Claude Code