Remotely change the model name in your app

The availability of generative AI models frequently changes — new, better models are released and older, less capable models are retired.

When you access generative AI models directly from a mobile or web app using Firebase AI Logic , it's critical that you configure your app to accommodate these frequent model changes. Not all of your users will update to the latest version of your app to start using the model you need them to use.

Firebase Remote Config lets you update parameter values in your app (like a model name) dynamically and remotely from the Firebase console, without the need to release a new version of your app.

Note that changing a model name is a critical use case for using Remote Config with Firebase AI Logic , but you can also use Remote Config to dynamically and even conditionally control parameters in your app , like model generation configuration (maximum tokens, temperature, etc.), safety settings, system instructions, and prompt data.

This guide describes how to implement Remote Config in your app, specifically to control the model name used in your app.

Step 1: Set the parameter value in the Firebase console

Create a Remote Config client template and configure a model_name parameter and its value to fetch and use in the app.

  1. Open your Firebase project in the Firebase console. Then, from the navigation menu, expand Runand select Remote Config .

  2. Ensure that Clientis selected from the Client/Serverselector at the top of the page.

  3. Start a client template by clicking Create Configuration(or Add parameterif you've previously used client templates).

  4. Define the model_name parameter:

    Parameter name Description Type Default value
    model_name
    Model name. See available model names . String gemini-2.5-flash
  5. After adding this parameter, click Publish changes. If this is not a new Remote Config template, review the changes and click Publish changesagain.

Step 2: Add and initialize Remote Config in your app

Add the Remote Config library and set up Remote Config within your app.

Swift

As part of Firebase AI Logic setup , you've already added the Firebase SDK to your app, but will also need to add Remote Config .

  1. In Xcode, with the project open, navigate to File > Add Package Dependencies.

  2. Select firebase-ios-sdkand then click Add package.

  3. From the Project navigator, select your app > Targets> your app.

  4. From the Generaltab, scroll to Frameworks, Libraries, and Embedded Content.

  5. Click +and choose FirebaseRemoteConfig, then click Add.

  6. Add the FirebaseRemoteConfig import to your code:

      import 
      
     FirebaseRemoteConfig 
     
    
  7. Inside the appropriate class for your app, initialize Firebase and add Remote Config to your main application logic.

    Here, you'll include Remote Config and the Remote Config real-time listener as imports so that the app can fetch new values in real-time, and add a minimum fetch interval:

      let 
      
     remoteConfig 
      
     = 
      
     RemoteConfig 
     . 
     remoteConfig 
     () 
     let 
      
     settings 
      
     = 
      
     RemoteConfigSettings 
     () 
     settings 
     . 
     minimumFetchInterval 
      
     = 
      
     3600 
     remoteConfig 
     . 
     configSettings 
      
     = 
      
     settings 
     
    

Kotlin

  1. Add the Remote Config dependency to your module (app-level) Gradle file (usually app/build.gradle.kts or app/build.gradle ):

      dependencies 
      
     { 
      
     implementation 
     ( 
     platform 
     ( 
     "com.google.firebase:firebase-bom:34.5.0" 
     )) 
      
     implementation 
     ( 
     "com.google.firebase:firebase-ai" 
     ) 
      
     implementation 
     ( 
     "com.google.firebase:firebase-config" 
     ) 
      
     // ... other dependencies 
     } 
     
    
  2. Add Remote Config to your main application logic. Here, you'll initialize Remote Config and add a minimum fetch interval:

      val 
      
     remoteConfig 
     : 
      
     FirebaseRemoteConfig 
      
     = 
      
     Firebase 
     . 
     remoteConfig 
     val 
      
     configSettings 
      
     = 
      
     remoteConfigSettings 
      
     { 
     minimumFetchIntervalInSeconds 
      
     = 
      
     3600 
     } 
     remoteConfig 
     . 
     setConfigSettingsAsync 
     ( 
     configSettings 
     ) 
     
    

Java

  1. Add the Remote Config dependency to your module (app-level) Gradle file (usually app/build.gradle.kts or app/build.gradle ):

      dependencies 
      
     { 
      
     implementation 
     ( 
     platform 
     ( 
     "com.google.firebase:firebase-bom:34.5.0" 
     )) 
      
     implementation 
     ( 
     "com.google.firebase:firebase-ai" 
     ) 
      
     implementation 
     ( 
     "com.google.firebase:firebase-config" 
     ) 
      
     // ... other dependencies 
     } 
     
    
  2. Add Remote Config to your main application logic. Here, you'll initialize Remote Config and add a minimum fetch interval:

      FirebaseRemoteConfig 
      
     mFirebaseRemoteConfig 
      
     = 
      
     FirebaseRemoteConfig 
     . 
     getInstance 
     (); 
     FirebaseRemoteConfigSettings 
      
     configSettings 
      
     = 
      
     new 
      
     FirebaseRemoteConfigSettings 
     . 
     Builder 
     () 
      
     . 
     setMinimumFetchIntervalInSeconds 
     ( 
     3600 
     ) 
      
     . 
     build 
     (); 
     mFirebaseRemoteConfig 
     . 
     setConfigSettingsAsync 
     ( 
     configSettings 
     ); 
     
    

Web

  1. Open your code in a text editor and import Remote Config :

      import 
      
     { 
      
     getRemoteConfig 
      
     } 
      
     from 
      
     'firebase/remote-config' 
     ; 
     
    
  2. Inside your primary function and after the Firebase app is initialized for Firebase AI Logic  SDK, initialize Remote Config :

       
     // Initialize Remote Config 
    and get a reference to the service 
      
     const 
      
     remoteConfig 
      
     = 
      
     getRemoteConfig 
     ( 
     app 
     ); 
     
    
  3. Set a minimum fetch interval:

      remoteConfig 
     . 
     settings 
     . 
     minimumFetchIntervalMillis 
      
     = 
      
     3600000 
     ; 
     
    

Dart

  1. From your Flutter project directory, install and add Remote Config using the following command:

     flutter  
    pub  
    add  
    firebase_remote_config 
    
  2. Open ./lib/main.dart and add the import after the other imports you added to support Firebase AI Logic :

      import 
      
     'package:firebase_vertexai/firebase_ai.dart' 
     ; 
     import 
      
     'package:firebase_core/firebase_core.dart' 
     ; 
     import 
      
     'package:firebase_remote_config/firebase_remote_config.dart' 
     ; 
     
    
  3. Add the _modelName variable to your app so that you can use it later:

      late 
      
     final 
      
     String 
      
     _modelName 
     ; 
     late 
      
     final 
      
     String 
      
     _systemInstructions 
     ; 
     late 
      
     final 
      
     String 
      
     _prompt 
     ; 
     
    
  4. Get the Remote Config object instance and set the minimum fetch interval to allow for frequent refreshes. Make sure to add this after Firebase is initialized.

       
     final 
      
     remoteConfig 
      
     = 
      
     FirebaseRemoteConfig 
     . 
     instance 
     ; 
      
     await 
      
     remoteConfig 
     . 
     setConfigSettings 
     ( 
     RemoteConfigSettings 
     ( 
      
     fetchTimeout: 
      
     const 
      
     Duration 
     ( 
     seconds: 
      
     3600 
     ), 
      
     minimumFetchInterval: 
      
     const 
      
     Duration 
     ( 
     seconds: 
      
     3600 
     ), 
      
     )); 
     
    

Unity

  1. Add Remote Config to your Unity project, following these instructions .

  2. Get the Remote Config object instance and set the minimum fetch interval to allow for frequent refreshes. Make sure to add this after Firebase is initialized.

      var 
      
     remoteConfig 
      
     = 
      
     FirebaseRemoteConfig 
     . 
     DefaultInstance 
     ; 
     const 
      
     int 
      
     MillisecondsPerSecond 
      
     = 
      
     1000 
     ; 
     await 
      
     remoteConfig 
     . 
     SetConfigSettingsAsync 
     ( 
     new 
      
     ConfigSettings 
     () 
      
     { 
      
     FetchTimeoutInMilliseconds 
      
     = 
      
     3600 
      
     * 
      
     MillisecondsPerSecond 
     , 
      
     MinimumFetchIntervalInMilliseconds 
      
     = 
      
     3600 
      
     * 
      
     MillisecondsPerSecond 
     }); 
     
    

Step 3: Set the in-app parameter value

You should set in-app default parameter values in the Remote Config object. This ensures that your app behaves as expected even if it cannot fetch values from the Remote Config service.

Swift

  1. In the Firebase console, open Remote Config .

  2. In the Parameters tab, open the Menu, and select Download default values.

  3. When prompted, enable .plist for iOS, then click Download file.

  4. Save the file in the your application directory.

  5. In Xcode, right-click on your app and select Add Files

  6. Select remote_config_defaults.plist, then click Add.

  7. Update your app code to reference the defaults file:

      // Set default values for Remote Config parameters. 
     remoteConfig 
     . 
     setDefaults 
     ( 
     fromPlist 
     : 
      
     "remote_config_defaults" 
     ) 
     
    

Kotlin

  1. From the Firebase console, open Remote Config .

  2. In the Parameters tab, open the Menu, and select Download default values.

  3. When prompted, enable .xml for Android, then click Download file.

  4. Save the file in your app's XML resources directory.

  5. Update your main activity file to add the defaults after the configSettings you added previously:

      // Set default values for Remote Config parameters. 
     remoteConfig 
     . 
     setDefaultsAsync 
     ( 
     R 
     . 
     xml 
     . 
     remote_config_defaults 
     ) 
     
    

Java

  1. In the Firebase console, open Remote Config .

  2. In the Parameters tab, open the Menu, and select Download default values.

  3. When prompted, enable .xml for Android, then click Download file.

  4. Save the file in your app's XML resources directory.

  5. Update your main activity file to add the defaults after the configSettings you added previously:

      // Set default values for Remote Config parameters. 
     mFirebaseRemoteConfig 
     . 
     setDefaultsAsync 
     ( 
     R 
     . 
     xml 
     . 
     remote_config_defaults 
     ); 
     
    

Web

You can set the default value for the model name directly in your code:

  // Set default values for Remote Config parameters. 
 remoteConfig 
 . 
 defaultConfig 
  
 = 
  
 { 
  
 model_name 
 : 
  
 'gemini-2.5-flash' 
 , 
 }; 
 

Dart

You can set the default value for the model name directly in your code:

  // Set default values for Remote Config parameters. 
 remoteConfig 
 . 
 setDefaults 
 ( 
 const 
  
 { 
  
 "model_name" 
 : 
  
 "gemini-2.5-flash" 
 }); 
 

Unity

You can set the default value for the model name directly in your code:

  // Set default values for Remote Config parameters. 
 await 
  
 remoteConfig 
 . 
 SetDefaultsAsync 
 ( 
  
 new 
  
 System 
 . 
 Collections 
 . 
 Generic 
 . 
 Dictionary<string 
 , 
  
 object 
> () 
  
 { 
  
 { 
  
 "model_name" 
 , 
  
 "gemini-2.5-flash" 
  
 } 
  
 } 
 ); 
 

Step 4: Fetch and activate the value

After setting the default value for the model name, add the following to fetch and activate values.

Swift

  // Fetch and activate Remote Config 
values 
 remoteConfig 
 . 
 fetchAndActivate 
  
 { 
  
 status 
 , 
  
 error 
  
 in 
  
 if 
  
 let 
  
 error 
  
 = 
  
 error 
  
 { 
  
 print 
 ( 
 "Error fetching Remote Config 
: 
 \( 
 error 
 . 
 localizedDescription 
 ) 
 " 
 ) 
  
 } 
 } 
 

This should update the Remote Config object whenever a new Remote Config template is published.

Kotlin

  // Fetch and activate Remote Config 
values 
 remoteConfig 
 . 
 fetchAndActivate 
 () 
  
 . 
 addOnCompleteListener 
 ( 
 this 
 ) 
  
 { 
  
 task 
  
 - 
>  
 if 
  
 ( 
 task 
 . 
 isSuccessful 
 ) 
  
 { 
  
 val 
  
 updated 
  
 = 
  
 task 
 . 
 result 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 " Remote Config 
values fetched and activated: 
 $ 
 updated 
 " 
 ) 
  
 } 
  
 else 
  
 { 
  
 Log 
 . 
 e 
 ( 
 TAG 
 , 
  
 "Error fetching Remote Config 
" 
 , 
  
 task 
 . 
 exception 
 ) 
  
 } 
  
 } 
 

