Proposal: Migrate Google Vertex AI integration from google-cloud-vertexai to google-genai (Imagen & Gemini)

Summary

  • Current state: The google-cloud-vertexai dependency is no longer the recommended path for Generative AI. In practice it’s convenient for Gemini chat flows but does not provide a first-class, maintainable path for Google’s Imagen image generation in Spring AI.
  • Issue: With google-cloud-vertexai, Spring AI can wire up Gemini conversations, but cannot cleanly support Google’s Imagen image models via a portable ImageModel implementation.
  • Proposal: Migrate the Google provider in Spring AI to Google Gen AI SDK (com.google.genai:google-genai) as the primary integration for both Gemini (chat/multimodal) and Imagen (image generation).

Reference repo for the current Vertex AI library:
https://github.com/googleapis/google-cloud-java/tree/main/java-vertexai

Background & Rationale

  • Google recommends using the Google Gen AI SDK going forward.
  • The google-genai SDK offers a unified Client that can target Gemini API or Vertex AI backends and includes built-in, high-level support for Imagen.
  • Aligning Spring AI with google-genai improves feature coverage (Imagen), reduces low-level request handling, and fits Spring AI’s ImageModel abstraction.

Problem Statement

  • The existing Spring AI adapter based on google-cloud-vertexai is oriented to Gemini chat and relies on low-level PredictionServiceClient#predict to hit image endpoints. This leads to ad-hoc request construction and an inconsistent developer experience versus other Spring AI models.
  • We need a portable, first-class image generation flow for Google models (Imagen) in Spring AI.

Proposed Change

  1. Introduce google-genai implementations
  2. Add ImagenImageApi, ImagenImageOptions, and ImagenImageModel powered by com.google.genai:google-genai.
  3. Expose Imagen parameters such as imageSize, aspectRatio, watermarking, language, safety filtering, and output formats through Spring AI’s options.
  4. Update Gemini support
  5. Provide a google-genai-based Gemini path for parity and consistency.
  6. Documentation & samples
  7. Document the migration and add end-to-end samples (Imagen generation with ImagePromptImageResponse).

Compatibility & Migration

  • Low-risk migration path: Keep the current google-cloud-vertexai adapter available for a transition period, but recommend google-genai for new development—especially for Imagen.
  • Longer term: Prefer google-genai as the primary implementation and discourage adding new features on top of google-cloud-vertexai for image generation.

Alternatives Considered

  • Continue on google-cloud-vertexai with custom wrappers around PredictionServiceClient#predict for Imagen.
  • Cons: Higher maintenance overhead, poorer developer experience, and not aligned with the recommended SDK direction.

References

  • Vertex AI library repo (current): https://github.com/googleapis/google-cloud-java/tree/main/java-vertexai
  • Google Gen AI SDK for Java (target): com.google.genai:google-genai

Tasks

  • [ ] Add google-genai-based Imagen implementation (API/Options/Model).
  • [ ] Update Gemini integration to use google-genai.
  • [ ] Provide migration notes and samples.
  • [ ] Add tests and documentation (Imagen generation, backend selection).

Comment From: ddobrin

Hi @qq1014853731,

2 modules are available to support the Spring AI integration with Gemini through the Google GenAI SDK: - models/spring-ai-google-genai - models/spring-ai-google-genai-embedding - auto-configuration/spring-ai-autoconfigure-model-google-genai (for both)

These are new implementations which support the existing integration through the Vertex SDK, and include support for API Key respectively Google Credentials

Documentation will be committed shortly.

New features, supported in Gemini 2.x models and the Google GenAI SDK, will be added to these modules