> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/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

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno google-genai
    ```
  </Step>

  <Step title="Export your Google API key">
    <CodeGroup>
      ```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"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `image_generation.py`, then run:

    ```bash theme={null}
    python image_generation.py
    ```
  </Step>
</Steps>

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