Java

   
 // Fetch and activate Remote Config 
values 
  
 mFirebaseRemoteConfig 
 . 
 fetchAndActivate 
 () 
  
 . 
 addOnCompleteListener 
 ( 
 this 
 , 
  
 new 
  
 OnCompleteListener<Boolean> 
 () 
  
 { 
  
 @Override 
  
 public 
  
 void 
  
 onComplete 
 ( 
 @NonNull 
  
 Task<Boolean> 
  
 task 
 ) 
  
 { 
  
 if 
  
 ( 
 task 
 . 
 isSuccessful 
 ()) 
  
 { 
  
 boolean 
  
 updated 
  
 = 
  
 task 
 . 
 getResult 
 (); 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "Config params updated: " 
  
 + 
  
 updated 
 ); 
  
 } 
  
 else 
  
 { 
  
 Log 
 . 
 e 
 ( 
 TAG 
 , 
  
 "Error fetching Remote Config 
" 
 , 
  
 task 
 . 
 exception 
 ) 
  
 } 
  
 } 
  
 }); 
 

Web

  1. Add getValue and fetchAndActivate to your imports:

      import 
      
     { 
      
     getValue 
     , 
      
     fetchAndActivate 
      
     } 
      
     from 
      
     'firebase/remote-config' 
     ; 
     
    
  2. Locate the code where you specify the default value for the model name. Directly after that code block, add the following code to fetch and activate the config and assign the fetched value to the modelName constant.

      // Fetch and activate Remote Config 
    . 
     try 
      
     { 
      
     await 
      
     fetchAndActivate 
     ( 
     remoteConfig 
     ); 
     } 
      
     catch 
     ( 
     err 
     ) 
      
     { 
      
     console 
     . 
     error 
     ( 
     ' Remote Config 
    fetch failed' 
     , 
      
     err 
     ); 
     } 
     console 
     . 
     log 
     ( 
     ' Remote Config 
    fetched.' 
     ); 
     // Assign Remote Config 
    values. 
     const 
      
     modelName 
      
     = 
      
     getValue 
     ( 
     remoteConfig 
     , 
      
     'model_name' 
     ). 
     asString 
     (); 
     
    

