Gemini Image Generation
Legacy GeminiTools example using the retired Imagen endpoint in the Gemini API.
This example preserves the earlier Imagen-based toolkit integration.
The source below calls imagen-3.0-generate-002 through generate_images. Google has retired this model and the Imagen 4 replacements in the Gemini API. Changing the model ID to a native Gemini image model does not adapt the request or response format. See Google’s deprecation schedule. This code is retained as a historical reference. Do not run it as written.
"""Example: Using the GeminiTools Toolkit for Image Generation
An Agent using the Gemini image generation tool.
Example prompts to try:
- "Generate an image of a dog and tell me the color of the dog"
- "Create an image of a cat driving a car"
Run `uv pip install google-genai agno` to install the necessary dependencies.
"""
import base64
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.models.gemini import GeminiTools
from agno.utils.media import save_base64_data
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=OpenAIChat(id="gpt-5.6-luna"),
tools=[GeminiTools()],
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
response = agent.run(
"Generate an image of a dog and tell me the color of the dog",
)
if response and response.images:
for image in response.images:
if image.content:
image_base64 = base64.b64encode(image.content).decode("utf-8")
save_base64_data(
base64_data=image_base64,
output_path=f"tmp/dog_{image.id}.png",
)
print(f"Image saved to tmp/dog_{image.id}.png")Current alternative
Use the Gemini image-generation agent, which calls a native Gemini image model with text and image response modalities.
Full source: cookbook/91_tools/models/gemini_image_generation.py