Skip to content
Open
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
30 changes: 25 additions & 5 deletions providers/anthropic/bedrock.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,34 @@ func bedrockBasicAuthConfig(apiKey, region string) aws.Config {
}
}

// bedrockInferenceProfilePrefixes are the cross-region inference
// profile prefixes Bedrock model IDs may already carry. IDs starting
// with one of these are fully qualified and must not be prefixed
// again with the caller's region.
var bedrockInferenceProfilePrefixes = []string{
"global.",
"us-gov.",
"us.",
"eu.",
"apac.",
"ap.",
"jp.",
"au.",
"ca.",
"sa.",
"il.",
"mx.",
}

func bedrockPrefixModelWithRegion(modelID, region string) string {
for _, prefix := range bedrockInferenceProfilePrefixes {
if strings.HasPrefix(modelID, prefix) {
return modelID
}
}
region = resolveBedrockRegion(region)
if len(region) < 2 {
return modelID
}
prefix := region[:2] + "."
if strings.HasPrefix(modelID, prefix) {
return modelID
}
return prefix + modelID
return region[:2] + "." + modelID
}
62 changes: 62 additions & 0 deletions providers/anthropic/bedrock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package anthropic

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestBedrockPrefixModelWithRegion(t *testing.T) {
t.Parallel()

tests := []struct {
name string
modelID string
region string
want string
}{
{
name: "bare model id gets region prefix",
modelID: "anthropic.claude-fable-5-1",
region: "us-east-1",
want: "us.anthropic.claude-fable-5-1",
},
{
name: "matching geo prefix is preserved",
modelID: "us.anthropic.claude-fable-5-1",
region: "us-east-1",
want: "us.anthropic.claude-fable-5-1",
},
{
name: "global inference profile is preserved",
modelID: "global.anthropic.claude-fable-5-1",
region: "us-east-1",
want: "global.anthropic.claude-fable-5-1",
},
{
name: "global inference profile is preserved outside us",
modelID: "global.anthropic.claude-fable-5-1",
region: "eu-west-1",
want: "global.anthropic.claude-fable-5-1",
},
{
name: "apac profile is not double prefixed",
modelID: "apac.anthropic.claude-fable-5-1",
region: "ap-southeast-2",
want: "apac.anthropic.claude-fable-5-1",
},
{
name: "cross geo profile is preserved",
modelID: "eu.anthropic.claude-fable-5-1",
region: "us-east-1",
want: "eu.anthropic.claude-fable-5-1",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, test.want, bedrockPrefixModelWithRegion(test.modelID, test.region))
})
}
}