fix(anthropic): preserve pi-ai default betas when injecting anthropic-beta header#19789
Merged
Takhoffman merged 2 commits intoopenclaw:mainfrom Feb 20, 2026
Merged
Conversation
Contributor
Author
|
The |
4b2db90 to
6d196af
Compare
…-beta header When injecting anthropic-beta via options.headers (e.g. for context1m), pi-ai's mergeHeaders uses Object.assign (last-wins), which overwrites the hardcoded defaultHeaders["anthropic-beta"] set by createClient. This strips critical betas like oauth-2025-04-20 for OAuth tokens, causing HTTP 401 errors. Fix by detecting the token type (sk-ant-oat-* prefix for OAuth) and pre-seeding the appropriate pi-ai default betas before merging, ensuring they survive the Object.assign overwrite. Fixes openclaw#19769
c8d33c6 to
41dfb38
Compare
Contributor
|
PR #19789 - fix(anthropic): preserve pi-ai default betas when injecting anthropic-beta header (#19789) Merged via squash.
Thanks @minupla! |
anisoptera
pushed a commit
to anisoptera/openclaw
that referenced
this pull request
Feb 20, 2026
…-beta header (openclaw#19789) thanks @minupla Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: minupla <42547246+minupla@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
mmyyfirstb
pushed a commit
to mmyyfirstb/openclaw
that referenced
this pull request
Feb 21, 2026
…-beta header (openclaw#19789) thanks @minupla Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: minupla <42547246+minupla@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
zooqueen
pushed a commit
to hanzoai/bot
that referenced
this pull request
Mar 6, 2026
…-beta header (openclaw#19789) thanks @minupla Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: minupla <42547246+minupla@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
hnykda
added a commit
to hnykda/openclaw
that referenced
this pull request
Mar 9, 2026
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>
3 tasks
Baelson
added a commit
to Baelson/openclaw
that referenced
this pull request
Apr 2, 2026
…efactor The extension refactor (59c23de) moved stream wrappers into the Anthropic plugin but broke two assumptions from the original OAuth fix (openclaw#19789): 1. The beta wrapper was only applied when user-configured betas were present, so PI_AI_DEFAULT/OAUTH_ANTHROPIC_BETAS were never injected for users without explicit beta config (openclaw#41444). 2. options.apiKey is always undefined at the wrapper layer in production — the apiKey is resolved deeper in sdk.js — so isAnthropicOAuthApiKey() always returned false, selecting the wrong beta set (openclaw#57292). Fix: always apply the beta wrapper for Anthropic, detect OAuth at setup time from auth profile config, and pass the flag to the wrapper. The runtime options.apiKey check is kept as a fallback for callers that still pass it. Closes openclaw#57292 Closes openclaw#41444 Related openclaw#19789
Closed
25 tasks
Open
3 tasks
lovewanwan
pushed a commit
to lovewanwan/openclaw
that referenced
this pull request
Apr 28, 2026
…-beta header (openclaw#19789) thanks @minupla Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: minupla <42547246+minupla@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This was referenced Apr 30, 2026
ogt-redknie
pushed a commit
to ogt-redknie/OPENX
that referenced
this pull request
May 2, 2026
…-beta header (openclaw#19789) thanks @minupla Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: minupla <42547246+minupla@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
May 9, 2026
…-beta header (openclaw#19789) thanks @minupla Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: minupla <42547246+minupla@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.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.
Problem
After #19769 was reported, updating to v2026.2.17 causes all Anthropic API calls to fail with HTTP 401 when using an OAuth token (
sk-ant-oat-*).Root cause: When the
context1mfeature injectsanthropic-betaviaoptions.headers,pi-ai'smergeHeadersusesObject.assign(last-wins). This overwritescreateClient's hardcodeddefaultHeaders["anthropic-beta"], stripping required betas likeoauth-2025-04-20. Without that beta, Anthropic rejects OAuth Bearer auth with a 401.Fix
sk-ant-oatprefixPI_AI_DEFAULT_ANTHROPIC_BETASorPI_AI_OAUTH_ANTHROPIC_BETAS) before merging custom betasSetto avoid duplicate entriesTests
Added a test case covering the OAuth token path with
context1menabled, verifying thatoauth-2025-04-20andclaude-code-20250219survive the header merge.Fixes #19769
Greptile Summary
Fixes a critical regression where
context1mfeature injection of theanthropic-betaheader viaoptions.headerswould overwrite pi-ai's hardcodeddefaultHeaders["anthropic-beta"](due toObject.assignlast-wins in pi-ai'smergeHeaders), stripping required betas likeoauth-2025-04-20and causing HTTP 401 for OAuth token users.PI_AI_DEFAULT_ANTHROPIC_BETASandPI_AI_OAUTH_ANTHROPIC_BETASconstants mirroring pi-ai's internal defaults, pre-seeded into the merged beta header to prevent overwriteoptions?.apiKeyprefix matching to select the appropriate beta setSetto avoid redundant entriescontext1menabledConfidence Score: 4/5
Last reviewed commit: 4b2db90
(2/5) Greptile learns from your feedback when you react with thumbs up/down!
Context used:
dashboard- CLAUDE.md (source)dashboard- AGENTS.md (source)