Skip to content

Commit 7b2f50a

Browse files
committed
Check for known region/inference profile prefixes on bedrock models
This is more reliable and requires less maintenance compared to checking for a valid provider prefix intstead Signed-off-by: Christopher Petito <chrisjpetito@gmail.com>
1 parent 0ef176a commit 7b2f50a

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

pkg/modelsdev/store.go

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,14 @@ func (s *Store) GetModel(ctx context.Context, id string) (*Model, error) {
178178
model, exists := provider.Models[modelID]
179179
if !exists {
180180
// For amazon-bedrock, try stripping region/inference profile prefixes
181-
// Bedrock uses prefixes like "global.", "us.", "eu.", "apac." etc. for
182-
// cross-region inference profiles, but models.dev stores models without
183-
// these prefixes. Try stripping the first segment if it doesn't match
184-
// a known model provider prefix (anthropic, meta, amazon, etc.)
181+
// Bedrock uses prefixes for cross-region inference profiles,
182+
// but models.dev stores models without these prefixes.
183+
//
184+
// Strip known region prefixes and retry lookup.
185185
if providerID == "amazon-bedrock" {
186186
if idx := strings.Index(modelID, "."); idx != -1 {
187187
possibleRegionPrefix := modelID[:idx]
188-
// Only strip if the prefix is NOT a known model provider
189-
// (i.e., it's likely a region prefix like "global", "us", "eu")
190-
if !isBedrockModelProvider(possibleRegionPrefix) {
188+
if isBedrockRegionPrefix(possibleRegionPrefix) {
191189
normalizedModelID := modelID[idx+1:]
192190
model, exists = provider.Models[normalizedModelID]
193191
if exists {
@@ -336,22 +334,18 @@ func (s *Store) ResolveModelAlias(ctx context.Context, providerID, modelName str
336334
return modelName
337335
}
338336

339-
// bedrockModelProviders contains known model provider prefixes used in Bedrock model IDs.
340-
// These are NOT region prefixes and should not be stripped when normalizing model IDs.
341-
var bedrockModelProviders = map[string]bool{
342-
"anthropic": true,
343-
"amazon": true,
344-
"meta": true,
345-
"cohere": true,
346-
"ai21": true,
347-
"mistral": true,
348-
"stability": true,
349-
"deepseek": true,
350-
"google": true,
351-
"minimax": true,
337+
// bedrockRegionPrefixes contains known regional/inference profile prefixes used in Bedrock model IDs.
338+
// These prefixes should be stripped when looking up models in the database since models.dev
339+
// stores models without regional prefixes. AWS uses these for cross-region inference profiles.
340+
// See: https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference.html
341+
var bedrockRegionPrefixes = map[string]bool{
342+
"us": true, // US region inference profile
343+
"eu": true, // EU region inference profile
344+
"apac": true, // Asia Pacific region inference profile
345+
"global": true, // Global inference profile (routes to any available region)
352346
}
353347

354-
// isBedrockModelProvider returns true if the prefix is a known Bedrock model provider.
355-
func isBedrockModelProvider(prefix string) bool {
356-
return bedrockModelProviders[prefix]
348+
// isBedrockRegionPrefix returns true if the prefix is a known Bedrock regional/inference profile prefix.
349+
func isBedrockRegionPrefix(prefix string) bool {
350+
return bedrockRegionPrefixes[prefix]
357351
}

0 commit comments

Comments
 (0)