Skip to content

Commit a02975d

Browse files
committed
feat: add Global Inference for Bedrock models (#8750)
1 parent ff0c65a commit a02975d

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

packages/types/src/provider-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ const bedrockSchema = apiModelIdProviderModelSchema.extend({
221221
awsSessionToken: z.string().optional(),
222222
awsRegion: z.string().optional(),
223223
awsUseCrossRegionInference: z.boolean().optional(),
224+
awsUseGlobalInference: z.boolean().optional(), // Enable Global Inference profile routing when supported
224225
awsUsePromptCache: z.boolean().optional(),
225226
awsProfile: z.string().optional(),
226227
awsUseProfile: z.boolean().optional(),

packages/types/src/providers/bedrock.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,14 @@ export const BEDROCK_1M_CONTEXT_MODEL_IDS = [
448448
"anthropic.claude-sonnet-4-20250514-v1:0",
449449
"anthropic.claude-sonnet-4-5-20250929-v1:0",
450450
] as const
451+
452+
// Amazon Bedrock models that support Global Inference profiles
453+
// As of Oct 2025, AWS supports Global Inference for:
454+
// - Claude Sonnet 4
455+
// - Claude Sonnet 4.5
456+
// - Claude Haiku 4.5
457+
export const BEDROCK_GLOBAL_INFERENCE_MODEL_IDS = [
458+
"anthropic.claude-sonnet-4-20250514-v1:0",
459+
"anthropic.claude-sonnet-4-5-20250929-v1:0",
460+
"anthropic.claude-haiku-4-5-20251001-v1:0",
461+
] as const

src/api/providers/bedrock.ts

Lines changed: 16 additions & 2 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_1M_CONTEXT_MODEL_IDS,
25+
BEDROCK_GLOBAL_INFERENCE_MODEL_IDS,
2526
} from "@roo-code/types"
2627

2728
import { ApiStream } from "../transform/stream"
@@ -887,6 +888,11 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
887888
}
888889
}
889890

891+
// Also strip Global Inference profile prefix if present
892+
if (modelId.startsWith("global.")) {
893+
return modelId.substring("global.".length)
894+
}
895+
890896
// Return the model ID as-is for all other cases
891897
return modelId
892898
}
@@ -964,8 +970,16 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
964970
//a model was selected from the drop down
965971
modelConfig = this.getModelById(this.options.apiModelId as string)
966972

967-
// Add cross-region inference prefix if enabled
968-
if (this.options.awsUseCrossRegionInference && this.options.awsRegion) {
973+
// Apply Global Inference prefix if enabled and supported (takes precedence over cross-region)
974+
const baseIdForGlobal = this.parseBaseModelId(modelConfig.id)
975+
if (
976+
this.options.awsUseGlobalInference &&
977+
BEDROCK_GLOBAL_INFERENCE_MODEL_IDS.includes(baseIdForGlobal as any)
978+
) {
979+
modelConfig.id = `global.${baseIdForGlobal}`
980+
}
981+
// Otherwise, add cross-region inference prefix if enabled
982+
else if (this.options.awsUseCrossRegionInference && this.options.awsRegion) {
969983
const prefix = AwsBedrockHandler.getPrefixForRegion(this.options.awsRegion)
970984
if (prefix) {
971985
modelConfig.id = `${prefix}${modelConfig.id}`

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

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

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

713
import { useAppTranslation } from "@src/i18n/TranslationContext"
814
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, StandardTooltip } from "@src/components/ui"
@@ -23,6 +29,11 @@ export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedMo
2329
const supports1MContextBeta =
2430
!!apiConfiguration?.apiModelId && BEDROCK_1M_CONTEXT_MODEL_IDS.includes(apiConfiguration.apiModelId as any)
2531

32+
// Check if the selected model supports Global Inference profile routing
33+
const supportsGlobalInference =
34+
!!apiConfiguration?.apiModelId &&
35+
BEDROCK_GLOBAL_INFERENCE_MODEL_IDS.includes(apiConfiguration.apiModelId as any)
36+
2637
// Update the endpoint enabled state when the configuration changes
2738
useEffect(() => {
2839
setAwsEndpointSelected(!!apiConfiguration?.awsBedrockEndpointEnabled)
@@ -138,6 +149,17 @@ export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedMo
138149
</SelectContent>
139150
</Select>
140151
</div>
152+
{supportsGlobalInference && (
153+
<Checkbox
154+
checked={apiConfiguration?.awsUseGlobalInference || false}
155+
onChange={(checked: boolean) => {
156+
// Enabling Global Inference should disable cross-region inference
157+
setApiConfigurationField("awsUseGlobalInference", checked)
158+
if (checked) setApiConfigurationField("awsUseCrossRegionInference", false)
159+
}}>
160+
{t("settings:providers.awsGlobalInference")}
161+
</Checkbox>
162+
)}
141163
<Checkbox
142164
checked={apiConfiguration?.awsUseCrossRegionInference || false}
143165
onChange={handleInputChange("awsUseCrossRegionInference", noTransform)}>

webview-ui/src/i18n/locales/en/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@
345345
"awsSessionToken": "AWS Session Token",
346346
"awsRegion": "AWS Region",
347347
"awsCrossRegion": "Use cross-region inference",
348+
"awsGlobalInference": "Use Global inference (auto-select optimal AWS Region)",
348349
"awsBedrockVpc": {
349350
"useCustomVpcEndpoint": "Use custom VPC endpoint",
350351
"vpcEndpointUrlPlaceholder": "Enter VPC Endpoint URL (optional)",

0 commit comments

Comments
 (0)