Dart

  // Fetch and activate Remote Config. 
 remoteConfig 
 . 
 fetchAndActivate 
 (); 
 // Assign Remote Config values. 
 String 
 ? 
  
 _modelName 
  
 = 
  
 remoteConfig 
 . 
 getString 
 ( 
 "model_name" 
 ); 
 

Unity

  // Fetch and activate Remote Config 
values. 
 await 
  
 remoteConfig 
 . 
 FetchAndActivateAsync 
 (); 
 

Step 5: Add a real-time Remote Config listener

Add a real-time Remote Config listener to your app to ensure that changes you make to the Remote Config template are propagated to the client as soon as they're updated.

The following code updates the Remote Config object whenever a parameter value changes.

Swift

  // Add real-time Remote Config 
 
 remoteConfig 
 . 
 addOnConfigUpdateListener 
  
 { 
  
 configUpdate 
 , 
  
 error 
  
 in 
  
 guard 
  
 let 
  
 configUpdate 
  
 = 
  
 configUpdate 
 , 
  
 error 
  
 == 
  
 nil 
  
 else 
  
 { 
  
 print 
 ( 
 "Error listening for config updates: 
 \( 
 error 
 ?. 
 localizedDescription 
  
 ?? 
  
 "No error available" 
 ) 
 " 
 ) 
  
 return 
  
 } 
  
 print 
 ( 
 "Updated keys: 
 \( 
 configUpdate 
 . 
 updatedKeys 
 ) 
 " 
 ) 
  
 remoteConfig 
 . 
 activate 
  
 { 
  
 changed 
 , 
  
 error 
  
 in 
  
 guard 
  
 error 
  
 == 
  
 nil 
  
 else 
  
 { 
  
 print 
 ( 
 "Error activating config: 
 \( 
 error 
 ?. 
 localizedDescription 
  
 ?? 
  
 "No error available" 
 ) 
 " 
 ) 
  
 return 
  
 } 
  
 print 
 ( 
 "Activated config successfully" 
 ) 
  
 } 
 } 
 

