Use the Type field to determine which variant is active, then access the corresponding field:
switch imageGenerationProviderPreferencesOnly.Type { case components.ImageGenerationProviderPreferencesOnlyTypeProviderName: // imageGenerationProviderPreferencesOnly.ProviderName is populated case components.ImageGenerationProviderPreferencesOnlyTypeStr: // imageGenerationProviderPreferencesOnly.Str is populated}