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

# Image Generation

> Create and edit images with multiple AI engines including DALL·E, Gemini, ComfyUI, and AUTOMATIC1111

## Overview

Open WebUI supports powerful image generation and editing capabilities through multiple engines, allowing you to create custom visuals directly in your chat conversations.

## Supported Engines

<Tabs>
  <Tab title="OpenAI">
    **DALL·E Integration**

    * DALL·E 2: Fast, cost-effective
    * DALL·E 3: Higher quality, more detailed
    * GPT-IMAGE 1 & 1.5: Latest models

    ```python theme={null}
    {
      "IMAGE_GENERATION_ENGINE": "openai",
      "IMAGE_GENERATION_MODEL": "dall-e-3",
      "IMAGES_OPENAI_API_BASE_URL": "https://api.openai.com/v1",
      "IMAGES_OPENAI_API_KEY": "sk-..."
    }
    ```
  </Tab>

  <Tab title="Gemini">
    **Google Imagen**

    * Imagen 3.0: High-quality generation
    * Multiple endpoint methods
    * Batch generation support

    ```python theme={null}
    {
      "IMAGE_GENERATION_ENGINE": "gemini",
      "IMAGE_GENERATION_MODEL": "imagen-3.0-generate-002",
      "IMAGES_GEMINI_API_BASE_URL": "https://us-central1-aiplatform.googleapis.com/v1",
      "IMAGES_GEMINI_API_KEY": "your-api-key",
      "IMAGES_GEMINI_ENDPOINT_METHOD": "generateContent"
    }
    ```
  </Tab>

  <Tab title="ComfyUI">
    **Local Workflow Execution**

    * Custom workflows
    * Full control over generation
    * Advanced LoRA/embedding support
    * Local/self-hosted

    ```python theme={null}
    {
      "IMAGE_GENERATION_ENGINE": "comfyui",
      "COMFYUI_BASE_URL": "http://comfyui:8188",
      "COMFYUI_API_KEY": "optional-key",
      "COMFYUI_WORKFLOW": "{...}",  // JSON workflow
      "COMFYUI_WORKFLOW_NODES": [...]
    }
    ```
  </Tab>

  <Tab title="AUTOMATIC1111">
    **Stable Diffusion WebUI**

    * Popular self-hosted option
    * Extensive model library
    * Community extensions
    * Free and open source

    ```python theme={null}
    {
      "IMAGE_GENERATION_ENGINE": "automatic1111",
      "AUTOMATIC1111_BASE_URL": "http://stable-diffusion:7860",
      "AUTOMATIC1111_API_AUTH": "username:password",
      "AUTOMATIC1111_PARAMS": {...}
    }
    ```
  </Tab>
</Tabs>

## Image Generation

### Basic Generation

Create images from text descriptions:

<Steps>
  <Step title="Enable Image Generation">
    ```python theme={null}
    {
      "ENABLE_IMAGE_GENERATION": true,
      "IMAGE_GENERATION_ENGINE": "openai",
      "IMAGE_GENERATION_MODEL": "dall-e-3"
    }
    ```
  </Step>

  <Step title="Configure Parameters">
    ```python theme={null}
    {
      "IMAGE_SIZE": "1024x1024",  // or "auto" for compatible models
      "IMAGE_STEPS": 50,          // Quality/speed tradeoff
      "ENABLE_IMAGE_PROMPT_GENERATION": true
    }
    ```
  </Step>

  <Step title="Generate in Chat">
    Simply describe what you want:

    ```
    Generate an image of a futuristic city at sunset
    ```
  </Step>
</Steps>

### API Usage

Generate images programmatically:

```bash theme={null}
# POST /api/v1/images/generations
curl -X POST "https://your-instance/api/v1/images/generations" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A serene mountain landscape at dawn",
    "n": 1,
    "size": "1024x1024",
    "steps": 50,
    "negative_prompt": "blurry, low quality"
  }'
```

Response:

```json theme={null}
[
  {
    "url": "/api/v1/files/{file-id}/content"
  }
]
```

### Generation Parameters

<CardGroup cols={2}>
  <Card title="Prompt" icon="message">
    Text description of desired image

    * Be specific and detailed
    * Include style, mood, lighting
    * Mention artistic techniques
  </Card>

  <Card title="Size" icon="expand">
    Image dimensions

    * Standard: 512x512, 1024x1024
    * Custom: WIDTHxHEIGHT format
    * "auto": Model-dependent sizing
  </Card>

  <Card title="Steps" icon="gauge">
    Generation iterations

    * More steps = higher quality
    * More steps = slower generation
    * Typical range: 20-100
  </Card>

  <Card title="Negative Prompt" icon="ban">
    What to avoid in the image

    * "blurry, distorted"
    * "low quality, watermark"
    * Engine-dependent support
  </Card>
