Skip to content

Commit 5be82b9

Browse files
committed
feat: update AWS Bedrock cross-region inference profile mapping
- Add AWS_INFERENCE_PROFILE_MAPPING with official inference profile prefixes - Update getPrefixForRegion to use AWS recommended inference profiles - Improve region-to-profile mapping based on AWS documentation - Prioritize more specific region patterns (e.g., us-gov- before us-) - Add support for apac., ca., sa., and ug. inference profiles
1 parent fba89d9 commit 5be82b9

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

packages/types/src/providers/bedrock.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,24 @@ export const BEDROCK_MAX_TOKENS = 4096
360360

361361
export const BEDROCK_DEFAULT_CONTEXT = 128_000
362362

363+
// AWS Bedrock Inference Profile mapping based on official documentation
364+
// https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html
365+
// This mapping prioritizes AWS's recommended inference profiles for optimal cross-region support
366+
export const AWS_INFERENCE_PROFILE_MAPPING: Record<string, string> = {
367+
// Americas regions → us. inference profile
368+
"us-": "us.",
369+
// Europe regions → eu. inference profile
370+
"eu-": "eu.",
371+
// Asia Pacific regions → apac. inference profile (updated per AWS documentation)
372+
"ap-": "apac.",
373+
// Canada regions → ca. inference profile
374+
"ca-": "ca.",
375+
// South America regions → sa. inference profile
376+
"sa-": "sa.",
377+
// US Government Cloud → ug. inference profile
378+
"us-gov-": "ug.",
379+
}
380+
363381
export const BEDROCK_REGION_INFO: Record<
364382
string,
365383
{

src/api/providers/bedrock.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
BEDROCK_MAX_TOKENS,
2222
BEDROCK_DEFAULT_CONTEXT,
2323
BEDROCK_REGION_INFO,
24+
AWS_INFERENCE_PROFILE_MAPPING,
2425
} from "@roo-code/types"
2526

2627
import { ApiStream } from "../transform/stream"
@@ -900,14 +901,12 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
900901
//a model was selected from the drop down
901902
modelConfig = this.getModelById(this.options.apiModelId as string)
902903

903-
if (this.options.awsUseCrossRegionInference) {
904-
// Get the current region
905-
const region = this.options.awsRegion || ""
906-
// Use the helper method to get the appropriate prefix for this region
907-
const prefix = AwsBedrockHandler.getPrefixForRegion(region)
908-
909-
// Apply the prefix if one was found, otherwise use the model ID as is
910-
modelConfig.id = prefix ? `${prefix}${modelConfig.id}` : modelConfig.id
904+
// Add cross-region inference prefix if enabled
905+
if (this.options.awsUseCrossRegionInference && this.options.awsRegion) {
906+
const prefix = AwsBedrockHandler.getPrefixForRegion(this.options.awsRegion)
907+
if (prefix) {
908+
modelConfig.id = `${prefix}${modelConfig.id}`
909+
}
911910
}
912911
}
913912

@@ -978,11 +977,16 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
978977
}
979978

980979
private static getPrefixForRegion(region: string): string | undefined {
981-
for (const [prefix, info] of Object.entries(BEDROCK_REGION_INFO)) {
982-
if (info.pattern && region.startsWith(info.pattern)) {
983-
return prefix
980+
// Use AWS recommended inference profile prefixes
981+
// Sort by prefix length (descending) to ensure more specific prefixes match first (e.g., us-gov- before us-)
982+
const sortedMappings = Object.entries(AWS_INFERENCE_PROFILE_MAPPING).sort(([a], [b]) => b.length - a.length)
983+
984+
for (const [regionPattern, inferenceProfile] of sortedMappings) {
985+
if (region.startsWith(regionPattern)) {
986+
return inferenceProfile
984987
}
985988
}
989+
986990
return undefined
987991
}
988992

0 commit comments

Comments
 (0)