Class GoogleGenAIPlugin

java.lang.Object
com.google.genkit.plugins.googlegenai.GoogleGenAIPlugin
All Implemented Interfaces:
Plugin

public class GoogleGenAIPlugin extends Object implements Plugin
Google GenAI plugin for Genkit using the official Google GenAI SDK.

This plugin provides access to Google's Gemini models for:

  • Text generation (Gemini 2.0, 2.5, 3.0 series)
  • Multimodal content (images, video, audio)
  • Embeddings (text-embedding-004, gemini-embedding-001)
  • Function calling/tools

Supports both:

  • Gemini Developer API (with API key)
  • Vertex AI API (with GCP credentials)

Example usage:


 // Using Gemini Developer API with API key
 Genkit genkit = Genkit.builder().addPlugin(GoogleGenAIPlugin.create()) // Uses GOOGLE_API_KEY env var
 		.build();

 // Using Vertex AI
 Genkit genkit = Genkit.builder().addPlugin(GoogleGenAIPlugin.create(
 		GoogleGenAIPluginOptions.builder().vertexAI(true).project("my-project").location("us-central1").build()))
 		.build();

 // Generate content
 GenerateResponse response = genkit
 		.generate(GenerateOptions.builder().model("googleai/gemini-2.0-flash").prompt("Hello, world!").build());
 
  • Field Details

    • SUPPORTED_MODELS

      public static final List<String> SUPPORTED_MODELS
      Supported Gemini models for text/multimodal generation.
    • SUPPORTED_EMBEDDING_MODELS

      public static final List<String> SUPPORTED_EMBEDDING_MODELS
      Supported embedding models.
    • SUPPORTED_IMAGE_MODELS

      public static final List<String> SUPPORTED_IMAGE_MODELS
      Supported image generation models (Imagen). Note: imagen-4.0-* models are supported by the Gemini Developer API. imagen-3.0-* models require Vertex AI.
    • SUPPORTED_TTS_MODELS

      public static final List<String> SUPPORTED_TTS_MODELS
      Supported TTS models.
    • SUPPORTED_VEO_MODELS

      public static final List<String> SUPPORTED_VEO_MODELS
      Supported video generation models (Veo).
  • Constructor Details

    • GoogleGenAIPlugin

      public GoogleGenAIPlugin()
      Creates a GoogleGenAIPlugin with default options. Reads API key from GOOGLE_API_KEY or GEMINI_API_KEY environment variable.
    • GoogleGenAIPlugin

      public GoogleGenAIPlugin(GoogleGenAIPluginOptions options)
      Creates a GoogleGenAIPlugin with the specified options.
      Parameters:
      options - the plugin options
  • Method Details

    • create

      public static GoogleGenAIPlugin create(String apiKey)
      Creates a GoogleGenAIPlugin with the specified API key.
      Parameters:
      apiKey - the Google API key
      Returns:
      a new GoogleGenAIPlugin
    • create

      public static GoogleGenAIPlugin create()
      Creates a GoogleGenAIPlugin using environment variables for configuration.
      Returns:
      a new GoogleGenAIPlugin
    • create

      public static GoogleGenAIPlugin create(GoogleGenAIPluginOptions options)
      Creates a GoogleGenAIPlugin with the specified options.
      Parameters:
      options - the plugin options
      Returns:
      a new GoogleGenAIPlugin
    • vertexAI

      public static GoogleGenAIPlugin vertexAI(String project, String location)
      Creates a GoogleGenAIPlugin configured for Vertex AI.
      Parameters:
      project - the GCP project ID
      location - the GCP location
      Returns:
      a new GoogleGenAIPlugin configured for Vertex AI
    • getName

      public String getName()
      Description copied from interface: Plugin
      Returns the unique identifier for the plugin. This name is used for registration and lookup.
      Specified by:
      getName in interface Plugin
      Returns:
      the plugin name
    • init

      public List<Action<?,?,?>> init()
      Description copied from interface: Plugin
      Initializes the plugin. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides.
      Specified by:
      init in interface Plugin
      Returns:
      list of actions provided by this plugin
    • customModel

      public GoogleGenAIPlugin customModel(String modelName)
      Registers a custom chat/generation model name. Use this to work with models not in the default list. Call this method before passing the plugin to Genkit.builder().
      Parameters:
      modelName - the model name (e.g., "gemini-3-flash")
      Returns:
      this plugin instance for method chaining
    • customEmbeddingModel

      public GoogleGenAIPlugin customEmbeddingModel(String modelName)
      Registers a custom embedding model name. Use this to work with embedding models not in the default list. Call this method before passing the plugin to Genkit.builder().
      Parameters:
      modelName - the embedding model name (e.g., "text-embedding-006")
      Returns:
      this plugin instance for method chaining
    • customImageModel

      public GoogleGenAIPlugin customImageModel(String modelName)
      Registers a custom image generation model name. Use this to work with Imagen models not in the default list. Call this method before passing the plugin to Genkit.builder().
      Parameters:
      modelName - the image model name (e.g., "imagen-5.0-generate-001")
      Returns:
      this plugin instance for method chaining
    • customTtsModel

      public GoogleGenAIPlugin customTtsModel(String modelName)
      Registers a custom TTS model name. Use this to work with TTS models not in the default list. Call this method before passing the plugin to Genkit.builder().
      Parameters:
      modelName - the TTS model name (e.g., "gemini-3-preview-tts")
      Returns:
      this plugin instance for method chaining
    • customVeoModel

      public GoogleGenAIPlugin customVeoModel(String modelName)
      Registers a custom video generation model name. Use this to work with Veo models not in the default list. Call this method before passing the plugin to Genkit.builder().
      Parameters:
      modelName - the video model name (e.g., "veo-4.0-generate-001")
      Returns:
      this plugin instance for method chaining
    • getOptions

      public GoogleGenAIPluginOptions getOptions()
      Gets the plugin options.
      Returns:
      the options