OpenAI Generate Images
Legacy DalleTools example that generates an image and reads its URL from the run output.
The source-fidelity code uses DalleTools, whose supported DALL-E models are deprecated. Migrate the image path to GPT Image 2 before use.
DALL-E models are deprecated. This source-fidelity example is preserved for reference and should not be run as written. Use Image Generation Agent with GPT Image 2.
"""
Openai Generate Images
======================
Cookbook example for `openai/chat/generate_images.py`.
"""
from agno.agent import Agent, RunOutput
from agno.models.openai import OpenAIChat
from agno.tools.dalle import DalleTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
image_agent = Agent(
model=OpenAIChat(id="gpt-5.6-luna"),
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")
# Retrieve and display generated images using get_last_run_output
run_response = image_agent.get_last_run_output()
if run_response and isinstance(run_response, RunOutput) and run_response.images:
for image_response in run_response.images:
image_url = image_response.url
print(image_url)
else:
print("No images found in run response")
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passCurrent Alternative
Follow Image Generation Agent to generate images with GPT Image 2.
Full source: cookbook/90_models/openai/chat/generate_images.py