Environment:A616567126 GPT WEB JAVA SD WebUI Service
| Knowledge Sources | |
|---|---|
| Domains | AI_Image_Generation, External_Service |
| Last Updated | 2026-10-13 18:00 GMT |
Overview
AUTOMATIC1111 Stable Diffusion WebUI with `--api` flag, accessed via REST API on port 7860 for text-to-image and image-to-image generation.
Description
This environment provides the external Stable Diffusion image generation service for GPT-WEB-JAVA. It communicates with the AUTOMATIC1111 SD WebUI via its REST API. The application calls the SD WebUI at a configurable URL (default `http://127.0.0.1:7860`) using Hutool's HttpUtil for POST requests. Supported endpoints include: `/sdapi/v1/txt2img` (text-to-image), `/sdapi/v1/img2img` (image-to-image), `/sdapi/v1/samplers` (sampler list), `/sdapi/v1/progress` (generation progress), and `/sdapi/v1/png-info` (PNG metadata). The SD WebUI must be started with the `--api` flag to expose REST endpoints. Optional authentication is supported via a configurable auth header. Image generation requests are queued through Redis with a maximum queue size of 5.
Usage
Use this environment for Stable Diffusion image generation. Required when `sys_config.is_open_sd = 1`. The SdController, MyTask scheduled job, and QueueUtil all depend on this service being available. Prompts are automatically translated to English via Baidu Translate before sending to SD.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux recommended | SD WebUI runs on any OS with Python |
| Hardware | NVIDIA GPU with 6GB+ VRAM | For Stable Diffusion model inference |
| Disk | 10GB+ for models and outputs | SD checkpoint files are large (2-7GB each) |
| Network | SD WebUI API accessible from application | Default: 127.0.0.1:7860 (same machine) |
Dependencies
External Services
- AUTOMATIC1111 Stable Diffusion WebUI (started with `--api` flag)
Java Packages (Maven)
- `hutool-all` = 5.8.12 (for HttpUtil REST calls)
Credentials
Credentials are stored in the `sys_config` database table:
- `sd_url`: SD WebUI base URL (e.g., `http://127.0.0.1:7860`)
- `sd_auth`: Optional Bearer token for SD WebUI API authentication
- `is_open_sd`: Must be `1` to enable SD functionality
Quick Install
# Start SD WebUI with API enabled:
# git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
# cd stable-diffusion-webui
# ./webui.sh --api
# Or with specific listen address:
./webui.sh --api --listen --port 7860
# Configure in GPT-WEB-JAVA:
# Set sys_config.sd_url = "http://127.0.0.1:7860"
# Set sys_config.is_open_sd = 1
Code Evidence
SD API endpoints from `CommonConst.java:259-282`:
public static final String SD_TXT_2_IMG = "/sdapi/v1/txt2img";
public static final String SD_IMG_2_IMG = "/sdapi/v1/img2img";
public static final String SD_SAMPLERS = "/sdapi/v1/samplers";
public static final String SD_PROGRESS = "/sdapi/v1/progress?skip_current_image=false";
public static final String SD_PNG_INFO = "/sdapi/v1/png-info";
SD request with auth header from `MyTask.java:81-86`:
String body = HttpUtil.createPost(postUrl)
.header(Header.CONTENT_TYPE, ContentType.JSON.getValue())
.header(Header.AUTHORIZATION, null != cacheObject.getSdAuth() ? cacheObject.getSdAuth() : null)
.body(StringUtil.toUnderlineCase(param))
.execute()
.body();
Queue size limit from `CommonConst.java:250`:
public static final Integer QUEUE_SIZE = 5;
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `Connection refused` | SD WebUI not running or `--api` flag not set | Start SD WebUI with `--api` flag |
| `队列已满请等待` | SD image generation queue is full (max 5) | Wait for queue to drain or increase `QUEUE_SIZE` constant |
| `图片生成失败` | SD WebUI returned error or invalid base64 image | Check SD WebUI logs; verify model is loaded |
| `401 Unauthorized` | SD WebUI auth required but not configured | Set `sd_auth` in `sys_config` table |
Compatibility Notes
- SD WebUI versions: API is stable across AUTOMATIC1111 releases; any recent version with `--api` flag works.
- Queue limit: Hardcoded `QUEUE_SIZE = 5`; for higher throughput, increase this value and ensure SD WebUI can handle concurrent requests.
- Prompt translation: Chinese prompts are auto-translated to English via Baidu Translate before sending to SD; configure Baidu translate API in `sys_config`.
- Image storage: Generated images are saved as base64-decoded files on the local filesystem at `img_upload_url` path, then served via Nginx static file proxy.