Image Model Output
Return generated images from model responses.
Similar to providing image inputs, you can also get image outputs from an agent.
Image Output Modality
The following example demonstrates how some models can directly generate images as part of their response.
from io import BytesIO
from agno.agent import Agent, RunOutput # noqa
from agno.models.google import Gemini
from PIL import Image
agent = Agent(
model=Gemini(
id="gemini-3.1-flash-image",
response_modalities=["Text", "Image"], # Generate both images and text in the response
)
)
# Print the response in the terminal
run_response = agent.run("Make me an image of a cat in a tree.")
if run_response and isinstance(run_response, RunOutput) and run_response.images:
for image_response in run_response.images:
image_bytes = image_response.content
if image_bytes:
image = Image.open(BytesIO(image_bytes))
image.show()
# Save the image to a file
# image.save("generated_image.png")
else:
print("No images found in run response")You can find all generated images in the
RunOutput.images list.Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U google-genai pillow agnoExport your Google API key
export GOOGLE_API_KEY="your_google_api_key_here"Run Agent
python image_agent.py