From ec40a48750230cb7a8f1d8ae917fa8c6809cb246 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sun, 5 Apr 2026 08:19:59 +0000 Subject: [PATCH] fix: preserve custom model name in Anthropic provider instead of falling back to default --- src/api/providers/__tests__/anthropic.spec.ts | 33 +++++++++++++++++++ src/api/providers/anthropic.ts | 7 ++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/api/providers/__tests__/anthropic.spec.ts b/src/api/providers/__tests__/anthropic.spec.ts index 3731f3a068b..ea35e3cfec1 100644 --- a/src/api/providers/__tests__/anthropic.spec.ts +++ b/src/api/providers/__tests__/anthropic.spec.ts @@ -343,6 +343,39 @@ describe("AnthropicHandler", () => { expect(model.info.inputPrice).toBe(6.0) expect(model.info.outputPrice).toBe(22.5) }) + + it("should pass through custom/unknown model IDs instead of falling back to default", () => { + const handler = new AnthropicHandler({ + apiKey: "test-api-key", + apiModelId: "qwen/qwen3.6-plus", + }) + const model = handler.getModel() + expect(model.id).toBe("qwen/qwen3.6-plus") + // Should use default model info as fallback for unknown models + expect(model.info).toBeDefined() + expect(model.info.contextWindow).toBeDefined() + }) + + it("should use default model ID when no model ID is provided at all", () => { + const handler = new AnthropicHandler({ + apiKey: "test-api-key", + apiModelId: undefined, + }) + const model = handler.getModel() + expect(model.id).toBeDefined() + // Should fall back to anthropicDefaultModelId, not an empty string + expect(model.id).not.toBe("") + }) + + it("should preserve custom model ID when using custom base URL", () => { + const handler = new AnthropicHandler({ + apiKey: "test-api-key", + anthropicBaseUrl: "http://localhost:3000/api", + apiModelId: "my-custom-model", + }) + const model = handler.getModel() + expect(model.id).toBe("my-custom-model") + }) }) describe("reasoning block filtering", () => { diff --git a/src/api/providers/anthropic.ts b/src/api/providers/anthropic.ts index 1786a105a5e..a40f5cc37b9 100644 --- a/src/api/providers/anthropic.ts +++ b/src/api/providers/anthropic.ts @@ -334,8 +334,11 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa getModel() { const modelId = this.options.apiModelId - let id = modelId && modelId in anthropicModels ? (modelId as AnthropicModelId) : anthropicDefaultModelId - let info: ModelInfo = anthropicModels[id] + const isKnownModel = modelId !== undefined && modelId in anthropicModels + let id: string = isKnownModel ? (modelId as AnthropicModelId) : modelId || anthropicDefaultModelId + let info: ModelInfo = isKnownModel + ? anthropicModels[modelId as AnthropicModelId] + : anthropicModels[anthropicDefaultModelId] // If 1M context beta is enabled for supported models, update the model info if (