# A1111 (Stable Diffusion WebUI)

Image generation via the [Automatic1111 Stable Diffusion WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) REST API. Best for photorealism, portraits, anime, and artistic styles.

## Setup

1. Install and start [A1111 WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) with API access enabled:

    ```bash
    # Start WebUI with API enabled
    python launch.py --api
    ```

2. Set the host URL:

    ```bash
    IMAGE_GENERATION_MCP_A1111_HOST=http://localhost:7860
    ```

The provider registers automatically when `IMAGE_GENERATION_MCP_A1111_HOST` is set.

## Model-aware presets

The provider auto-detects the SD architecture from the checkpoint name and applies optimized generation parameters:

### SD 1.5 (default)

Used when no XL/Lightning/Turbo tag is found in the checkpoint name.

| Parameter | Value |
|-----------|-------|
| Base resolution | 768px |
| Steps | 30 |
| CFG scale | 7.0 |
| Sampler | DPM++ 2M Karras |

| Aspect ratio | Size |
|-------------|------|
| `1:1` | 768x768 |
| `16:9` | 912x512 |
| `9:16` | 512x912 |
| `3:2` | 768x512 |
| `2:3` | 512x768 |

### SDXL

Used when checkpoint name contains `sdxl`, `xl_`, `_xl`, or `-xl`.

| Parameter | Value |
|-----------|-------|
| Base resolution | 1024px |
| Steps | 35 |
| CFG scale | 7.5 |
| Sampler | DPM++ 2M Karras |

| Aspect ratio | Size |
|-------------|------|
| `1:1` | 1024x1024 |
| `16:9` | 1344x768 |
| `9:16` | 768x1344 |
| `3:2` | 1216x832 |
| `2:3` | 832x1216 |

### SDXL Lightning/Turbo

Used when checkpoint name contains XL tags AND `lightning` or `turbo`.

| Parameter | Value |
|-----------|-------|
| Base resolution | 1024px |
| Steps | 6 |
| CFG scale | 2.0 |
| Sampler | DPM++ SDE Karras |

Sizes are the same as standard SDXL.

## Checkpoint override

To use a specific checkpoint (and enable preset detection from its name):

```bash
IMAGE_GENERATION_MCP_A1111_MODEL=realisticVisionV60B1_v51VAE.safetensors
```

When `A1111_MODEL` is set, the provider sends `override_settings.sd_model_checkpoint` in the API payload.

## Negative prompts

A1111 has native negative prompt support via the `negative_prompt` field in the API payload. This is more effective than OpenAI's "Avoid:" workaround.

See the [Prompt Writing Guide](../guides/prompt-writing.md) for recommended negative prompts.

## Metadata

The provider extracts from the A1111 response:

- **seed** -- the random seed used for generation (useful for reproducibility)
- **model name** -- the active checkpoint name (from response `info` JSON)
- **size** -- pixel dimensions used
- **steps** -- number of diffusion steps

## Timeout

The default timeout is **180 seconds**. SDXL at high resolution on consumer GPUs can take 30-60+ seconds. If you experience timeouts, ensure your WebUI is responding.

## Troubleshooting

| Error | Cause | Resolution |
|-------|-------|------------|
| Connection error | Cannot reach A1111 WebUI | Verify WebUI is running with `--api` flag at the configured host |
| Timeout (180s) | Generation too slow | Check GPU utilization; consider a faster model or lower resolution |
| HTTP 404 | Wrong API endpoint | Verify the WebUI version supports `/sdapi/v1/txt2img` |
