Migrate to use the GA version of Vertex AI in Firebase


Vertex AI in Firebase launched to General Availability (GA) on October 21, 2024.

If you used the beta version of the Vertex AI in Firebase library (firebase-vertexai:16.0.0-betaXX), then you need to make the following changes to upgrade to use the GA version of the library (firebase-vertexai:16.0.0 or higher).

Here's a high-level list of the changes required to migrate:

Enable the new required API in your Firebase project (required for everyone)

You need to enable the Vertex AI in Firebase API in your Firebase project and add it to the allowlist of your Firebase API key. This is a new API that's required to use the GA version of Vertex AI in Firebase.

  1. In the Firebase console, go to the Build with Gemini page.

  2. In the Vertex AI in Firebase card, click Get started to launch a workflow that helps you to enable this API and add it to the allowlist of your Firebase API key.

  3. You can skip the rest of the workflow in the console.

Update to the GA version of the library (required for everyone)

Follow these instructions to update your dependencies to use the latest version of the Firebase Android BoM. Using the BoM isn't required, but we strongly recommend using it because it helps to ensure that your app is using compatible versions of each Firebase library.

  1. In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle), replace the dependency for Vertex AI in Firebase with the following:

    // BEFORE
    dependencies {
      implementation("com.google.firebase:firebase-vertexai:16.0.0-betaXX")
    }
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:33.7.0"))
    
      // Add the dependency for the Vertex AI in Firebase library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-vertexai")
    }
  2. Sync your Android project with Gradle files.

Note that if you choose to not use the Firebase BoM, then just accept the latest version of firebase-vertexai that's suggested by Android Studio.

Additional changes (required depending on features you use)

Several changes were implemented for the GA versions of the SDKs. Review the following lists for any changes that you might need to make in your code to accommodate taking up the GA-version of the SDK in your app.

  • Function calling
    If you implemented this feature before GA, then you'll need to make updates to how you define your schema. We recommend reviewing the updated function calling guide to learn how to write your function declarations.

  • Generating structured output (like JSON) using responseSchema
    If you implemented this feature before GA, then you'll need to make updates to how you define your schema. We recommend reviewing the new structured output guide to learn how to write JSON schemas.

  • Timeout

    • Changed the default timeout for requests to be 180 seconds.
  • Enumerations

    • Replaced enum classes and sealed classes with regular classes. This change allows more flexibility for evolving the API in a backward compatible way.

    • Renamed the BlockThreshold enumeration to HarmBlockThreshold.

    • Removed values from the following enumerations: HarmBlockThreshold, HarmProbability, HarmSeverity, BlockReason, and FinishReason.

  • Blob methods

    • Renamed all methods that included Blob as part of their name to use InlineData instead.
  • Safety settings

    • Changed the field method to be nullable.
  • Duration class

    • Removed all usages of Kotlin's Duration class, and replaced it with long. This change provides better interoperability with Java.
  • Citation metadata

    • Wrapped all the fields previously declared in CitationMetadata into a new class called Citation. Citations can be found in the list called citations in CitationMetadata. This change allows better alignment of types across platforms.
  • Count tokens

    • Changed the field totalBillableCharacters to be nullable.
  • Total billable characters

    • Changed the totalBillableCharacters property in CountTokensResponse to be optional to reflect situations where no characters are sent.
  • Instantiating a model

    • Moved the requestOptions parameter to the end of the parameter list to align with other platforms.