Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions packages/types/src/providers/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,24 @@ export const BEDROCK_MAX_TOKENS = 4096

export const BEDROCK_DEFAULT_CONTEXT = 128_000

// AWS Bedrock Inference Profile mapping based on official documentation
// https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html
// This mapping prioritizes AWS's recommended inference profiles for optimal cross-region support
export const AWS_INFERENCE_PROFILE_MAPPING: Record<string, string> = {
// Americas regions β†’ us. inference profile
"us-": "us.",
// Europe regions β†’ eu. inference profile
"eu-": "eu.",
// Asia Pacific regions β†’ apac. inference profile (updated per AWS documentation)
"ap-": "apac.",
// Canada regions β†’ ca. inference profile
"ca-": "ca.",
// South America regions β†’ sa. inference profile
"sa-": "sa.",
// US Government Cloud β†’ ug. inference profile
"us-gov-": "ug.",
}

export const BEDROCK_REGION_INFO: Record<
string,
{
Expand Down
26 changes: 15 additions & 11 deletions src/api/providers/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
BEDROCK_MAX_TOKENS,
BEDROCK_DEFAULT_CONTEXT,
BEDROCK_REGION_INFO,
AWS_INFERENCE_PROFILE_MAPPING,
} from "@roo-code/types"

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

if (this.options.awsUseCrossRegionInference) {
// Get the current region
const region = this.options.awsRegion || ""
// Use the helper method to get the appropriate prefix for this region
const prefix = AwsBedrockHandler.getPrefixForRegion(region)

// Apply the prefix if one was found, otherwise use the model ID as is
modelConfig.id = prefix ? `${prefix}${modelConfig.id}` : modelConfig.id
// Add cross-region inference prefix if enabled
if (this.options.awsUseCrossRegionInference && this.options.awsRegion) {
const prefix = AwsBedrockHandler.getPrefixForRegion(this.options.awsRegion)
if (prefix) {
modelConfig.id = `${prefix}${modelConfig.id}`
}
}
}

Expand Down Expand Up @@ -978,11 +977,16 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
}

private static getPrefixForRegion(region: string): string | undefined {
for (const [prefix, info] of Object.entries(BEDROCK_REGION_INFO)) {
if (info.pattern && region.startsWith(info.pattern)) {
return prefix
// Use AWS recommended inference profile prefixes
// Sort by prefix length (descending) to ensure more specific prefixes match first (e.g., us-gov- before us-)
const sortedMappings = Object.entries(AWS_INFERENCE_PROFILE_MAPPING).sort(([a], [b]) => b.length - a.length)

for (const [regionPattern, inferenceProfile] of sortedMappings) {
if (region.startsWith(regionPattern)) {
return inferenceProfile
}
}

return undefined
}

Expand Down