</CardGroup>

## Image Editing

Modify existing images with AI.

### Configuration

```python theme={null}
{
  "ENABLE_IMAGE_EDIT": true,
  "IMAGE_EDIT_ENGINE": "openai",  // openai, gemini, comfyui
  "IMAGE_EDIT_MODEL": "dall-e-2",
  "IMAGE_EDIT_SIZE": "1024x1024"
}
```

### Edit Workflow

<Steps>
  <Step title="Upload Image">
    Provide source image(s):

    * File upload
    * URL reference
    * File ID from previous generation
  </Step>

  <Step title="Describe Changes">
    Specify desired modifications:

    ```json theme={null}
    {
      "prompt": "Add a rainbow in the sky",
      "image": "data:image/png;base64,..."
    }
    ```
  </Step>

  <Step title="Optional Parameters">
    * Background color for transparency
    * Multiple image inputs (for Gemini)
    * Size adjustments
  </Step>

  <Step title="Generate Edited Version">
    API returns modified image URL
  </Step>
</Steps>

### Edit API

```bash theme={null}
# POST /api/v1/images/edit
curl -X POST "https://your-instance/api/v1/images/edit" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "image": "https://example.com/image.png",
    "prompt": "Change the sky to nighttime with stars",
    "size": "1024x1024",
    "n": 1
  }'
```

### Supported Edit Operations

<Tabs>
  <Tab title="OpenAI">
    **DALL·E Edit Capabilities:**

    * Single image input
    * Inpainting/outpainting
    * Background replacement
    * Style transfer
    * Detail enhancement
  </Tab>

  <Tab title="Gemini">
    **Imagen Edit Features:**

    * Multiple image inputs
    * Context-aware editing
    * Batch processing
    * High-quality results
  </Tab>

  <Tab title="ComfyUI">
    **Custom Workflow Editing:**

    * Full workflow control
    * ControlNet integration
    * Image-to-image pipelines
    * Advanced compositing
  </Tab>
</Tabs>

## ComfyUI Integration

Advanced users can leverage ComfyUI's powerful workflow system.

### Workflow Configuration

<Steps>
  <Step title="Design Workflow">
    Create workflow in ComfyUI interface:

    * Load desired models
    * Configure nodes
    * Test generation
  </Step>

  <Step title="Export Workflow">
    Save workflow as JSON from ComfyUI
  </Step>

  <Step title="Configure Nodes">
    Map workflow nodes to Open WebUI parameters:

    ```python theme={null}
    {
      "COMFYUI_WORKFLOW_NODES": [
        {
          "type": "model",
          "node_ids": ["4"]
        },
        {
          "type": "prompt",
          "node_ids": ["6", "7"]
        },
        {
          "type": "size",
          "node_ids": ["5"]
        }
      ]
    }
    ```
  </Step>

  <Step title="Upload to Open WebUI">
    Paste workflow JSON in settings:

    ```python theme={null}
    {
      "COMFYUI_WORKFLOW": "{...}"
    }
    ```
  </Step>
</Steps>

### Workflow Node Types

* **model**: Checkpoint/model selector
* **prompt**: Positive/negative prompts
* **size**: Width/height dimensions
* **steps**: Sampling steps
* **seed**: Random seed control
* **sampler**: Sampling method

<Tip>
  ComfyUI workflows allow complete control over the generation pipeline, including custom samplers, LoRAs, and post-processing.
</Tip>

## AUTOMATIC1111 Integration

### Configuration

```python theme={null}
{
  "IMAGE_GENERATION_ENGINE": "automatic1111",
  "AUTOMATIC1111_BASE_URL": "http://localhost:7860",
  "AUTOMATIC1111_API_AUTH": "username:password",  // Optional
  "IMAGE_SIZE": "512x512",
  "IMAGE_STEPS": 50
}
```

### Custom Parameters

Pass additional parameters to AUTOMATIC1111:

```python theme={null}
{
  "AUTOMATIC1111_PARAMS": {
    "cfg_scale": 7.5,
    "sampler_name": "Euler a",
    "enable_hr": true,
    "hr_scale": 2,
    "denoising_strength": 0.7
  }
}
```

