diff --git a/sdk/cliproxy/service.go b/sdk/cliproxy/service.go index 725bc4e6..904eff4c 100644 --- a/sdk/cliproxy/service.go +++ b/sdk/cliproxy/service.go @@ -508,22 +508,35 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) { if s.cfg != nil { providerKey := provider compatName := strings.TrimSpace(a.Provider) + isCompatAuth := false if strings.EqualFold(providerKey, "openai-compatibility") { + isCompatAuth = true if a.Attributes != nil { if v := strings.TrimSpace(a.Attributes["compat_name"]); v != "" { compatName = v } if v := strings.TrimSpace(a.Attributes["provider_key"]); v != "" { providerKey = strings.ToLower(v) + isCompatAuth = true } } if providerKey == "openai-compatibility" && compatName != "" { providerKey = strings.ToLower(compatName) } + } else if a.Attributes != nil { + if v := strings.TrimSpace(a.Attributes["compat_name"]); v != "" { + compatName = v + isCompatAuth = true + } + if v := strings.TrimSpace(a.Attributes["provider_key"]); v != "" { + providerKey = strings.ToLower(v) + isCompatAuth = true + } } for i := range s.cfg.OpenAICompatibility { compat := &s.cfg.OpenAICompatibility[i] if strings.EqualFold(compat.Name, compatName) { + isCompatAuth = true // Convert compatibility models to registry models ms := make([]*ModelInfo, 0, len(compat.Models)) for j := range compat.Models { @@ -543,10 +556,18 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) { providerKey = "openai-compatibility" } GlobalModelRegistry().RegisterClient(a.ID, providerKey, ms) + } else { + // Ensure stale registrations are cleared when model list becomes empty. + GlobalModelRegistry().UnregisterClient(a.ID) } return } } + if isCompatAuth { + // No matching provider found or models removed entirely; drop any prior registration. + GlobalModelRegistry().UnregisterClient(a.ID) + return + } } } if len(models) > 0 {