diff --git a/packages/types/src/providers/bedrock.ts b/packages/types/src/providers/bedrock.ts index 6b8045911879..87e62e10458d 100644 --- a/packages/types/src/providers/bedrock.ts +++ b/packages/types/src/providers/bedrock.ts @@ -457,7 +457,6 @@ export const BEDROCK_REGIONS = [ { value: "us-gov-west-1", label: "us-gov-west-1" }, ].sort((a, b) => a.value.localeCompare(b.value)) -export const BEDROCK_CLAUDE_SONNET_4_MODEL_ID = "anthropic.claude-sonnet-4-20250514-v1:0" export const BEDROCK_1M_CONTEXT_MODEL_IDS = [ "anthropic.claude-sonnet-4-20250514-v1:0", "anthropic.claude-sonnet-4-5-20250929-v1:0", diff --git a/src/api/providers/__tests__/bedrock.spec.ts b/src/api/providers/__tests__/bedrock.spec.ts index 8df495ca9f5f..55317dac4009 100644 --- a/src/api/providers/__tests__/bedrock.spec.ts +++ b/src/api/providers/__tests__/bedrock.spec.ts @@ -25,7 +25,7 @@ vi.mock("@aws-sdk/client-bedrock-runtime", () => { import { AwsBedrockHandler } from "../bedrock" import { ConverseStreamCommand, BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime" -import { BEDROCK_CLAUDE_SONNET_4_MODEL_ID } from "@roo-code/types" +import { BEDROCK_1M_CONTEXT_MODEL_IDS } from "@roo-code/types" import type { Anthropic } from "@anthropic-ai/sdk" @@ -569,7 +569,7 @@ describe("AwsBedrockHandler", () => { describe("1M context beta feature", () => { it("should enable 1M context window when awsBedrock1MContext is true for Claude Sonnet 4", () => { const handler = new AwsBedrockHandler({ - apiModelId: BEDROCK_CLAUDE_SONNET_4_MODEL_ID, + apiModelId: BEDROCK_1M_CONTEXT_MODEL_IDS[0], awsAccessKey: "test", awsSecretKey: "test", awsRegion: "us-east-1", @@ -584,7 +584,7 @@ describe("AwsBedrockHandler", () => { it("should use default context window when awsBedrock1MContext is false for Claude Sonnet 4", () => { const handler = new AwsBedrockHandler({ - apiModelId: BEDROCK_CLAUDE_SONNET_4_MODEL_ID, + apiModelId: BEDROCK_1M_CONTEXT_MODEL_IDS[0], awsAccessKey: "test", awsSecretKey: "test", awsRegion: "us-east-1", @@ -614,7 +614,7 @@ describe("AwsBedrockHandler", () => { it("should include anthropic_beta parameter when 1M context is enabled", async () => { const handler = new AwsBedrockHandler({ - apiModelId: BEDROCK_CLAUDE_SONNET_4_MODEL_ID, + apiModelId: BEDROCK_1M_CONTEXT_MODEL_IDS[0], awsAccessKey: "test", awsSecretKey: "test", awsRegion: "us-east-1", @@ -644,7 +644,7 @@ describe("AwsBedrockHandler", () => { it("should not include anthropic_beta parameter when 1M context is disabled", async () => { const handler = new AwsBedrockHandler({ - apiModelId: BEDROCK_CLAUDE_SONNET_4_MODEL_ID, + apiModelId: BEDROCK_1M_CONTEXT_MODEL_IDS[0], awsAccessKey: "test", awsSecretKey: "test", awsRegion: "us-east-1", @@ -698,7 +698,7 @@ describe("AwsBedrockHandler", () => { it("should enable 1M context window with cross-region inference for Claude Sonnet 4", () => { const handler = new AwsBedrockHandler({ - apiModelId: BEDROCK_CLAUDE_SONNET_4_MODEL_ID, + apiModelId: BEDROCK_1M_CONTEXT_MODEL_IDS[0], awsAccessKey: "test", awsSecretKey: "test", awsRegion: "us-east-1", @@ -711,12 +711,12 @@ describe("AwsBedrockHandler", () => { // Should have 1M context window even with cross-region prefix expect(model.info.contextWindow).toBe(1_000_000) // Model ID should have cross-region prefix - expect(model.id).toBe(`us.${BEDROCK_CLAUDE_SONNET_4_MODEL_ID}`) + expect(model.id).toBe(`us.${BEDROCK_1M_CONTEXT_MODEL_IDS[0]}`) }) it("should include anthropic_beta parameter with cross-region inference for Claude Sonnet 4", async () => { const handler = new AwsBedrockHandler({ - apiModelId: BEDROCK_CLAUDE_SONNET_4_MODEL_ID, + apiModelId: BEDROCK_1M_CONTEXT_MODEL_IDS[0], awsAccessKey: "test", awsSecretKey: "test", awsRegion: "us-east-1", @@ -746,7 +746,7 @@ describe("AwsBedrockHandler", () => { // Should not include anthropic_version since thinking is not enabled expect(commandArg.additionalModelRequestFields.anthropic_version).toBeUndefined() // Model ID should have cross-region prefix - expect(commandArg.modelId).toBe(`us.${BEDROCK_CLAUDE_SONNET_4_MODEL_ID}`) + expect(commandArg.modelId).toBe(`us.${BEDROCK_1M_CONTEXT_MODEL_IDS[0]}`) }) }) }) diff --git a/src/api/providers/bedrock.ts b/src/api/providers/bedrock.ts index fc91dc2cb6dd..493c02483f16 100644 --- a/src/api/providers/bedrock.ts +++ b/src/api/providers/bedrock.ts @@ -21,7 +21,6 @@ import { BEDROCK_MAX_TOKENS, BEDROCK_DEFAULT_CONTEXT, AWS_INFERENCE_PROFILE_MAPPING, - BEDROCK_CLAUDE_SONNET_4_MODEL_ID, BEDROCK_1M_CONTEXT_MODEL_IDS, } from "@roo-code/types" @@ -373,7 +372,7 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH maxTokens: modelConfig.maxTokens || (modelConfig.info.maxTokens as number), temperature: modelConfig.temperature ?? (this.options.modelTemperature as number), } - + // Check if 1M context is enabled for Claude Sonnet 4 // Use parseBaseModelId to handle cross-region inference prefixes const baseModelId = this.parseBaseModelId(modelConfig.id) diff --git a/webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts b/webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts index 9d8c627b7fab..1157bdf2ee70 100644 --- a/webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts +++ b/webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts @@ -5,7 +5,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query" import { renderHook } from "@testing-library/react" import type { Mock } from "vitest" -import { ProviderSettings, ModelInfo, BEDROCK_CLAUDE_SONNET_4_MODEL_ID } from "@roo-code/types" +import { ProviderSettings, ModelInfo, BEDROCK_1M_CONTEXT_MODEL_IDS } from "@roo-code/types" import { useSelectedModel } from "../useSelectedModel" import { useRouterModels } from "../useRouterModels" @@ -474,28 +474,28 @@ describe("useSelectedModel", () => { it("should enable 1M context window for Bedrock Claude Sonnet 4 when awsBedrock1MContext is true", () => { const apiConfiguration: ProviderSettings = { apiProvider: "bedrock", - apiModelId: BEDROCK_CLAUDE_SONNET_4_MODEL_ID, + apiModelId: BEDROCK_1M_CONTEXT_MODEL_IDS[0], awsBedrock1MContext: true, } const wrapper = createWrapper() const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper }) - expect(result.current.id).toBe(BEDROCK_CLAUDE_SONNET_4_MODEL_ID) + expect(result.current.id).toBe(BEDROCK_1M_CONTEXT_MODEL_IDS[0]) expect(result.current.info?.contextWindow).toBe(1_000_000) }) it("should use default context window for Bedrock Claude Sonnet 4 when awsBedrock1MContext is false", () => { const apiConfiguration: ProviderSettings = { apiProvider: "bedrock", - apiModelId: BEDROCK_CLAUDE_SONNET_4_MODEL_ID, + apiModelId: BEDROCK_1M_CONTEXT_MODEL_IDS[0], awsBedrock1MContext: false, } const wrapper = createWrapper() const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper }) - expect(result.current.id).toBe(BEDROCK_CLAUDE_SONNET_4_MODEL_ID) + expect(result.current.id).toBe(BEDROCK_1M_CONTEXT_MODEL_IDS[0]) expect(result.current.info?.contextWindow).toBe(200_000) }) diff --git a/webview-ui/src/components/ui/hooks/useSelectedModel.ts b/webview-ui/src/components/ui/hooks/useSelectedModel.ts index b68e4809f295..0d0514b4d667 100644 --- a/webview-ui/src/components/ui/hooks/useSelectedModel.ts +++ b/webview-ui/src/components/ui/hooks/useSelectedModel.ts @@ -367,11 +367,11 @@ function getSelectedModel({ // Apply 1M context beta tier pricing for Claude Sonnet 4 if ( provider === "anthropic" && - id === "claude-sonnet-4-20250514" && + (id === "claude-sonnet-4-20250514" || id === "claude-sonnet-4-5") && apiConfiguration.anthropicBeta1MContext && baseInfo ) { - // Type assertion since we know claude-sonnet-4-20250514 has tiers + // Type assertion since we know claude-sonnet-4-20250514 and claude-sonnet-4-5 have tiers const modelWithTiers = baseInfo as typeof baseInfo & { tiers?: Array<{ contextWindow: number