fix(models): canonicalize Bedrock provider aliases (#25756) (thanks @fwhite13)

This commit is contained in:
Peter Steinberger
2026-02-24 23:57:04 +00:00
parent e619a667c8
commit e315c2adff
4 changed files with 35 additions and 2 deletions

View File

@@ -89,6 +89,15 @@ describe("resolveModelAuthMode", () => {
"aws-sdk",
);
});
it("returns aws-sdk for underscore/space bedrock aliases without explicit auth override", () => {
expect(resolveModelAuthMode("aws_bedrock", undefined, { version: 1, profiles: {} })).toBe(
"aws-sdk",
);
expect(resolveModelAuthMode("amazon bedrock", undefined, { version: 1, profiles: {} })).toBe(
"aws-sdk",
);
});
});
describe("requireApiKey", () => {

View File

@@ -21,6 +21,8 @@ describe("model-selection", () => {
expect(normalizeProviderId("kimi-code")).toBe("kimi-coding");
expect(normalizeProviderId("bedrock")).toBe("amazon-bedrock");
expect(normalizeProviderId("aws-bedrock")).toBe("amazon-bedrock");
expect(normalizeProviderId("aws_bedrock")).toBe("amazon-bedrock");
expect(normalizeProviderId("amazon bedrock")).toBe("amazon-bedrock");
expect(normalizeProviderId("amazon-bedrock")).toBe("amazon-bedrock");
});
});
@@ -111,6 +113,17 @@ describe("model-selection", () => {
});
});
it("normalizes bedrock provider aliases in full model refs", () => {
expect(parseModelRef("aws_bedrock/us.anthropic.claude-opus-4-6-v1", "openai")).toEqual({
provider: "amazon-bedrock",
model: "us.anthropic.claude-opus-4-6-v1",
});
expect(parseModelRef("amazon bedrock/us.anthropic.claude-opus-4-6-v1", "openai")).toEqual({
provider: "amazon-bedrock",
model: "us.anthropic.claude-opus-4-6-v1",
});
});
it("keeps already-prefixed Vercel Anthropic models unchanged", () => {
expect(parseModelRef("vercel-ai-gateway/anthropic/claude-opus-4.6", "openai")).toEqual({
provider: "vercel-ai-gateway",

View File

@@ -38,6 +38,7 @@ export function modelKey(provider: string, model: string) {
export function normalizeProviderId(provider: string): string {
const normalized = provider.trim().toLowerCase();
const normalizedWithDashes = normalized.replace(/[\s_]+/g, "-");
if (normalized === "z.ai" || normalized === "z-ai") {
return "zai";
}
@@ -50,7 +51,11 @@ export function normalizeProviderId(provider: string): string {
if (normalized === "kimi-code") {
return "kimi-coding";
}
if (normalized === "bedrock" || normalized === "aws-bedrock") {
if (
normalizedWithDashes === "bedrock" ||
normalizedWithDashes === "aws-bedrock" ||
normalizedWithDashes === "amazon-bedrock"
) {
return "amazon-bedrock";
}
// Backward compatibility for older provider naming.