Code
cookbook/11_models/openai/responses/image_generation_agent.py
Copy
Ask AI
"""🔧 Example: Using the OpenAITools Toolkit for Image Generation
This script demonstrates how to use the `OpenAITools` toolkit, which includes a tool for generating images using OpenAI's DALL-E within an Agno Agent.
Example prompts to try:
- "Create a surreal painting of a floating city in the clouds at sunset"
- "Generate a photorealistic image of a cozy coffee shop interior"
- "Design a cute cartoon mascot for a tech startup"
- "Create an artistic portrait of a cyberpunk samurai"
Run `uv pip install openai agno` to install the necessary dependencies.
"""
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.openai import OpenAITools
from agno.utils.media import save_base64_data
agent = Agent(
model=OpenAIResponses(id="gpt-5.2"),
tools=[OpenAITools(image_model="gpt-image-1")],
markdown=True,
)
response = agent.run(
"Generate a photorealistic image of a cozy coffee shop interior",
)
if response.images and response.images[0].content:
save_base64_data(str(response.images[0].content), "tmp/coffee_shop.png")
Usage
1
Set up your virtual environment
Copy
Ask AI
uv venv --python 3.12
source .venv/bin/activate
2
Set your API key
Copy
Ask AI
export OPENAI_API_KEY=xxx
3
Install dependencies
Copy
Ask AI
uv pip install -U openai agno
4
Run Agent
Copy
Ask AI
python cookbook/11_models/openai/responses/image_generation_agent.py