Get started with the Gemini API using the Vertex AI in Firebase SDKs


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

Note that you can also use this guide to get started with accessing Imagen models using the Vertex AI in Firebase SDKs.

Prerequisites

Step 1: Set up a Firebase project and connect your app to Firebase

If you already have a Firebase project and an app connected to Firebase

  1. In the Firebase console, go to the Vertex AI page.

  2. Click the Vertex AI in Firebase card to launch a workflow that helps you complete the following tasks:

  3. Continue to the next step in this guide to add the SDK to your app.

If you do not already have a Firebase project and an app connected to Firebase

  1. Sign into the Firebase console.

  2. Click Create project, and then use either of the following options:

    • Option 1: Create a wholly new Firebase project (and its underlying Google Cloud project automatically) by entering a new project name in the first step of the "Create project" workflow.

    • Option 2: "Add Firebase" to an existing Google Cloud project by selecting your Google Cloud project name from the drop-down menu in the first step of the "Create project" workflow.

    Note that when prompted, you do not need to set up Google Analytics to use the Vertex AI in Firebase SDKs.

  3. In the Firebase console, go to the Vertex AI page.

  4. Click the Vertex AI in Firebase card to launch a workflow that helps you complete the following tasks:


Step 2: Add the SDK

With your Firebase project set up and your app connected to Firebase (see previous step), you can now add the Vertex AI in Firebase SDK to your app.

Step 3: Initialize the Vertex AI service and create a GenerativeModel instance

Before you can make any API calls and send a prompt to a Gemini model, you need to initialize the Vertex AI service and create a GenerativeModel instance.

After you finish this getting started guide, learn how to choose a model and (optionally) a location appropriate for your use case and app.

Step 4: Send a prompt request to a model

Now that you've connected your app to Firebase, added the SDK, and initialized the Vertex AI service and the generative model, you're ready to send a prompt request to a Gemini model.

You can use generateContent() to generate text from a text-only prompt request:

What else can you do?

Learn more about the supported models

Learn about the models available for various use cases and their quotas and pricing.

Try out other capabilities

Learn how to control content generation

You can also experiment with prompts and model configurations using Vertex AI Studio.


Give feedback about your experience with Vertex AI in Firebase