ResolveModelAliases resolves model aliases to their pinned versions in the config. For example, "claude-sonnet-4-5" might resolve to "claude-sonnet-4-5-20250929". This modifies the config in place. NOTE: Alias resolution is skipped for models with custom base_url configurations, either set directly
(ctx context.Context, cfg *latest.Config, store *modelsdev.Store)
| 18 | // This is necessary because external providers (like Azure Foundry) may use the alias |
| 19 | // names directly as deployment names rather than the pinned version names. |
| 20 | func ResolveModelAliases(ctx context.Context, cfg *latest.Config, store *modelsdev.Store) { |
| 21 | // Resolve model aliases in the models section |
| 22 | for name, modelCfg := range cfg.Models { |
| 23 | if modelCfg.IsFirstAvailable() || isInlineModelEntry(name, modelCfg) { |
| 24 | continue |
| 25 | } |
| 26 | |
| 27 | // Skip alias resolution for models with custom base_url (direct or via provider) |
| 28 | // Custom endpoints like Azure Foundry use alias names as deployment names |
| 29 | if hasCustomBaseURL(&modelCfg, cfg.Providers) { |
| 30 | slog.DebugContext(ctx, "Skipping model alias resolution for model with custom base_url", |
| 31 | "model_name", name, "provider", modelCfg.Provider, "model", modelCfg.Model) |
| 32 | continue |
| 33 | } |
| 34 | |
| 35 | if resolved := store.ResolveModelAlias(ctx, modelCfg.Provider, modelCfg.Model); resolved != modelCfg.Model { |
| 36 | modelCfg.DisplayModel = modelCfg.Model |
| 37 | modelCfg.Model = resolved |
| 38 | cfg.Models[name] = modelCfg |
| 39 | } |
| 40 | |
| 41 | // Resolve model aliases in routing rules |
| 42 | for i, rule := range modelCfg.Routing { |
| 43 | if provider, model, ok := strings.Cut(rule.Model, "/"); ok { |
| 44 | if resolved := store.ResolveModelAlias(ctx, provider, model); resolved != model { |
| 45 | modelCfg.Routing[i].Model = provider + "/" + resolved |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | cfg.Models[name] = modelCfg |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | func isInlineModelEntry(name string, modelCfg latest.ModelConfig) bool { |
| 54 | return name == modelCfg.Provider+"/"+modelCfg.Model |