Class GoogleGenAIPlugin
java.lang.Object
com.google.genkit.plugins.googlegenai.GoogleGenAIPlugin
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionSupported embedding models.Supported image generation models (Imagen).Supported Gemini models for text/multimodal generation.Supported TTS models.Supported video generation models (Veo). -
Constructor Summary
ConstructorsConstructorDescriptionCreates a GoogleGenAIPlugin with default options.Creates a GoogleGenAIPlugin with the specified options. -
Method Summary
Modifier and TypeMethodDescriptionstatic GoogleGenAIPlugincreate()Creates a GoogleGenAIPlugin using environment variables for configuration.static GoogleGenAIPlugincreate(GoogleGenAIPluginOptions options) Creates a GoogleGenAIPlugin with the specified options.static GoogleGenAIPluginCreates a GoogleGenAIPlugin with the specified API key.customEmbeddingModel(String modelName) Registers a custom embedding model name.customImageModel(String modelName) Registers a custom image generation model name.customModel(String modelName) Registers a custom chat/generation model name.customTtsModel(String modelName) Registers a custom TTS model name.customVeoModel(String modelName) Registers a custom video generation model name.getName()Returns the unique identifier for the plugin.Gets the plugin options.init()Initializes the plugin.static GoogleGenAIPluginCreates a GoogleGenAIPlugin configured for Vertex AI.
-
Field Details
-
SUPPORTED_MODELS
Supported Gemini models for text/multimodal generation. -
SUPPORTED_EMBEDDING_MODELS
Supported embedding models. -
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
Supported TTS models. -
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
Creates a GoogleGenAIPlugin with the specified options.- Parameters:
options- the plugin options
-
-
Method Details
-
create
Creates a GoogleGenAIPlugin with the specified API key.- Parameters:
apiKey- the Google API key- Returns:
- a new GoogleGenAIPlugin
-
create
Creates a GoogleGenAIPlugin using environment variables for configuration.- Returns:
- a new GoogleGenAIPlugin
-
create
Creates a GoogleGenAIPlugin with the specified options.- Parameters:
options- the plugin options- Returns:
- a new GoogleGenAIPlugin
-
vertexAI
Creates a GoogleGenAIPlugin configured for Vertex AI.- Parameters:
project- the GCP project IDlocation- the GCP location- Returns:
- a new GoogleGenAIPlugin configured for Vertex AI
-
getName
Description copied from interface:PluginReturns the unique identifier for the plugin. This name is used for registration and lookup. -
init
Description copied from interface:PluginInitializes the plugin. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides. -
customModel
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
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
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
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
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
Gets the plugin options.- Returns:
- the options
-