> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Generation Tools

> Generate images using OpenAI tools.

Similar to providing multimodal inputs, you can also get multimodal outputs from an agent.

## Image Generation using a tool

The following example demonstrates how to generate an image using an OpenAI tool with an agent.

```python image_agent.py theme={null}
import base64

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
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"),
    db=SqliteDb(db_file="tmp/test.db"),
    tools=[OpenAITools(image_model="gpt-image-2")],
    add_history_to_context=True,
    markdown=True,
)

response = agent.run(
    "Generate a photorealistic image of a cozy coffee shop interior",
)

if response.images and response.images[0].content:
    image_base64 = base64.b64encode(response.images[0].content).decode("utf-8")
    save_base64_data(image_base64, "tmp/coffee_shop.png")
```

> [!TIP]
>
> The output of the tool generating a media also goes to the model's input as a
> message so it has access to the media (image, audio, video) and can use it in
> the response. For example, if you say "Generate an image of a dog and tell me
> its color." the model will have access to the image and can use it to describe
> the dog's color in the response in the same run.
>
> That also means you can ask follow-up questions about the image, since it would be available in the history of the agent.

## Usage

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno openai sqlalchemy
```

**2. Export your OpenAI API key**

```bash Mac/Linux theme={null}
  export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
  $Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Run Agent**

```bash theme={null}
python image_agent.py
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.