-
Notifications
You must be signed in to change notification settings - Fork 132
feat: add multi-region support for AWS Bedrock #1897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
fc99b87
6c9f08e
b8f0900
a1a39fa
00558c2
2c42852
97647fb
0d9a1eb
e2d4966
46d2987
3fcf9e7
c4f6525
0d9dfec
77c825d
1277697
ded25d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,26 @@ import { | |
|
|
||
| import type { ProviderKeyOptions } from "@llmgateway/db"; | ||
|
|
||
| /** | ||
| * Derive the AWS Bedrock cross-region inference prefix from a region ID. | ||
| * Many newer models are only available through cross-region inference profiles. | ||
| */ | ||
| function bedrockRegionPrefix(region: string): string { | ||
| if (region.startsWith("us-")) { | ||
| return "us."; | ||
| } | ||
| if (region.startsWith("eu-")) { | ||
| return "eu."; | ||
| } | ||
| if (region.startsWith("ap-")) { | ||
| return "apac."; | ||
| } | ||
| if (region.startsWith("me-")) { | ||
| return "apac."; | ||
| } | ||
| return "us."; | ||
| } | ||
|
Comment on lines
+13
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: For AWS Bedrock cross-region inference in Middle East regions (me-central-1 UAE and me-south-1 Bahrain), the prefix for global cross-region inference profiles is "global.". These profiles route inference requests from the source Middle East region to optimal commercial AWS Regions worldwide for higher throughput. Example model ID from me-central-1: global.anthropic.claude-sonnet-4-6 Usage example (Python boto3): bedrock = boto3.client('bedrock-runtime', region_name='me-central-1') model_id = "global.anthropic.claude-sonnet-4-6" response = bedrock.converse(... , modelId=model_id) Supported models include Anthropic Claude Opus 4.6, Sonnet 4.6, Haiku 4.5, Sonnet 4.5, Opus 4.5 as source regions me-central-1 and me-south-1, destination: commercial regions. ARN pattern: arn:aws:bedrock:REGION:ACCOUNT:inference-profile/global.MODEL-NAME Geographic profiles use prefixes like "us.", "eu.", but for Middle East global CRIS, it's "global.". No specific "me." geographic prefix found; global provides worldwide routing. Citations:
Middle East region should use AWS Bedrock cross-region inference for Middle East regions ( if (region.startsWith("me-")) {
return "global.";
}Additionally, regions like 🤖 Prompt for AI Agents
Comment on lines
+17
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code does this kind of guess: us-east-1 -> us., eu-west-1 -> eu., ap-northeast-1 -> apac.. Why it is wrong: AWS prefixes are model-specific. Claude Sonnet 4.5 supports us., eu., au., jp., and global., not apac.. |
||
|
|
||
| function buildVertexCompatibleEndpoint( | ||
| provider: "google-vertex" | "quartz", | ||
| url: string, | ||
|
|
@@ -220,12 +240,14 @@ export function getProviderEndpoint( | |
| break; | ||
| case "aws-bedrock": | ||
| url = | ||
| regionBaseUrl ?? | ||
| getProviderEnvValue( | ||
| "aws-bedrock", | ||
| "baseUrl", | ||
| configIndex, | ||
| "https://bedrock-runtime.us-east-1.amazonaws.com", | ||
| ) ?? "https://bedrock-runtime.us-east-1.amazonaws.com"; | ||
| ) ?? | ||
| "https://bedrock-runtime.us-east-1.amazonaws.com"; | ||
| break; | ||
| case "azure": { | ||
| const resource = | ||
|
|
@@ -330,10 +352,20 @@ export function getProviderEndpoint( | |
| } | ||
| return `${url}/api/paas/v4/chat/completions`; | ||
| case "aws-bedrock": { | ||
| const prefix = | ||
| providerKeyOptions?.aws_bedrock_region_prefix ?? | ||
| getProviderEnvValue("aws-bedrock", "region", configIndex, "global.") ?? | ||
| "global."; | ||
| // When a specific region is selected (via regionConfig), derive the | ||
| // cross-region inference prefix from the region. Many newer models | ||
| // (Claude Sonnet 4, Opus 4.5, etc.) are CR-only and require a prefix. | ||
| // Fall back to the legacy explicit prefix for backward compatibility. | ||
| const prefix = region | ||
| ? bedrockRegionPrefix(region) | ||
| : (providerKeyOptions?.aws_bedrock_region_prefix ?? | ||
| getProviderEnvValue( | ||
| "aws-bedrock", | ||
| "region", | ||
| configIndex, | ||
| "global.", | ||
| ) ?? | ||
| "global."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not every Bedrock model supports global |
||
|
|
||
| const endpoint = stream ? "converse-stream" : "converse"; | ||
| return `${url}/model/${prefix}${modelName}/${endpoint}`; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.