ResolveModelAlias resolves a model alias to its pinned version. For example, ("anthropic", "claude-sonnet-4-5") might resolve to "claude-sonnet-4-5-20250929". If the model is not an alias (already pinned or unknown), the original model name is returned. This method uses the models.dev database to fi
(ctx context.Context, providerID, modelName string)
| 402 | // If the model is not an alias (already pinned or unknown), the original model name is returned. |
| 403 | // This method uses the models.dev database to find the corresponding pinned version. |
| 404 | func (s *Store) ResolveModelAlias(ctx context.Context, providerID, modelName string) string { |
| 405 | if providerID == "" || modelName == "" { |
| 406 | return modelName |
| 407 | } |
| 408 | |
| 409 | // If the model already has a date suffix, it's already pinned |
| 410 | if datePattern.MatchString(modelName) { |
| 411 | return modelName |
| 412 | } |
| 413 | |
| 414 | provider, err := s.getProvider(ctx, providerID) |
| 415 | if err != nil { |
| 416 | return modelName |
| 417 | } |
| 418 | |
| 419 | // Check if the model exists and is marked as "(latest)" |
| 420 | model, exists := provider.Models[modelName] |
| 421 | if !exists || !strings.Contains(model.Name, "(latest)") { |
| 422 | return modelName |
| 423 | } |
| 424 | |
| 425 | // Find the pinned version by matching the base display name |
| 426 | // e.g., "Claude Sonnet 4 (latest)" -> "Claude Sonnet 4" |
| 427 | baseDisplayName := strings.TrimSuffix(model.Name, " (latest)") |
| 428 | |
| 429 | for pinnedID, pinnedModel := range provider.Models { |
| 430 | if pinnedID != modelName && |
| 431 | !strings.Contains(pinnedModel.Name, "(latest)") && |
| 432 | pinnedModel.Name == baseDisplayName && |
| 433 | datePattern.MatchString(pinnedID) { |
| 434 | return pinnedID |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | return modelName |
| 439 | } |
| 440 | |
| 441 | // bedrockRegionPrefixes contains known regional/inference profile prefixes used in Bedrock model IDs. |
| 442 | // These prefixes should be stripped when looking up models in the database since models.dev |