A powerful command-line tool for automating Stable Diffusion image generation through the WebUI API. Generate multiple images with different configurations, monitor progress in real-time, and save results with metadata.
The colorized terminal interface showing:
- Real-time progress bars with visual feedback
- Step-by-step generation tracking
- ETA estimates and completion status
- Colorized output for different message types
The tool integrates well with development environments, showing clean output and easy debugging capabilities.
- Batch Processing: Process multiple configurations from a JSONL file
- Real-time Progress: Live progress bars with step-by-step generation tracking
- Colorized Output: Beautiful terminal interface with chalk-powered colors
- Graceful Exit: Press 'z' to safely exit after current generation completes
- Organized Output: Automatic date-based directory organization
- Metadata Saving: Optional JSON metadata files with generation parameters
- Flexible Configuration: Extensive CLI options for customization
- Detailed Logging: Verbose mode with timestamps and file paths
# Clone or download the project
cd stable-diffusion-api-automate
# Install dependencies
npm install- Configure environment variables:
Copy the example environment file and customize it:
cp .env.example .envEdit .env file:
# Required: Your WebUI API URL
SD_WEBUI_URL=http://192.168.100.105:7860
# Optional: Default paths (can be overridden by CLI options)
# CONFIGS_FILE=prompts/configs.jsonl
# OUTPUT_DIR=out- Start Stable Diffusion WebUI with API enabled:
# Windows
.\webui.bat --listen --api
# Linux/Mac
./webui.sh --listen --apiThe --listen flag allows external connections, and --api enables the API endpoints required by this tool.
For more detailed API documentation, see: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API
- Prepare your configuration file (
prompts/configs.jsonl):
{"prompt": "1girl, solo, green tracksuit, black hair, brown eyes, mischievous smile", "negative_prompt": "worst quality, bad quality", "width": 720, "height": 1280, "sampler_name": "Euler a", "steps": 28, "cfg_scale": 7, "seed": -1, "batch_size": 1, "n_iter": 2, "hires_fix": false}
{"prompt": "1girl, solo, red dress, blonde hair, blue eyes, gentle smile", "negative_prompt": "worst quality, bad quality", "width": 720, "height": 1280, "sampler_name": "Euler a", "steps": 28, "cfg_scale": 7, "seed": -1, "batch_size": 1, "n_iter": 1, "hires_fix": false}- Run the tool:
npm start- Monitor progress and press 'z' if you need to stop gracefully.
# Run with default settings
npm start
# Show help
npm run help
# Run with verbose logging
npm start -- -v
# Use custom config file and output directory
npm start -- --configs-file custom.jsonl --output-dir ./my-images
# Save metadata files
npm start -- --save-meta
# Quiet mode (no config logging)
npm start -- --disable-log-config| Option | Description | Default |
|---|---|---|
--configs-file <path> |
Path to configs JSONL file | From .env or prompts/configs.jsonl |
--output-dir <path> |
Output directory for images | From .env or out |
--base-url <url> |
WebUI API base URL | From .env or http://localhost:7860 |
--save-meta |
Save metadata JSON files | false |
--disable-log-config |
Disable configuration logging | false |
-v, --verbose |
Enable verbose logging | false |
-h, --help |
Display help information | - |
- 'z' or 'Z': Graceful exit (completes current generation then stops)
- Ctrl+C: Force exit (immediate termination)
The tool uses environment variables for configuration. Create a .env file in the project root:
# Required: WebUI API URL
SD_WEBUI_URL=http://localhost:7860
# Optional: Default file paths
CONFIGS_FILE=prompts/configs.jsonl
OUTPUT_DIR=outSettings are applied in this order (highest to lowest priority):
- Command-line arguments (e.g.,
--base-url http://localhost:8080) - Environment variables (from
.envfile) - Default values
# Local WebUI (default port)
SD_WEBUI_URL=http://localhost:7860
# Local WebUI with custom port
SD_WEBUI_URL=http://localhost:8080
# Remote WebUI on local network
SD_WEBUI_URL=http://192.168.1.100:7860
# Remote WebUI with custom port
SD_WEBUI_URL=http://192.168.1.100:8080The configuration file should be in JSONL (JSON Lines) format, with each line containing a complete Stable Diffusion API payload:
{
"prompt": "your positive prompt here",
"negative_prompt": "your negative prompt here",
"width": 720,
"height": 1280,
"sampler_name": "Euler a",
"steps": 28,
"cfg_scale": 7,
"seed": -1,
"batch_size": 1,
"n_iter": 2,
"hires_fix": false
}All standard Stable Diffusion WebUI API parameters are supported:
prompt- Positive prompt textnegative_prompt- Negative prompt textwidth,height- Image dimensionssampler_name- Sampling methodsteps- Number of sampling stepscfg_scale- CFG scale valueseed- Random seed (-1 for random)batch_size- Number of images per batchn_iter- Number of iterationshires_fix- Enable high-resolution fix- And many more...
The tool provides detailed real-time progress information:
🔄 [████████████████░░░░░░░░░░░░░░] 57.1% Step 16/28 ETA: 12.3s
🔄 Iter 1/2: [████████████████░░░░░░░░░░░░░░] 57.1% Step 16/28 | Overall: [████████░░░░░░░░░░░░░░░░░░░░] 28.6% ETA: 25.1s
📸 [████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 30.0% Config 3/10
Generated files are organized by date:
out/
└── 2025-08-14/
├── 1723648392847-2605429855.png
├── 1723648392847-2605429855.meta.json (if --save-meta)
├── 1723648394123-2605429856.png
└── 1723648394123-2605429856.meta.json (if --save-meta)
Images are named using the format: [timestamp]-[seed].png
timestamp: Unix timestamp when the image was generatedseed: Actual seed used for generation (from API response)
When --save-meta is enabled, each image gets an accompanying .meta.json file containing:
{
"config": {
"prompt": "...",
"negative_prompt": "...",
"width": 720,
// ... full generation parameters
},
"response": {
"info": {
"seed": 2605429855,
// ... API response metadata
},
"timestamp": "2025-08-14T12:34:56.789Z",
"filename": "1723648392847-2605429855.png",
"seed": 2605429855
}
}- Stable Diffusion WebUI running with
--listen --apiflags - WebUI endpoint configured in
.envfile (see Environment Configuration section) - WebUI must be accessible from the machine running this tool
To start WebUI with API:
# Windows
.\webui.bat --listen --api
# Linux/Mac
./webui.sh --listen --apiImportant: Both --listen and --api flags are required:
--listen: Allows connections from other machines--api: Enables REST API endpoints
For comprehensive API documentation and advanced configuration options, visit:
https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API
- Ensure WebUI is running with
--apiflag - Check if the server IP/port is correct (default:
192.168.100.105:7860) - Verify firewall settings allow connections
- The tool automatically monitors
/sdapi/v1/progressendpoint - If progress seems stuck, the server might be overloaded
- Try reducing
n_iterorbatch_sizevalues
- Check WebUI console for error messages
- Verify your prompts don't contain invalid characters
- Ensure model is loaded in WebUI
- Make sure terminal supports raw mode input
- Try pressing 'z' multiple times
- Use Ctrl+C as last resort (may not save current generation)
# Generate images with default settings
npm start# Custom configuration with metadata saving
npm start -- \
--configs-file ./my-prompts.jsonl \
--output-dir ./renders \
--save-meta \
--verbose# Minimal output, no config logging
npm start -- --disable-log-config- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - feel free to use and modify as needed.

