Proposal: Migrate Google Vertex AI integration from google-cloud-vertexai to google-genai (Imagen & Gemini)
Summary
- Current state: The
google-cloud-vertexaidependency 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 portableImageModelimplementation. - 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-genaiSDK offers a unifiedClientthat can target Gemini API or Vertex AI backends and includes built-in, high-level support for Imagen. - Aligning Spring AI with
google-genaiimproves feature coverage (Imagen), reduces low-level request handling, and fits Spring AI’sImageModelabstraction.
Problem Statement
- The existing Spring AI adapter based on
google-cloud-vertexaiis oriented to Gemini chat and relies on low-levelPredictionServiceClient#predictto 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
- Introduce
google-genaiimplementations - Add
ImagenImageApi,ImagenImageOptions, andImagenImageModelpowered bycom.google.genai:google-genai. - Expose Imagen parameters such as
imageSize,aspectRatio, watermarking, language, safety filtering, and output formats through Spring AI’s options. - Update Gemini support
- Provide a
google-genai-based Gemini path for parity and consistency. - Documentation & samples
- Document the migration and add end-to-end samples (Imagen generation with
ImagePrompt→ImageResponse).
Compatibility & Migration
- Low-risk migration path: Keep the current
google-cloud-vertexaiadapter available for a transition period, but recommendgoogle-genaifor new development—especially for Imagen. - Longer term: Prefer
google-genaias the primary implementation and discourage adding new features on top ofgoogle-cloud-vertexaifor image generation.
Alternatives Considered
- Continue on
google-cloud-vertexaiwith custom wrappers aroundPredictionServiceClient#predictfor 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