@@ -202,7 +202,13 @@ const ApiOptions = ({
202202 ( value : ProviderName ) => {
203203 setApiConfigurationField ( "apiProvider" , value )
204204
205- // Helper function to validate and reset model if invalid
205+ // It would be much easier to have a single attribute that stores
206+ // the modelId, but we have a separate attribute for each of
207+ // OpenRouter, Glama, Unbound, and Requesty.
208+ // If you switch to one of these providers and the corresponding
209+ // modelId is not set then you immediately end up in an error state.
210+ // To address that we set the modelId to the default value for th
211+ // provider if it's not already set.
206212 const validateAndResetModel = (
207213 modelId : string | undefined ,
208214 field : keyof ProviderSettings ,
@@ -211,15 +217,13 @@ const ApiOptions = ({
211217 if ( modelId ) {
212218 const tempConfig = { ...apiConfiguration , apiProvider : value , apiModelId : modelId }
213219 const modelError = getModelValidationError ( tempConfig , routerModels , organizationAllowList )
220+ // if we have any errors, reset the modelId to default value to prevent ambiguity
214221 if ( modelError ) {
215- setApiConfigurationField ( field , "" )
222+ setApiConfigurationField ( field , defaultValue || "" )
216223 }
217- } else if ( defaultValue ) {
218- setApiConfigurationField ( field , defaultValue )
219224 }
220225 }
221226
222- // Validate current model for the new provider
223227 switch ( value ) {
224228 case "openrouter" :
225229 validateAndResetModel (
0 commit comments