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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2026 Posit Software, PBC. All rights reserved.
*--------------------------------------------------------------------------------------------*/

import { describe, expect, it } from "vitest";

import { getInferenceProfilePrefix } from "../bedrock-provider";

describe("getInferenceProfilePrefix", () => {
it("uses the us-gov partition for AWS GovCloud regions", () => {
// Regression: GovCloud regions also start with "us-", so they must be
// matched before the general us- case or they'd get the commercial "us."
// prefix, whose inference profiles don't exist in GovCloud.
expect(getInferenceProfilePrefix("us-gov-west-1")).toBe("us-gov");
expect(getInferenceProfilePrefix("us-gov-east-1")).toBe("us-gov");
});

it("maps commercial regions to their partition prefixes", () => {
expect(getInferenceProfilePrefix("us-east-1")).toBe("us");
expect(getInferenceProfilePrefix("us-west-2")).toBe("us");
expect(getInferenceProfilePrefix("eu-west-1")).toBe("eu");
expect(getInferenceProfilePrefix("eu-central-1")).toBe("eu");
expect(getInferenceProfilePrefix("ap-northeast-1")).toBe("apac");
expect(getInferenceProfilePrefix("ap-southeast-1")).toBe("apac");
});

it("defaults unknown regions to us", () => {
expect(getInferenceProfilePrefix("ca-central-1")).toBe("us");
});
});
10 changes: 9 additions & 1 deletion packages/ai-provider-bridge/src/providers/bedrock-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ const MODEL_CACHE_TTL = 60 * 60 * 1000;
* Claude 4.x and newer models require inference profiles, not direct model IDs.
*
* AWS cross-region inference profiles use these prefixes:
* - us-gov.* for AWS GovCloud regions (us-gov-west-1, us-gov-east-1)
* - us.* for US regions (us-east-1, us-west-2, etc.)
* - eu.* for EU regions (eu-west-1, eu-central-1, etc.)
* - apac.* for Asia-Pacific regions (ap-northeast-1, ap-southeast-1, etc.)
*
* GovCloud must be checked before the general `us-` case: `us-gov-west-1`
* also starts with `us-`, but its profiles live under the `us-gov` partition
* and the commercial `us.` profiles don't exist there.
*/
function getInferenceProfilePrefix(region: string): string {
export function getInferenceProfilePrefix(region: string): string {
if (region.startsWith("us-gov-")) {
return "us-gov";
}
if (region.startsWith("us-")) {
return "us";
}
Expand Down