Code
cookbook/11_models/openai/chat/generate_images.py
Copy
Ask AI
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.dalle import DalleTools
image_agent = Agent(
model=OpenAIResponses(id="gpt-5.2"),
tools=[DalleTools()],
description="You are an AI agent that can generate images using DALL-E.",
instructions="When the user asks you to create an image, use the `create_image` tool to create the image.",
markdown=True,
)
image_agent.print_response("Generate an image of a white siamese cat")
images = image_agent.get_images()
if images and isinstance(images, list):
for image_response in images:
image_url = image_response.url
print(image_url)
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/chat/generate_images.py