Kotlin

Optionally, you can also configure an action inside the addOnCompleteListener activation:

   
 // Add a real-time Remote Config 
listener 
  
 remoteConfig 
 . 
 addOnConfigUpdateListener 
 ( 
 object 
  
 : 
  
 ConfigUpdateListener 
  
 { 
  
 override 
  
 fun 
  
 onUpdate 
 ( 
 configUpdate 
  
 : 
  
 ConfigUpdate 
 ) 
  
 { 
  
 Log 
 . 
 d 
 ( 
 ContentValues 
 . 
 TAG 
 , 
  
 "Updated keys: " 
  
 + 
  
 configUpdate 
 . 
 updatedKeys 
 ); 
  
 remoteConfig 
 . 
 activate 
 (). 
 addOnCompleteListener 
  
 { 
  
 // Optionally, add an action to perform on update here. 
  
 } 
  
 } 
  
 override 
  
 fun 
  
 onError 
 ( 
 error 
  
 : 
  
 FirebaseRemoteConfigException 
 ) 
  
 { 
  
 Log 
 . 
 w 
 ( 
 ContentValues 
 . 
 TAG 
 , 
  
 "Config update error with code: " 
  
 + 
  
 error 
 . 
 code 
 , 
  
 error 
 ) 
  
 } 
  
 } 
 

Java

Optionally, you can also configure an action inside the addOnCompleteListener activation:

   
 // Add a real-time Remote Config 
listener 
  
 remoteConfig 
 . 
 addOnConfigUpdateListener 
 ( 
 new 
  
 ConfigUpdateListener 
 () 
  
 { 
  
 @Override 
  
 public 
  
 void 
  
 onUpdate 
 ( 
 ConfigUpdate 
  
 configUpdate 
 ) 
  
 { 
  
 Log 
 . 
 d 
 ( 
 ContentValues 
 . 
 TAG 
 , 
  
 "Updated keys: " 
  
 + 
  
 configUpdate 
 . 
 getUpdatedKeys 
 ()); 
  
 remoteConfig 
 . 
 activate 
 (). 
 addOnCompleteListener 
 ( 
 new 
  
 OnCompleteListener<Boolean> 
 () 
  
 { 
  
 @Override 
  
 public 
  
 void 
  
 onComplete 
 ( 
 @NonNull 
  
 Task<Boolean> 
  
 task 
 ) 
  
 { 
  
 // Optionally, add an action to perform on update here. 
  
 } 
  
 }); 
  
 } 
  
 @Override 
  
 public 
  
 void 
  
 onError 
 ( 
 FirebaseRemoteConfigException 
  
 error 
 ) 
  
 { 
  
 Log 
 . 
 w 
 ( 
 ContentValues 
 . 
 TAG 
 , 
  
 "Config update error with code: " 
  
 + 
  
 error 
 . 
 getCode 
 (), 
  
 error 
 ); 
  
 } 
  
 }); 
 

Web

Real-time Remote Config listeners aren't supported for Web apps.

Dart

  // Add a real-time Remote Config 
listener 
 remoteConfig 
 . 
 onConfigUpdated 
 . 
 listen 
 (( 
 event 
 ) 
  
 async 
  
 { 
  
 await 
  
 remoteConfig 
 . 
 activate 
 (); 
 }); 
 

Unity

  // Add a real-time Remote Config 
listener to automatically update whenever 
 // a new template is published. 
 // Note: the parameters can be anonymous as they are unused. 
 remoteConfig 
 . 
 OnConfigUpdateListener 
  
 += 
  
 ( 
 _ 
 , 
  
 _ 
 ) 
  
 = 
>  
 { 
  
 remoteConfig 
 . 
 ActivateAsync 
 (); 
 }; 
 

Step 6: Update the Gemini API requests to use the Remote Config value

Click your Gemini API provider to view provider-specific content and code on this page.

Now that Remote Config is fully configured, update your code to replace hard-coded values with values sourced from Remote Config .

Swift

  import 
  
 FirebaseAI 
 // When creating a `GenerativeModel` instance, source the model name value from Remote Config 
 let 
  
 modelName 
  
 = 
  
 remoteConfig 
 . 
 configValue 
 ( 
 forKey 
 : 
  
 "model_name" 
 ). 
 stringValue 
 let 
  
 model 
  
 = 
  
 FirebaseAI 
 . 
 firebaseAI 
 ( 
 backend 
 : 
  
 . 
 googleAI 
 ()). 
 generativeModel 
 ( 
  
 modelName 
 : 
  
 modelName 
 ) 
 // ... 
 

Kotlin

  // When creating a `GenerativeModel` instance, source the model name value from Remote Config 
 val 
  
 model 
  
 = 
  
 Firebase 
 . 
 ai 
 ( 
 backend 
  
 = 
  
 GenerativeBackend 
 . 
 googleAI 
 ()). 
 generativeModel 
 ( 
  
 modelName 
  
 = 
  
 remoteConfig 
 . 
 getString 
 ( 
 "model_name" 
 ) 
 ) 
 // ... 
 

Java

  // When creating a `GenerativeModel` instance, source the model name value from Remote Config 
 GenerativeModel 
  
 ai 
  
 = 
  
 FirebaseAI 
 . 
 getInstance 
 ( 
 GenerativeBackend 
 . 
 googleAI 
 ()) 
  
 . 
 generativeModel 
 ( 
  
 /* modelName */ 
  
 remoteConfig 
 . 
 getString 
 ( 
 "model_name" 
 ), 
  
 /* generationConfig (optional) */ 
  
 null 
 , 
  
 /* safetySettings (optional) */ 
  
 null 
 , 
  
 /* requestOptions (optional) */ 
  
 new 
  
 RequestOptions 
 (), 
  
 /* tools (optional) */ 
  
 null 
 , 
  
 /* toolsConfig (optional) */ 
  
 null 
 , 
  
 /* systemInstruction (optional) */ 
  
 null 
 , 
  
 ); 
 GenerativeModelFutures 
  
 model 
  
 = 
  
 GenerativeModelFutures 
 . 
 from 
 ( 
 ai 
 ); 
 // ... 
 

Web

  // ... 
 const 
  
 ai 
  
 = 
  
 getAI 
 ( 
 firebaseApp 
 , 
  
 { 
  
 backend 
 : 
  
 new 
  
 GoogleAIBackend 
 () 
  
 }); 
 // When creating a `GenerativeModel` instance, source the model name value from Remote Config 
 const 
  
 model 
  
 = 
  
 getGenerativeModel 
 ( 
 ai 
 , 
  
 { 
  
 model 
 : 
  
 modelName 
 }); 
 // ... 
 

Dart

  // ... 
 // When creating a `GenerativeModel` instance, source the model name value from Remote Config 
 final 
  
 model 
  
 = 
  
 FirebaseAI 
 . 
 googleAI 
 (). 
 generativeModel 
 ( 
  
 model: 
  
 _modelName 
 , 
 ); 
 // ... 
 

Unity

  // ... 
 var 
  
 ai 
  
 = 
  
 FirebaseAI 
 . 
 GetInstance 
 ( 
 FirebaseAI 
 . 
 Backend 
 . 
 GoogleAI 
 ()); 
 // When creating a `GenerativeModel` instance, source the model name value from Remote Config 
 var 
  
 modelName 
  
 = 
  
 remoteConfig 
 . 
 GetValue 
 ( 
 "model_name" 
 ). 
 StringValue 
 ; 
 var 
  
 model 
  
 = 
  
 ai 
 . 
 GetGenerativeModel 
 ( 
  
 modelName 
 : 
  
 modelName 
 ); 
 // ... 
 

Step 7: Run the app

Build and run the app and verify that it works. Make changes to your configuration from the Remote Config page in the Firebase console, publish the changes, and verify the result.

Next steps

Create a Mobile Website
View Site in Mobile | Classic
Share by: