diff --git a/.review/pr-8274 b/.review/pr-8274 new file mode 160000 index 0000000000..e46929b8d8 --- /dev/null +++ b/.review/pr-8274 @@ -0,0 +1 @@ +Subproject commit e46929b8d8add0cd3c412d69f8ac882c405a4ba9 diff --git a/src/api/providers/__tests__/anthropic.spec.ts b/src/api/providers/__tests__/anthropic.spec.ts index 7b74c87dfc..1b8e30b9ca 100644 --- a/src/api/providers/__tests__/anthropic.spec.ts +++ b/src/api/providers/__tests__/anthropic.spec.ts @@ -265,13 +265,14 @@ describe("AnthropicHandler", () => { expect(result.temperature).toBe(0) }) - it("should handle Claude 4.5 Sonnet model correctly", () => { + it("should handle Claude 4.5 Sonnet model correctly and convert ID to API format", () => { const handler = new AnthropicHandler({ apiKey: "test-api-key", apiModelId: "claude-4.5-sonnet", }) const model = handler.getModel() - expect(model.id).toBe("claude-4.5-sonnet") + // The model ID should be converted to the format expected by Anthropic API + expect(model.id).toBe("claude-sonnet-4-5") expect(model.info.maxTokens).toBe(64000) expect(model.info.contextWindow).toBe(200000) expect(model.info.supportsReasoningBudget).toBe(true) diff --git a/src/api/providers/anthropic.ts b/src/api/providers/anthropic.ts index 80ef572b5b..7dc0190545 100644 --- a/src/api/providers/anthropic.ts +++ b/src/api/providers/anthropic.ts @@ -45,15 +45,23 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa const cacheControl: CacheControlEphemeral = { type: "ephemeral" } let { id: modelId, betas = [], maxTokens, temperature, reasoning: thinking } = this.getModel() + // Store the original model ID for switch statements + const originalModelId = modelId + + // Convert claude-4.5-sonnet to the format expected by Anthropic API + if (modelId === "claude-4.5-sonnet") { + modelId = "claude-sonnet-4-5" as any + } + // Add 1M context beta flag if enabled for Claude Sonnet 4 and 4.5 if ( - (modelId === "claude-sonnet-4-20250514" || modelId === "claude-4.5-sonnet") && + (originalModelId === "claude-sonnet-4-20250514" || originalModelId === "claude-4.5-sonnet") && this.options.anthropicBeta1MContext ) { betas.push("context-1m-2025-08-07") } - switch (modelId) { + switch (originalModelId) { case "claude-4.5-sonnet": case "claude-sonnet-4-20250514": case "claude-opus-4-1-20250805": @@ -113,7 +121,7 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa // https://github.com/anthropics/anthropic-sdk-typescript/commit/c920b77fc67bd839bfeb6716ceab9d7c9bbe7393 // Then check for models that support prompt caching - switch (modelId) { + switch (originalModelId) { case "claude-4.5-sonnet": case "claude-sonnet-4-20250514": case "claude-opus-4-1-20250805": @@ -275,8 +283,18 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa // reasoning model and that reasoning is required to be enabled. // The actual model ID honored by Anthropic's API does not have this // suffix. + + // Map internal model IDs to Anthropic API model IDs + let apiModelId = id + if (id === "claude-3-7-sonnet-20250219:thinking") { + apiModelId = "claude-3-7-sonnet-20250219" + } else if (id === "claude-4.5-sonnet") { + // Convert claude-4.5-sonnet to the format expected by Anthropic API + apiModelId = "claude-sonnet-4-5" as AnthropicModelId + } + return { - id: id === "claude-3-7-sonnet-20250219:thinking" ? "claude-3-7-sonnet-20250219" : id, + id: apiModelId, info, betas: id === "claude-3-7-sonnet-20250219:thinking" ? ["output-128k-2025-02-19"] : undefined, ...params, diff --git a/tmp/pr-8287-Roo-Code b/tmp/pr-8287-Roo-Code new file mode 160000 index 0000000000..88a473b017 --- /dev/null +++ b/tmp/pr-8287-Roo-Code @@ -0,0 +1 @@ +Subproject commit 88a473b017af37091c85ce3056e444e856f80d6e