coder-abu 7d45fea17e
fix(models): keep the OAuth betas when a Claude request sends its own betas (#8061)
* fix(models): keep the OAuth betas when a Claude request sends its own betas

ClaudeChatModel put the Claude Code OAuth betas (oauth-2025-04-20, ...)
only in the client's default anthropic-beta header. A request whose
payload carries betas is sent through beta.messages.create, and the
Anthropic SDK turns that list into a per-request anthropic-beta header
that replaces the default. So a configured betas list (even []),
per-call betas, or a server tool for which langchain-anthropic appends a
beta sent the request without oauth-2025-04-20, and Anthropic rejects
the Bearer token.

_get_request_payload now puts the OAuth betas first in any request betas
list before the thinking budget resolves the header. Requests without
betas keep the default header, and API-key models are unchanged. The
list is rebuilt because the payload's betas can be self.betas.

Fixes #8060

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(changelog): link the Claude OAuth betas fix to #8061

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(models): keep the OAuth betas in a caller's anthropic-beta extra header

The Anthropic SDK lets a request's extra_headers override both the
client default and the header built from betas. An anthropic-beta in
extra_headers, from model_kwargs or passed per call, therefore still
dropped the OAuth betas and Anthropic rejected the Bearer token.

_apply_oauth_betas now gives that header the same merge as betas: the
OAuth betas go first and the caller's betas follow without repeats.
The headers dict is copied because it can be the one in model_kwargs.
API-key models are unchanged.

Refs #8060

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: AochenShen99 <sac1063467113@hotmail.com>
2026-11-12 18:29:48 +08:00
..