Get started with the Gemini API using the Firebase AI Logic SDKs  |  Firebase AI Logic

Get started with the Gemini API using the Firebase AI Logic SDKs

This guide shows you how to get started making calls to the Gemini API directly from your app using the Firebase AI Logic client SDKs for your chosen platform.

Prerequisites

This guide assumes that you're familiar with using various development environments to develop apps for different platforms. Make sure that your development environment meets the requirements for the specific platform you are targeting.

Check out helpful resources

Try out the quickstart app

Use the quickstart app to try out the SDK quickly and see a complete implementation of various use cases. To use the quickstart app, you'll need to connect it to a Firebase project.

Watch a video tutorial

You can also watch a series of video tutorials available on YouTube which demonstrate how to get started with Firebase AI Logic by building real-world applications.

Step 1: Set up a Firebase project and enable APIs

  1. Sign into the Firebase console, and then select your Firebase project.

    Don't already have a Firebase project? You can create a new Firebase project by following the prompts in the console.

  2. In the Firebase console, go to AI Services > AI Logic.

  3. Click Get started to launch a guided workflow that helps you set up the required APIs and resources for your project.

  4. If prompted, follow the on-screen instructions to register your app and add your Firebase configuration to your app.

  5. When asked to choose a "Gemini API provider", we recommend selecting the Gemini Developer API.

  6. Continue in the workflow to set up the required APIs and associated services for Firebase AI Logic.

Step 2: Add the required SDKs

You can now add the required SDKs to your app by following the installation procedures specific to your platform:

iOS (Swift)

Use Swift Package Manager to install and manage Firebase dependencies.

  1. In Xcode, with your app project open, navigate to File > Add Package Dependencies.
  2. Add the Firebase Apple platforms SDK repository: https://github.com/firebase/firebase-ios-sdk
  3. Select the latest SDK version and add the required libraries.

Android (Kotlin/Java)

Add the dependencies for the Firebase AI Logic and App Check libraries in your Gradle file. You can use the Firebase Android BoM to manage library versions properly.

Kotlin Example Code:

dependencies {
  implementation(platform("com.google.firebase:firebase-bom:<latest-version>"))
  implementation("com.google.firebase:firebase-ai")
}

Java Example Code:

dependencies {
  implementation(platform("com.google.firebase:firebase-bom:<latest-version>"))
  implementation("com.google.firebase:firebase-ai")
}

Web

To install the Firebase JavaScript SDK:

npm install firebase

Initialize Firebase in your app:

import { initializeApp } from "firebase/app";
const firebaseApp = initializeApp({ /* your config */ });

Flutter

Install the Firebase AI Logic and App Check plugins:

flutter pub add firebase_ai firebase_app_check

Unity

Download the FirebaseUnity SDK and import the required packages.

Step 3: Configure the App Check debug provider for local development

Follow the specific instructions for each platform to set up App Check using the debug provider, allowing you to develop locally while maintaining protections on the Firebase AI Logic API.

Step 4: Initialize the service and create a model instance

To initialize the Gemini API and create a model instance, follow the platform-specific instructions provided:

Swift Example:

let ai = FirebaseAI.firebaseAI(backend: .googleAI())
let model = ai.generativeModel(modelName: "gemini-3.8-flash")

Step 5: Send a request to a model

Use the generate methods available in the SDKs to send prompts to the Gemini models and receive generated content in return. Here is an example of sending a request to the model:

Swift Example:

let prompt = "Write a story about a magic backpack."
let response = try await model.generateContent(prompt)
print(response.text ?? "No text in response.")

What else can you do?