The latest Gemini models, likeGemini 3.1 Flash Image(Nano Banana 2), are available to use with Firebase AI Logic!Learn more.
Gemini 2.0 Flash and Flash-Lite models will shut down onJune 1, 2026. To avoid service disruption, update to a newer model likegemini-3.1-flash-lite.Learn more.
Migrate to the Firebase AI Logic SDKs from the Google AI client SDKsStay organized with collectionsSave and categorize content based on your preferences.
You might have tried out an alternative set of mobile or web client SDKs that
gave you access to theGemini Developer API.
Those client SDKs were not integrated into the robust Firebase ecosystem that
offers critical services for mobile and web apps. They are now deprecated in
favor of theFirebase AI Logicclient SDKs, which can give you
access to theGemini Developer API.
Security features for mobile and web apps
For mobile and web apps, security is critical and requires special
considerations because your code – including calls to theGemini API– is
running in an unprotected environment. You can useFirebase App Checkto
protect APIs from abuse by unauthorized clients.
When youuseFirebase App CheckwithFirebase AI Logic,
you never add yourGeminiAPI key for theGemini Developer APIdirectly into your mobile or web app's codebase. Instead, theGeminiAPI key stays on the server, unexposed to malicious actors.
Ecosystem built for mobile and web apps
Firebase is Google's platform for developing mobile and web apps. UsingFirebase AI Logicmeans that your apps are in an ecosystem that's focused on
the needs of full-stack apps and developers. For example:
Dynamically set run-time configurations or swap out values in
your app (like a model name and version) without releasing a new app version
usingFirebase Remote Config.
UseCloud Storage for Firebaseto include large files in your multimodal
requests (if you use theVertex AIGemini API). TheCloud Storageclient SDKs help you handle file uploads and downloads (even in
poor network conditions) and offer more security for your end-users' data.
Learn more in oursolution guide about usingCloud Storage for Firebase.
Manage structured data using database SDKs built for mobile and web apps
(likeCloud Firestore).
Migrate to theFirebase AI Logic SDKs
Overview of steps to migrate to theFirebase AI Logic SDKs:
Step 1: Set up a new or existing Firebase project and connect your app to
Firebase.
Step 2: Add theFirebase AI Logic SDKs to your app.
Step 3: Update your imports and initialization in your app.
Step 4: Update your code depending on the features that you use.
Step 1: Set up a Firebase project and connect your app
Sign into theFirebaseconsole,
and then select your Firebase project.
Don't already have a Firebase project?
If you don't already have a Firebase project, click the button to create a
new Firebase project, and then use either of the following options:
Option 1: Create a wholly new Firebase project (and its underlyingGoogle Cloudproject automatically) by entering a new project name in the
first step of the workflow.
Option 2: "Add Firebase" to an existingGoogle Cloudproject by
clickingAdd Firebase to Google Cloud project(at bottom of page).
In the first step of the workflow, start entering theproject nameof
the existing project, and then select the project from the displayed list.
If you'd like, you can add Firebase to the project that was created behind
the scenes when you created aGeminiAPI key inGoogle AI Studio.
Complete the remaining steps of the on-screen workflow to create a Firebase
project. Note that when prompted, you donotneed to set upGoogle Analyticsto use theFirebase AI Logic SDKs.
ClickGet startedto launch a guided workflow that helps you set up therequired APIsand resources for your project.
Select theGemini Developer API. You can always set up and use
the other API provider later, if you'd like.
The console will enable the required APIs and create a new, dedicatedGeminiAPI key in your project. Donotadd this newGeminiAPI key into your app's codebase.Learn more.
If prompted in the console's workflow, follow the on-screen instructions to
register your app and connect it to Firebase.
Continue in this migration guide to update the library and initialization in
your app.
Step 2: Add theFirebase AI Logic SDK to your app
With your Firebase project set up and your app connected to Firebase
(see previous step), you can now add theFirebase AI Logic SDK to your app.
TheFirebase AI Logic SDK for Android (firebase-ai) provides
access to the APIs for interacting withGeminimodels.
In yourmodule (app-level) Gradle file(like<project>/<app-module>/build.gradle.kts),
add the dependency for theFirebase AI Logiclibrary for Android.
We recommend using theFirebase Android BoMto control library versioning.
For Java, you need to add two additional libraries.
dependencies{// ... other androidx dependencies// Import theBoMfor the Firebase platformimplementation(platform("com.google.firebase:firebase-bom:34.13.0"))// Add the dependency for theFirebase AI Logiclibrary// When using theBoM, you don't specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-ai")// Required for one-shot operations (to use `ListenableFuture` from Guava Android)implementation("com.google.guava:guava:31.0.1-android")// Required for streaming operations (to use `Publisher` from Reactive Streams)implementation("org.reactivestreams:reactive-streams:1.0.4")}
By using theFirebase Android BoM,
your app will always use compatible versions of Firebase Android libraries.
(Alternative)
Add Firebase library dependencies without using theBoM
If you choose not to use theFirebase BoM, you must specify each
Firebase library version in its dependency line.
Note that if you usemultipleFirebase libraries in your app, we
strongly recommend using theBoMto manage library versions, which
ensures that all versions are compatible.
dependencies{// Add the dependency for theFirebase AI Logiclibrary// When NOT using theBoM, you must specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-ai:17.12.0")}
Web
TheFirebase AI Logiclibrary provides access to the APIs for interacting
withGeminimodels. The library is included as part of the
Firebase JavaScript SDK for Web.
Install the Firebase JS SDK for Web using npm:
npm install firebase
Initialize Firebase in your app:
import{initializeApp}from"firebase/app";// TODO(developer) Replace the following with your app's Firebase configuration// See: https://firebase.google.com/docs/web/learn-more#config-objectconstfirebaseConfig={// ...};// Initialize FirebaseAppconstfirebaseApp=initializeApp(firebaseConfig);
Dart
TheFirebase AI Logicplugin for Flutter (firebase_ai) provides
access to the APIs for interacting withGeminimodels.
From your Flutter project directory, run the following command to
install the core plugin and theFirebase AI Logicplugin:
flutterpubaddfirebase_corefirebase_ai
In yourlib/main.dartfile, import the Firebase core plugin, theFirebase AI Logicplugin, and the configuration file you generated
earlier:
Step 4: Update code depending on the features that you use
This step describes changes that may be required depending on which features you
use.
TheFirebase AI Logicclient SDKs don't support
code execution. If you use this feature, make sure to accommodate this in
your app.
Review the following lists for any changes that you might need to make in your
code to accommodate migrating to theFirebase AI Logicclient SDKs.
Required for all languages and platforms
Function calling If you implemented this feature, then you'll need to make updates to
how you define your schema. We recommend reviewing the updatedfunction calling guideto learn how to
write your function declarations.
Generating structured output (like JSON) usingresponseSchema If you implemented this feature, then you'll need to make updates to
how you define your schema. We recommend reviewing the newstructured output guideto learn
how to write JSON schemas.
Timeout
Changed the default timeout for requests to be 180 seconds.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-05-27 UTC."],[],[]]