Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/types/src/providers/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type AnthropicModelId = keyof typeof anthropicModels
export const anthropicDefaultModelId: AnthropicModelId = "claude-sonnet-4-20250514"

export const anthropicModels = {
"claude-4.5-sonnet": {
"claude-sonnet-4-5": {
maxTokens: 64_000, // Overridden to 8k if `enableReasoningEffort` is false.
contextWindow: 200_000, // Default 200K, extendable to 1M with beta flag 'context-1m-2025-08-07'
supportsImages: true,
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/providers/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,7 @@ export const BEDROCK_REGIONS = [
].sort((a, b) => a.value.localeCompare(b.value))

export const BEDROCK_CLAUDE_SONNET_4_MODEL_ID = "anthropic.claude-sonnet-4-20250514-v1:0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope

export const BEDROCK_1M_CONTEXT_MODEL_IDS = [
"anthropic.claude-sonnet-4-20250514-v1:0",
"anthropic.claude-sonnet-4-5-20250929-v1:0",
] as const
4 changes: 2 additions & 2 deletions packages/types/src/providers/claude-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function getClaudeCodeModelId(baseModelId: ClaudeCodeModelId, useVertex =
}

export const claudeCodeModels = {
"claude-4.5-sonnet": {
...anthropicModels["claude-4.5-sonnet"],
"claude-sonnet-4-5": {
...anthropicModels["claude-sonnet-4-5"],
supportsImages: false,
supportsPromptCache: true, // Claude Code does report cache tokens
supportsReasoningEffort: false,
Expand Down
6 changes: 3 additions & 3 deletions src/api/providers/__tests__/anthropic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ describe("AnthropicHandler", () => {
it("should handle Claude 4.5 Sonnet model correctly", () => {
const handler = new AnthropicHandler({
apiKey: "test-api-key",
apiModelId: "claude-4.5-sonnet",
apiModelId: "claude-sonnet-4-5",
})
const model = handler.getModel()
expect(model.id).toBe("claude-4.5-sonnet")
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)
Expand All @@ -280,7 +280,7 @@ describe("AnthropicHandler", () => {
it("should enable 1M context for Claude 4.5 Sonnet when beta flag is set", () => {
const handler = new AnthropicHandler({
apiKey: "test-api-key",
apiModelId: "claude-4.5-sonnet",
apiModelId: "claude-sonnet-4-5",
anthropicBeta1MContext: true,
})
const model = handler.getModel()
Expand Down
8 changes: 4 additions & 4 deletions src/api/providers/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa

// 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") &&
(modelId === "claude-sonnet-4-20250514" || modelId === "claude-sonnet-4-5") &&
this.options.anthropicBeta1MContext
) {
betas.push("context-1m-2025-08-07")
}

switch (modelId) {
case "claude-4.5-sonnet":
case "claude-sonnet-4-5":
case "claude-sonnet-4-20250514":
case "claude-opus-4-1-20250805":
case "claude-opus-4-20250514":
Expand Down Expand Up @@ -114,7 +114,7 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa

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

// If 1M context beta is enabled for Claude Sonnet 4 or 4.5, update the model info
if ((id === "claude-sonnet-4-20250514" || id === "claude-4.5-sonnet") && this.options.anthropicBeta1MContext) {
if ((id === "claude-sonnet-4-20250514" || id === "claude-sonnet-4-5") && this.options.anthropicBeta1MContext) {
// Use the tier pricing for 1M context
const tier = info.tiers?.[0]
if (tier) {
Expand Down
10 changes: 6 additions & 4 deletions src/api/providers/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
BEDROCK_DEFAULT_CONTEXT,
AWS_INFERENCE_PROFILE_MAPPING,
BEDROCK_CLAUDE_SONNET_4_MODEL_ID,
BEDROCK_1M_CONTEXT_MODEL_IDS,
} from "@roo-code/types"

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

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

// Add anthropic_beta for 1M context to additionalModelRequestFields
if (is1MContextEnabled) {
Expand Down Expand Up @@ -976,10 +978,10 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
}
}

// Check if 1M context is enabled for Claude Sonnet 4
// Check if 1M context is enabled for Claude Sonnet 4 / 4.5
// Use parseBaseModelId to handle cross-region inference prefixes
const baseModelId = this.parseBaseModelId(modelConfig.id)
if (baseModelId === BEDROCK_CLAUDE_SONNET_4_MODEL_ID && this.options.awsBedrock1MContext) {
if (BEDROCK_1M_CONTEXT_MODEL_IDS.includes(baseModelId as any) && this.options.awsBedrock1MContext) {
// Update context window to 1M tokens when 1M context beta is enabled
modelConfig.info = {
...modelConfig.info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Anthropic = ({ apiConfiguration, setApiConfigurationField }: Anthro

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

const handleInputChange = useCallback(
<K extends keyof ProviderSettings, E>(
Expand Down
12 changes: 4 additions & 8 deletions webview-ui/src/components/settings/providers/Bedrock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { useCallback, useState, useEffect } from "react"
import { Checkbox } from "vscrui"
import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react"

import {
type ProviderSettings,
type ModelInfo,
BEDROCK_REGIONS,
BEDROCK_CLAUDE_SONNET_4_MODEL_ID,
} from "@roo-code/types"
import { type ProviderSettings, type ModelInfo, BEDROCK_REGIONS, BEDROCK_1M_CONTEXT_MODEL_IDS } from "@roo-code/types"

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

// Check if the selected model supports 1M context (Claude Sonnet 4)
const supports1MContextBeta = apiConfiguration?.apiModelId === BEDROCK_CLAUDE_SONNET_4_MODEL_ID
// Check if the selected model supports 1M context (Claude Sonnet 4 / 4.5)
const supports1MContextBeta =
!!apiConfiguration?.apiModelId && BEDROCK_1M_CONTEXT_MODEL_IDS.includes(apiConfiguration.apiModelId as any)

// Update the endpoint enabled state when the configuration changes
useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions webview-ui/src/components/ui/hooks/useSelectedModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
qwenCodeDefaultModelId,
qwenCodeModels,
vercelAiGatewayDefaultModelId,
BEDROCK_CLAUDE_SONNET_4_MODEL_ID,
BEDROCK_1M_CONTEXT_MODEL_IDS,
deepInfraDefaultModelId,
} from "@roo-code/types"

Expand Down Expand Up @@ -200,8 +200,8 @@ function getSelectedModel({
}
}

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