Google GenAI Plugin
Google Gen AI
The genkit-plugin-google-genai
package provides two plugins for accessing Google’s generative AI models:
GoogleAI
: For accessing models via the Google Gemini API (requires an API key).VertexAI
: For accessing models via the Gemini API within Google Cloud Vertex AI (uses standard Google Cloud authentication).
Installation
pip3 install genkit-plugin-google-genai
Configuration
Google Gemini API (GoogleAI
)
To use the Google Gemini API, you need an API key.
from genkit.ai import Genkitfrom genkit.plugins.google_genai import GoogleAI
ai = Genkit( plugins=[GoogleAI()], model='googleai/gemini-2.0-flash',)
You will need to set GEMINI_API_KEY environment variable or you can provide the API Key directly:
ai = Genkit( plugins=[GoogleAI(api_key='...')])
Gemini API in Vertex AI (VertexAI
)
To use models via Vertex AI, ensure you have authenticated with Google Cloud (e.g., via gcloud auth application-default login
).
from genkit.ai import Genkitfrom genkit.plugins.google_genai import VertexAI
ai = Genkit( plugins=[VertexAI()], model='vertexai/gemini-2.0-flash', # optional)
You can specify the location
and project
ID, among other configuration options available in the VertexAI
constructor.
ai = Genkit( plugins=[VertexAI( location='us-east1', project='my-project-id', )],)