Google Cloud Services - Gen AI

This extension allows to inject a com.google.genai.Client object, from the Google Gen AI SDK, inside your Quarkus application. The client can talk to Vertex AI (default) or to the Gemini Developer API.

It replaces the Vertex AI extension, which relies on Vertex AI SDK generative APIs that are deprecated by Google.

Be sure to have read the Google Cloud Services extension pack global documentation before this one, it contains general configuration and information.

Bootstrapping the project

First, we need a new project.Create a new project with the following command (replace the version placeholder with the correct one):

mvn io.quarkus:quarkus-maven-plugin:<quarkusVersion>:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=genai-quickstart \
    -Dextensions="resteasy-reactive-jackson,quarkus-google-cloud-genai"
cd genai-quickstart

This command generates a Maven project, importing the Google Cloud Gen AI extension.

If you already have your Quarkus project configured, you can add the quarkus-google-cloud-genai extension to your project by running the following command in your project base directory:

./mvnw quarkus:add-extension -Dextensions="quarkus-google-cloud-genai"

This will add the following to your pom.xml:

<dependency>
    <groupId>io.quarkiverse.googlecloudservices</groupId>
    <artifactId>quarkus-google-cloud-genai</artifactId>
</dependency>

Choosing the backend

By default, the client uses Vertex AI with the Google Cloud credentials and project ID configured as described in the global documentation. You can set the region with:

quarkus.google.cloud.genai.location=us-central1

If no project ID or location is configured, the SDK falls back to the GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION environment variables.

To use the Gemini Developer API instead, configure an API key, no Google Cloud credentials are needed:

quarkus.google.cloud.genai.api-key=<your-api-key>

The backend is selected as follows: quarkus.google.cloud.genai.vertex-ai if set, otherwise the Gemini Developer API when an API key is configured, otherwise Vertex AI. Setting an API key together with vertex-ai=true fails at startup. The API key is a secret: prefer an environment variable or a secret source over a plain application.properties.

Some example

This is an example usage of the extension: we create a REST resource with a single endpoint that takes a prompt as query parameter and generates a response using Gemini Flash.

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;

import com.google.genai.Client;

@Path("/genai")
public class GenAIResource {
    @Inject
    Client client;

    @GET
    public String generate(@QueryParam("prompt") String prompt) {
        return client.models.generateContent("gemini-2.5-flash", prompt, null).text();
    }
}

Migrating from the Vertex AI extension

Replace the quarkus-google-cloud-vertex-ai dependency by quarkus-google-cloud-genai and the quarkus.google.cloud.vertexai. properties by quarkus.google.cloud.genai.. Then replace the VertexAI and GenerativeModel usages by the Client API, see the Google migration guide.

Configuration Reference

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

Gemini Developer API key. When set, the client uses the Gemini Developer API instead of Vertex AI, unless vertex-ai is set to true.

Environment variable: QUARKUS_GOOGLE_CLOUD_GENAI_API_KEY

string

Force the backend: true for Vertex AI, false for the Gemini Developer API. Defaults to Vertex AI unless an API key is configured.

Environment variable: QUARKUS_GOOGLE_CLOUD_GENAI_VERTEX_AI

boolean

Google Cloud region used by Vertex AI, for example global or us-central1.

Environment variable: QUARKUS_GOOGLE_CLOUD_GENAI_LOCATION

string

Override the base URL of the API.

Environment variable: QUARKUS_GOOGLE_CLOUD_GENAI_BASE_URL

string

Override the API version.

Environment variable: QUARKUS_GOOGLE_CLOUD_GENAI_API_VERSION

string

Timeout of HTTP requests.

Environment variable: QUARKUS_GOOGLE_CLOUD_GENAI_TIMEOUT

Duration 

About the Duration format

To write duration values, use the standard java.time.Duration format. See the Duration#parse() Java API documentation for more information.

You can also use a simplified format, starting with a number:

  • If the value is only a number, it represents time in seconds.

  • If the value is a number followed by ms, it represents time in milliseconds.

In other cases, the simplified format is translated to the java.time.Duration format for parsing:

  • If the value is a number followed by h, m, or s, it is prefixed with PT.

  • If the value is a number followed by d, it is prefixed with P.