> ## 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.

# Gemini Interactions - Image Generation

> Example showing image generation with the Interactions API.

Example showing image generation with the Interactions API. Uses response\_modalities=\["text", "image"] to enable image output.

```python image_generation.py theme={null}
"""
Gemini Interactions - Image Generation
=======================================

Example showing image generation with the Interactions API.
Uses response_modalities=["text", "image"] to enable image output.

Note: Image generation requires a model that supports image output,
such as gemini-3.1-flash-image-preview.
"""

from agno.agent import Agent
from agno.models.google import GeminiInteractions

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    model=GeminiInteractions(
        id="gemini-3.1-flash-image-preview",
        response_modalities=["text", "image"],
    ),
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    response = agent.run("Generate an image of a sunset over mountains")

    if response.images:
        for i, img in enumerate(response.images):
            filepath = f"generated_image_{i}.png"
            content = img.get_content_bytes()
            if content:
                with open(filepath, "wb") as f:
                    f.write(content)
                print(f"Saved image to {filepath}")
    else:
        print("No images generated")

    if response.content:
        print(f"Response: {response.content}")
```

## Run the Example

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

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno google-genai
```

**2. Export your Google API key**

```bash Mac/Linux theme={null}
export GOOGLE_API_KEY="your_google_api_key_here"
```

```bash Windows theme={null}
$Env:GOOGLE_API_KEY="your_google_api_key_here"
```

**3. Use the stable image model**

Before running the source-fidelity code, change `gemini-3.1-flash-image-preview` to `gemini-3.1-flash-image`. The preview model has been shut down.

**4. Run the example**

Save the code above as `image_generation.py`, then run:

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

Full source: [cookbook/90\_models/google/gemini\_interactions/image\_generation.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/90_models/google/gemini_interactions/image_generation.py)


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