Skip to content

Commit b264495

Browse files
authored
fix: Anthropic Sonnet 4.5 model id + Bedrock 1M context checkbox (#8384)
fix(anthropic): use claude-sonnet-4-5 id fix(bedrock): enable 1M context checkbox for Sonnet 4.5 via shared list closes #8379 closes #8381
1 parent f3b3751 commit b264495

File tree

9 files changed

+28
-26
lines changed

9 files changed

+28
-26
lines changed

packages/types/src/providers/anthropic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type AnthropicModelId = keyof typeof anthropicModels
66
export const anthropicDefaultModelId: AnthropicModelId = "claude-sonnet-4-20250514"
77

88
export const anthropicModels = {
9-
"claude-4.5-sonnet": {
9+
"claude-sonnet-4-5": {
1010
maxTokens: 64_000, // Overridden to 8k if `enableReasoningEffort` is false.
1111
contextWindow: 200_000, // Default 200K, extendable to 1M with beta flag 'context-1m-2025-08-07'
1212
supportsImages: true,

packages/types/src/providers/bedrock.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,7 @@ export const BEDROCK_REGIONS = [
458458
].sort((a, b) => a.value.localeCompare(b.value))
459459

460460
export const BEDROCK_CLAUDE_SONNET_4_MODEL_ID = "anthropic.claude-sonnet-4-20250514-v1:0"
461+
export const BEDROCK_1M_CONTEXT_MODEL_IDS = [
462+
"anthropic.claude-sonnet-4-20250514-v1:0",
463+
"anthropic.claude-sonnet-4-5-20250929-v1:0",
464+
] as const

packages/types/src/providers/claude-code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export function getClaudeCodeModelId(baseModelId: ClaudeCodeModelId, useVertex =
4040
}
4141

4242
export const claudeCodeModels = {
43-
"claude-4.5-sonnet": {
44-
...anthropicModels["claude-4.5-sonnet"],
43+
"claude-sonnet-4-5": {
44+
...anthropicModels["claude-sonnet-4-5"],
4545
supportsImages: false,
4646
supportsPromptCache: true, // Claude Code does report cache tokens
4747
supportsReasoningEffort: false,

src/api/providers/__tests__/anthropic.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ describe("AnthropicHandler", () => {
268268
it("should handle Claude 4.5 Sonnet model correctly", () => {
269269
const handler = new AnthropicHandler({
270270
apiKey: "test-api-key",
271-
apiModelId: "claude-4.5-sonnet",
271+
apiModelId: "claude-sonnet-4-5",
272272
})
273273
const model = handler.getModel()
274-
expect(model.id).toBe("claude-4.5-sonnet")
274+
expect(model.id).toBe("claude-sonnet-4-5")
275275
expect(model.info.maxTokens).toBe(64000)
276276
expect(model.info.contextWindow).toBe(200000)
277277
expect(model.info.supportsReasoningBudget).toBe(true)
@@ -280,7 +280,7 @@ describe("AnthropicHandler", () => {
280280
it("should enable 1M context for Claude 4.5 Sonnet when beta flag is set", () => {
281281
const handler = new AnthropicHandler({
282282
apiKey: "test-api-key",
283-
apiModelId: "claude-4.5-sonnet",
283+
apiModelId: "claude-sonnet-4-5",
284284
anthropicBeta1MContext: true,
285285
})
286286
const model = handler.getModel()

src/api/providers/anthropic.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
4747

4848
// Add 1M context beta flag if enabled for Claude Sonnet 4 and 4.5
4949
if (
50-
(modelId === "claude-sonnet-4-20250514" || modelId === "claude-4.5-sonnet") &&
50+
(modelId === "claude-sonnet-4-20250514" || modelId === "claude-sonnet-4-5") &&
5151
this.options.anthropicBeta1MContext
5252
) {
5353
betas.push("context-1m-2025-08-07")
5454
}
5555

5656
switch (modelId) {
57-
case "claude-4.5-sonnet":
57+
case "claude-sonnet-4-5":
5858
case "claude-sonnet-4-20250514":
5959
case "claude-opus-4-1-20250805":
6060
case "claude-opus-4-20250514":
@@ -114,7 +114,7 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
114114

115115
// Then check for models that support prompt caching
116116
switch (modelId) {
117-
case "claude-4.5-sonnet":
117+
case "claude-sonnet-4-5":
118118
case "claude-sonnet-4-20250514":
119119
case "claude-opus-4-1-20250805":
120120
case "claude-opus-4-20250514":
@@ -249,7 +249,7 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
249249
let info: ModelInfo = anthropicModels[id]
250250

251251
// If 1M context beta is enabled for Claude Sonnet 4 or 4.5, update the model info
252-
if ((id === "claude-sonnet-4-20250514" || id === "claude-4.5-sonnet") && this.options.anthropicBeta1MContext) {
252+
if ((id === "claude-sonnet-4-20250514" || id === "claude-sonnet-4-5") && this.options.anthropicBeta1MContext) {
253253
// Use the tier pricing for 1M context
254254
const tier = info.tiers?.[0]
255255
if (tier) {

src/api/providers/bedrock.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
BEDROCK_DEFAULT_CONTEXT,
2323
AWS_INFERENCE_PROFILE_MAPPING,
2424
BEDROCK_CLAUDE_SONNET_4_MODEL_ID,
25+
BEDROCK_1M_CONTEXT_MODEL_IDS,
2526
} from "@roo-code/types"
2627

2728
import { ApiStream } from "../transform/stream"
@@ -378,10 +379,11 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
378379
inferenceConfig.topP = 0.1
379380
}
380381

381-
// Check if 1M context is enabled for Claude Sonnet 4
382+
// Check if 1M context is enabled for Claude Sonnet 4 / 4.5
382383
// Use parseBaseModelId to handle cross-region inference prefixes
383384
const baseModelId = this.parseBaseModelId(modelConfig.id)
384-
const is1MContextEnabled = baseModelId === BEDROCK_CLAUDE_SONNET_4_MODEL_ID && this.options.awsBedrock1MContext
385+
const is1MContextEnabled =
386+
BEDROCK_1M_CONTEXT_MODEL_IDS.includes(baseModelId as any) && this.options.awsBedrock1MContext
385387

386388
// Add anthropic_beta for 1M context to additionalModelRequestFields
387389
if (is1MContextEnabled) {
@@ -976,10 +978,10 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
976978
}
977979
}
978980

979-
// Check if 1M context is enabled for Claude Sonnet 4
981+
// Check if 1M context is enabled for Claude Sonnet 4 / 4.5
980982
// Use parseBaseModelId to handle cross-region inference prefixes
981983
const baseModelId = this.parseBaseModelId(modelConfig.id)
982-
if (baseModelId === BEDROCK_CLAUDE_SONNET_4_MODEL_ID && this.options.awsBedrock1MContext) {
984+
if (BEDROCK_1M_CONTEXT_MODEL_IDS.includes(baseModelId as any) && this.options.awsBedrock1MContext) {
983985
// Update context window to 1M tokens when 1M context beta is enabled
984986
modelConfig.info = {
985987
...modelConfig.info,

webview-ui/src/components/settings/providers/Anthropic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const Anthropic = ({ apiConfiguration, setApiConfigurationField }: Anthro
2323

2424
// Check if the current model supports 1M context beta
2525
const supports1MContextBeta =
26-
selectedModel?.id === "claude-sonnet-4-20250514" || selectedModel?.id === "claude-4.5-sonnet"
26+
selectedModel?.id === "claude-sonnet-4-20250514" || selectedModel?.id === "claude-sonnet-4-5"
2727

2828
const handleInputChange = useCallback(
2929
<K extends keyof ProviderSettings, E>(

webview-ui/src/components/settings/providers/Bedrock.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { useCallback, useState, useEffect } from "react"
22
import { Checkbox } from "vscrui"
33
import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
44

5-
import {
6-
type ProviderSettings,
7-
type ModelInfo,
8-
BEDROCK_REGIONS,
9-
BEDROCK_CLAUDE_SONNET_4_MODEL_ID,
10-
} from "@roo-code/types"
5+
import { type ProviderSettings, type ModelInfo, BEDROCK_REGIONS, BEDROCK_1M_CONTEXT_MODEL_IDS } from "@roo-code/types"
116

127
import { useAppTranslation } from "@src/i18n/TranslationContext"
138
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, StandardTooltip } from "@src/components/ui"
@@ -24,8 +19,9 @@ export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedMo
2419
const { t } = useAppTranslation()
2520
const [awsEndpointSelected, setAwsEndpointSelected] = useState(!!apiConfiguration?.awsBedrockEndpointEnabled)
2621

27-
// Check if the selected model supports 1M context (Claude Sonnet 4)
28-
const supports1MContextBeta = apiConfiguration?.apiModelId === BEDROCK_CLAUDE_SONNET_4_MODEL_ID
22+
// Check if the selected model supports 1M context (Claude Sonnet 4 / 4.5)
23+
const supports1MContextBeta =
24+
!!apiConfiguration?.apiModelId && BEDROCK_1M_CONTEXT_MODEL_IDS.includes(apiConfiguration.apiModelId as any)
2925

3026
// Update the endpoint enabled state when the configuration changes
3127
useEffect(() => {

webview-ui/src/components/ui/hooks/useSelectedModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import {
5555
qwenCodeDefaultModelId,
5656
qwenCodeModels,
5757
vercelAiGatewayDefaultModelId,
58-
BEDROCK_CLAUDE_SONNET_4_MODEL_ID,
58+
BEDROCK_1M_CONTEXT_MODEL_IDS,
5959
deepInfraDefaultModelId,
6060
} from "@roo-code/types"
6161

@@ -200,8 +200,8 @@ function getSelectedModel({
200200
}
201201
}
202202

203-
// Apply 1M context for Claude Sonnet 4 when enabled
204-
if (id === BEDROCK_CLAUDE_SONNET_4_MODEL_ID && apiConfiguration.awsBedrock1MContext && baseInfo) {
203+
// Apply 1M context for Claude Sonnet 4 / 4.5 when enabled
204+
if (BEDROCK_1M_CONTEXT_MODEL_IDS.includes(id as any) && apiConfiguration.awsBedrock1MContext && baseInfo) {
205205
// Create a new ModelInfo object with updated context window
206206
const info: ModelInfo = {
207207
...baseInfo,

0 commit comments

Comments
 (0)