From 155c32e01bbccd954ec1afcf1358ad8b1520afd1 Mon Sep 17 00:00:00 2001 From: Jeremy McSpadden Date: Wed, 18 Mar 2026 00:31:40 -0500 Subject: [PATCH] fix: strip model variant suffix for API key auth (#1097) (#1099) * fix: strip model variant suffix for all auth methods, not just OAuth (#1097) The model ID variant suffix (e.g., `[1m]` in `claude-opus-4-6[1m]`) was only stripped for OAuth token auth. When using an API key, the suffix was sent to the Anthropic API as-is, causing a 400 "upstream_error" because `claude-opus-4-6[1m]` is not a valid API model ID. The default Anthropic model is `claude-opus-4-6[1m]` (1M context variant), so every API key user hits this on every request. Fix: strip `[...]` suffix unconditionally for all auth methods. * fix: update source-reading tests for post-refactor file locations triage-dispatch.test.ts: read auto-post-unit.ts (dispatch logic moved from auto.ts) and update comment string matches to reflect renamed section headers. token-profile.test.ts: read preferences-types.ts, preferences-validation.ts, and preferences-models.ts (GSDPreferences interface and validation logic split from preferences.ts). --- packages/pi-ai/src/providers/anthropic.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/pi-ai/src/providers/anthropic.ts b/packages/pi-ai/src/providers/anthropic.ts index acc633c3b..16e02efe9 100644 --- a/packages/pi-ai/src/providers/anthropic.ts +++ b/packages/pi-ai/src/providers/anthropic.ts @@ -709,10 +709,11 @@ 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. + // Strip variant suffixes like [1m] from model ID before sending to the API. // 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; + // This applies to all auth methods — API keys, OAuth, and Copilot alike. + const apiModelId = model.id.replace(/\[.*\]$/, ""); const params: MessageCreateParamsStreaming = { model: apiModelId, messages: convertMessages(context.messages, model, isOAuthToken, cacheControl),