mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:38:27 +00:00
Providers: skip context1m beta for Anthropic OAuth tokens (#24620)
* Providers: skip context1m beta for Anthropic OAuth tokens * Tests: cover OAuth context1m beta skip behavior * Docs: note context1m OAuth incompatibility * Agents: add context1m-aware context token resolver * Agents: cover context1m context-token resolver * Commands: apply context1m-aware context tokens in session store * Commands: apply context1m-aware context tokens in status summary * Status: resolve context tokens with context1m model params * Status: test context1m status context display
This commit is contained in:
@@ -276,13 +276,25 @@ function createAnthropicBetaHeadersWrapper(
|
||||
): StreamFn {
|
||||
const underlying = baseStreamFn ?? streamSimple;
|
||||
return (model, context, options) => {
|
||||
const isOauth = isAnthropicOAuthApiKey(options?.apiKey);
|
||||
const requestedContext1m = betas.includes(ANTHROPIC_CONTEXT_1M_BETA);
|
||||
const effectiveBetas =
|
||||
isOauth && requestedContext1m
|
||||
? betas.filter((beta) => beta !== ANTHROPIC_CONTEXT_1M_BETA)
|
||||
: betas;
|
||||
if (isOauth && requestedContext1m) {
|
||||
log.warn(
|
||||
`ignoring context1m for OAuth token auth on ${model.provider}/${model.id}; Anthropic rejects context-1m beta with OAuth auth`,
|
||||
);
|
||||
}
|
||||
|
||||
// Preserve the betas pi-ai's createClient would inject for the given token type.
|
||||
// Without this, our options.headers["anthropic-beta"] overwrites the pi-ai
|
||||
// defaultHeaders via Object.assign, stripping critical betas like oauth-2025-04-20.
|
||||
const piAiBetas = isAnthropicOAuthApiKey(options?.apiKey)
|
||||
const piAiBetas = isOauth
|
||||
? (PI_AI_OAUTH_ANTHROPIC_BETAS as readonly string[])
|
||||
: (PI_AI_DEFAULT_ANTHROPIC_BETAS as readonly string[]);
|
||||
const allBetas = [...new Set([...piAiBetas, ...betas])];
|
||||
const allBetas = [...new Set([...piAiBetas, ...effectiveBetas])];
|
||||
return underlying(model, context, {
|
||||
...options,
|
||||
headers: mergeAnthropicBetaHeader(options?.headers, allBetas),
|
||||
|
||||
Reference in New Issue
Block a user