fix: strip variant suffix from model ID for OAuth Anthropic API calls

Model variants like `claude-opus-4-6[1m]` use bracket suffixes to
differentiate context window configurations internally, but the
Anthropic API only accepts base model IDs (e.g. `claude-opus-4-6`).

Sending the full variant ID via OAuth (Claude Max/Pro) causes a 404:
  {"type":"not_found_error","message":"model: claude-opus-4-6[1m]"}

Strip any `[...]` suffix from model.id for OAuth requests only.
API key auth is left unchanged since the behavior there is unverified.
This commit is contained in:
vp275 2026-03-14 16:35:04 +05:30
parent 714712b7f3
commit 03c48efbad

View file

@ -637,8 +637,12 @@ function buildParams(
options?: AnthropicOptions,
): MessageCreateParamsStreaming {
const { cacheControl } = getCacheControl(model.baseUrl, options?.cacheRetention);
// For OAuth (Claude Max/Pro), strip variant suffixes like [1m] from model ID.
// The API only accepts the base model ID (e.g. "claude-opus-4-6"),
// not internal variant identifiers (e.g. "claude-opus-4-6[1m]").
const apiModelId = isOAuthToken ? model.id.replace(/\[.*\]$/, "") : model.id;
const params: MessageCreateParamsStreaming = {
model: model.id,
model: apiModelId,
messages: convertMessages(context.messages, model, isOAuthToken, cacheControl),
max_tokens: options?.maxTokens || (model.maxTokens / 3) | 0,
stream: true,