-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
OAuth 401 regression: oauth-2025-04-20 beta not injected when context1m set via model headers #41444
Copy link
Copy link
Open
BingqingLyu/openclaw
#289Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.staleMarked as stale due to inactivityMarked as stale due to inactivity
Description
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.staleMarked as stale due to inactivityMarked as stale due to inactivity
Type
Fields
Priority
None yet
Summary
When the Anthropic API key is an OAuth token (
sk-ant-oat-*), requests fail with HTTP 401 ifcontext-1m-2025-08-07is configured via model-level headers rather than via agent extra params (context1m: true). Theoauth-2025-04-20beta header is never injected, causing Anthropic to reject the Bearer auth.Environment
sk-ant-oat01-*(OAuth access token)Error
The error is misleading — OAuth IS supported, but requires the
oauth-2025-04-20beta header.Root Cause Analysis
The fix from #19789 correctly handles OAuth tokens inside
createAnthropicBetaHeadersWrapper, but this wrapper is only applied whenresolveAnthropicBetas()returns a non-empty array:If
context-1mis configured via the model provider definition (models.providers.anthropic.models[].headers):{ "id": "claude-opus-4-6", "headers": { "anthropic-beta": "context-1m-2025-08-07" } }...instead of via agent extra params (
agents.defaults.models[].params.context1m: true), then:resolveAnthropicBetas()returnsundefined(no extraParams match)createAnthropicBetaHeadersWrapperis never appliedoauth-2025-04-20beta is never injectedsk-ant-oat→ usesAuthorization: Bearerheaderswithanthropic-beta: context-1m-2025-08-07overwrite the SDK's default headers viaObject.assign, stripping the OAuth betaReproduction
Confirmed via direct curl from the container:
Suggested Fix
The
oauth-2025-04-20beta should be injected unconditionally whenever ansk-ant-oattoken is detected, not only whencreateAnthropicBetaHeadersWrapperhappens to be applied. The OAuth beta injection should be independent ofresolveAnthropicBetas.Either:
createAnthropicBetaHeadersWrapperfor Anthropic providers (even with empty betas), so the OAuth detection logic always runsoauth-2025-04-20regardless of other beta configurationWorkaround
Move
context-1mfrom model-level headers to agent extra params:Related
🤖 Generated with Claude Code