### Model Management

Switch models dynamically:

```bash theme={null}
# GET /api/v1/images/models
# Returns available SD models

# Set active model
POST /api/v1/images/generations
{
  "model": "sd_xl_base_1.0.safetensors",
  "prompt": "..."
}
```

## Image Storage

Generated and edited images are automatically stored in the file system.

### Storage Flow

<Steps>
  <Step title="Generation/Edit">
    Image created by AI engine
  </Step>

  <Step title="Upload to Storage">
    * Converted to standard format (PNG/JPEG)
    * Assigned unique file ID
    * Metadata stored (prompt, model, parameters)
  </Step>

  <Step title="Database Record">
    File entry created with:

    * User association
    * Generation parameters
    * Timestamp
  </Step>

  <Step title="Chat Linking">
    Optional: Link to chat message for context
  </Step>
</Steps>

### Accessing Images

```bash theme={null}
# Get image by ID
GET /api/v1/files/{file-id}/content

# Returns image file
Content-Type: image/png
```

## Permissions

Control who can generate images:

```python theme={null}
# User permissions
{
  "USER_PERMISSIONS": {
    "features.image_generation": true  // Per-user setting
  }
}
```

<Warning>
  Image generation can be resource-intensive. Consider setting usage limits or restricting to specific user groups.
</Warning>

## Best Practices

<CardGroup cols={2}>
  <Card title="Prompt Engineering" icon="wand-magic-sparkles">
    **Write effective prompts:**

    * Be specific about style and details
    * Include lighting and mood
    * Specify artistic techniques
    * Use negative prompts to avoid unwanted elements
  </Card>

  <Card title="Quality vs Speed" icon="gauge">
    **Balance performance:**

    * More steps = better quality, slower
    * Larger sizes = more detail, higher cost
    * Test with low steps first
    * Increase for final generation
  </Card>

  <Card title="Model Selection" icon="brain">
    **Choose appropriate engine:**

    * OpenAI: Best quality, easiest setup
    * Gemini: Good balance, Google ecosystem
    * ComfyUI: Maximum control, self-hosted
    * AUTOMATIC1111: Free, extensive models
  </Card>

  <Card title="Cost Management" icon="dollar-sign">
    **Control expenses:**

    * Monitor API usage
    * Set generation limits
    * Use local engines for volume
    * Cache common generations
  </Card>
</CardGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Connection failed to image engine">
    **Check:**

    * Base URL is correct and accessible
    * API key is valid (if required)
    * Firewall allows connection
    * Engine is running and healthy
    * Authentication credentials correct
  </Accordion>

  <Accordion title="Poor image quality">
    **Solutions:**

    * Increase step count
    * Use larger image size
    * Refine prompt with more details
    * Try different model
    * Adjust sampling parameters
  </Accordion>

  <Accordion title="Generation timeout">
    **Fix:**

    * Reduce image size
    * Lower step count
    * Check engine performance
    * Increase timeout settings
    * Use faster sampler
  </Accordion>

  <Accordion title="ComfyUI workflow fails">
    **Verify:**

    * Workflow JSON is valid
    * Node IDs correctly mapped
    * Required models installed
    * ComfyUI API accessible
    * Workflow tested in ComfyUI first
  </Accordion>
</AccordionGroup>

## Advanced Features

### Auto-Size Support

Some models support automatic sizing:

```python theme={null}
{
  "IMAGE_SIZE": "auto"  // Model chooses optimal size
}
```

<Note>
  Auto-size is only supported by models matching the pattern: `gpt-image-*`, `dall-e-*`
</Note>

### Batch Generation

Generate multiple variations:

```python theme={null}
{
  "prompt": "A beautiful sunset",
  "n": 4  // Generate 4 variations
}
```

### Image Caching

Generated images are cached based on:

* Prompt hash
* Model configuration
* Generation parameters

Repeated identical requests return cached results instantly.

## API Reference

<CardGroup cols={2}>
  <Card title="Generate Image" icon="image">
    ```
    POST /api/v1/images/generations
    ```

    Create new images from prompts
  </Card>

  <Card title="Edit Image" icon="pen">
    ```
    POST /api/v1/images/edit
    ```

    Modify existing images
  </Card>

  <Card title="Get Models" icon="list">
    ```
    GET /api/v1/images/models
    ```

    List available image models
  </Card>

  <Card title="Get Config" icon="gear">
    ```
    GET /api/v1/images/config
    ```

    Retrieve current settings
  </Card>
</CardGroup>
