Gemini
GeminiTools are a set of tools that allow an Agent to interact with Google AI API services for generating images and videos.
Prerequisites
Before using GeminiTools, make sure to have the google-genai library installed and the credentials configured.
-
Install dependencies:
1uv pip install google-genai kern-ai -
Set your credentials:
- For Gemini API:
1export GOOGLE_API_KEY="your-google-genai-api-key"
- For Vertex AI:
1export GOOGLE_CLOUD_PROJECT="your-google-cloud-project-id"2export GOOGLE_CLOUD_LOCATION="your-google-cloud-location"3export GOOGLE_GENAI_USE_VERTEXAI=true
- For Gemini API:
Initialization
Import GeminiTools and add it to your Agent's tool list.
1from kern.agent import Agent2from kern.tools.models.gemini import GeminiTools34agent = Agent(5 tools=[GeminiTools()],6 )Usage Examples
GeminiTools can be used for a variety of tasks. Here are some examples:
Image Generation
1from kern.agent import Agent2from kern.models.openai import OpenAIResponses3from kern.tools.models.gemini import GeminiTools4from kern.utils.media import save_base64_data56agent = Agent(7 model=OpenAIResponses(id="gpt-5.2"),8 tools=[GeminiTools()],9 )1011response = agent.run("Create an artistic portrait of a cyberpunk samurai in a rainy city")12if response.images:13 save_base64_data(response.images[0].content, "tmp/cyberpunk_samurai.png")Video Generation
Note
Video generation requires Vertex AI.
1from kern.agent import Agent2from kern.models.openai import OpenAIResponses3from kern.tools.models.gemini import GeminiTools4from kern.utils.media import save_base64_data56agent = Agent(7 model=OpenAIResponses(id="gpt-5.2"),8 tools=[GeminiTools(vertexai=True)],9 debug_mode=True,10)1112agent.print_response(13 "Generate a 5-second video of a kitten playing a piano",14)15response = agent.run("Generate a 5-second video of a kitten playing a piano")16if response.videos:17 for video in response.videos:18 save_base64_data(video.content, f"tmp/kitten_piano_{video.id}.mp4")Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Optional[str] | None | Google API key for authentication. If not provided, uses GOOGLE_API_KEY environment variable. |
vertexai | bool | False | Whether to use Vertex AI instead of standard Gemini API. Required for video generation. |
project_id | Optional[str] | None | Google Cloud project ID. Required when using Vertex AI. |
location | Optional[str] | None | Google Cloud location/region. Required when using Vertex AI. |
image_generation_model | str | "imagen-3.0-generate-002" | Model to use for image generation. |
video_generation_model | str | "veo-2.0-generate-001" | Model to use for video generation. |
enable_generate_image | bool | True | Enable the image generation function. |
enable_generate_video | bool | True | Enable the video generation function. |
all | bool | False | Enable all available functions. When True, all enable flags are ignored. |
Toolkit Functions
| Function | Description |
|---|---|
generate_image | Generate an image based on a text prompt |
generate_video | Generate a video based on a text prompt |
Developer Resources
- View Toolkit
- View Image Generation Guide
- View Video Generation Guide