Skip to content

fix: always apply Anthropic beta headers wrapper for OAuth token support#289

Open
BingqingLyu wants to merge 1 commit intomainfrom
fork-pr-41461-fix-oauth-beta-unconditional
Open

fix: always apply Anthropic beta headers wrapper for OAuth token support#289
BingqingLyu wants to merge 1 commit intomainfrom
fork-pr-41461-fix-oauth-beta-unconditional

Conversation

@BingqingLyu
Copy link
Copy Markdown
Owner

@BingqingLyu BingqingLyu commented Apr 27, 2026

Summary

  • Always apply createAnthropicBetaHeadersWrapper for Anthropic providers, not just when resolveAnthropicBetas() returns non-empty
  • This ensures the oauth-2025-04-20 beta is injected for OAuth tokens (sk-ant-oat-*) even when context1m is configured via model-level headers instead of agent extra params

Problem

When context-1m-2025-08-07 is set in models.providers.anthropic.models[].headers (model-level) rather than in agents.defaults.models[].params.context1m (extra params), resolveAnthropicBetas() returns undefined, so createAnthropicBetaHeadersWrapper is never applied. The pi-ai SDK detects the sk-ant-oat prefix and uses Authorization: Bearer, but without the required oauth-2025-04-20 beta header, Anthropic rejects with:

HTTP 401 authentication_error: OAuth authentication is currently not supported.

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 for provider === "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 without context1m configured.

Test plan

  • All 67 existing tests pass
  • New test: OAuth betas injected for sk-ant-oat tokens even without context1m
  • Verified fix resolves the issue on a live deployment

Fixes openclaw#41444
Related: openclaw#19769, openclaw#19789

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth 401 regression: oauth-2025-04-20 beta not injected when context1m set via model headers

2 participants