image-generator-sd-webui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImage Generator (sd-webui API)
图像生成器(sd-webui API)
Overview
概述
Drive a Stable Diffusion WebUI / Forge server through its REST API to enumerate available resources, run , poll progress, and interrupt jobs. All scripts under are thin wrappers; they print JSON or extracted fields to stdout so the agent can pipe / parse them.
txt2imgscripts/curl通过REST API控制Stable Diffusion WebUI / Forge服务器,枚举可用资源、运行任务、查询进度并中断任务。目录下的所有脚本都是轻量的封装;它们会将JSON或提取的字段输出到标准输出,以便Agent进行管道传输或解析。
txt2imgscripts/curlServer connection
服务器连接
Before doing anything, confirm the server URL (and optional HTTP Basic Auth) with the user. Pass them as environment variables to every script:
bash
export SD_WEBUI_URL="http://localhost:7860" # required, no trailing slash
export SD_WEBUI_USER="" # optional, HTTP Basic Auth
export SD_WEBUI_PASS="" # optionalIf unset, scripts default to with no auth.
http://localhost:7860Quick connectivity test (returns on success, exits non-zero on failure):
OK <url>bash
scripts/probe.sh在执行任何操作之前,请与用户确认服务器URL(以及可选的HTTP基本认证信息)。将它们作为环境变量传递给每个脚本:
bash
export SD_WEBUI_URL="http://localhost:7860" # 必填,末尾不能带斜杠
export SD_WEBUI_USER="" # 可选,HTTP基本认证用户名
export SD_WEBUI_PASS="" # 可选,HTTP基本认证密码如果未设置,脚本默认使用且不启用认证。
http://localhost:7860快速连接测试(成功时返回,失败时返回非零退出码):
OK <url>bash
scripts/probe.shWorkflow
工作流程
- Probe — Verify the server is reachable (). On failure, ask the user for the correct URL / credentials.
scripts/probe.sh - Enumerate & choose — List the resources to pick (models, modules, samplers, schedulers, styles) and ask the user to choose. Capture their choice verbatim in the API's English /
name/title— sd-webui matches exactly, do not translate or rename.model_name - Prompt — Obtain the positive prompt, negative prompt, and any extra params (steps, CFG, size). See "Prompt engineering" for sourcing these.
- Generate — Call with a request JSON. It returns a JSON object containing the base64 PNG image and the generation
scripts/generate.sh.info - (Optional) Track progress — While generation is running (in another shell / background), call to print
scripts/progress.sh(0–1),progress, andeta_relative.state - (Optional) Cancel — Call to interrupt the current job.
scripts/cancel.sh
- 探测 — 验证服务器是否可达()。如果失败,请询问用户正确的URL/凭据。
scripts/probe.sh - 枚举与选择 — 列出可供选择的资源(模型、模块、采样器、调度器、风格)并让用户选择。请完整保留用户选择的API英文/
name/title字段内容 — sd-webui要求完全匹配,请勿翻译或重命名。model_name - 提示词 — 获取正向提示词、负向提示词以及任何额外参数(步数、CFG值、图像尺寸)。提示词相关内容请参考「提示词工程」部分。
- 生成 — 使用请求JSON调用。它会返回一个包含base64格式PNG图像和生成
scripts/generate.sh信息的JSON对象。info - (可选)跟踪进度 — 在生成任务运行期间(在另一个shell/后台执行),调用来输出
scripts/progress.sh(0–1)、progress和eta_relative信息。state - (可选)取消 — 调用中断当前任务。
scripts/cancel.sh
Tasks
任务
Listing available resources
列出可用资源
| User wants | Command | API endpoint |
|---|---|---|
| Checkpoints (models) | | |
| Extra modules (TE / VAE, Forge-only) | | |
| Samplers | | |
| Schedulers | | |
| Style presets | | |
| Upscalers | | |
| LoRAs | | |
| Embeddings | | |
scripts/list.sh <kind>columnfzf--jsonAfter listing, present the options to the user (use with an enum if the list is short). For models, prefer the full (which embeds the hash suffix, e.g. ) over because the title is unambiguous — if the user supplies a bare filename without the hash, verify it via and substitute the exact title before sending it to the API. For schedulers, prints the human-readable (e.g. ); both and the lowercase () are accepted by the txt2img field.
ask_usertitleanima/animaika_v36.safetensors [d50fb5b9a0]model_namelist.sh modelslist.sh schedulerslabelBetalabelnamebetascheduler| 用户需求 | 命令 | API 端点 |
|---|---|---|
| 模型(Checkpoints) | | |
| 额外模块(TE/VAE,仅Forge支持) | | |
| 采样器 | | |
| 调度器 | | |
| 风格预设 | | |
| 图像放大工具 | | |
| LoRA模型 | | |
| Embeddings模型 | | |
scripts/list.sh <kind>columnfzf--json列出资源后,将选项展示给用户(如果列表较短,可使用配合枚举选项)。对于模型,优先使用完整的(包含哈希后缀,例如)而非,因为标题具有明确的唯一性 — 如果用户提供的是不带哈希的裸文件名,请通过验证并替换为精确的标题后再发送给API。对于调度器,会输出易读的(例如);txt2img的字段同时接受和小写的()。
ask_usertitleanima/animaika_v36.safetensors [d50fb5b9a0]model_namelist.sh modelslist.sh schedulerslabelBetaschedulerlabelnamebetaGenerating an image (txt2img)
生成图像(txt2img)
- Build a JSON request. Required field: . Recommended:
prompt,negative_prompt,steps,cfg_scale,width,height,sampler_name,scheduler(array of style names), andstyles(model title) /override_settings.sd_model_checkpoint(array of module names, Forge only). Seeoverride_settings.forge_additional_modulesfor every field.references/txt2img-parameters.md - Run:
bash
scripts/generate.sh request.json > result.json # or pipe: cat request.json | scripts/generate.sh - > result.json - Extract the image (base64 PNG):
bash
jq -r '.images[0]' result.json | base64 -d > out.png - The field is a JSON string with
info,seed,all_prompts, etc. — parse withsampler_name.jq -r '.info | fromjson'
Important behaviour notes:
- pre-pin: sd-webui/Forge validates
samples_formatbefore applyingsamples_format, so if the server's persistent value is unsupported (e.g.override_settings), txt2img fails.avifpreemptivelygenerate.shsPOSTtosamples_format=pngand redundantly injects/sdapi/v1/options. ⚠️ The pre-pin mutates the server's persistent default tooverride_settings.samples_format=png—"png"cannot undo it. If the user shares the server with clients expecting a different default, restore manually after:override_settings_restore_afterwards. Convert locally if you need non-PNG output (see "Converting to another format" below).scripts/options.sh set samples_format '"webp"' - is forced on by
override_settings_restore_afterwards: trueso the othergenerate.shkeys (model checkpoint, modules, VAE) do not stick.override_settings - Generation is synchronous — the POST blocks until the image is ready. The script uses a 600s curl timeout; override with .
SD_WEBUI_TIMEOUT=900 scripts/generate.sh ...
- 构建JSON请求。必填字段:。推荐字段:
prompt、negative_prompt、steps、cfg_scale、width、height、sampler_name、scheduler(风格名称数组)以及styles(模型标题)/override_settings.sd_model_checkpoint(模块名称数组,仅Forge支持)。所有字段详情请参考override_settings.forge_additional_modules。references/txt2img-parameters.md - 运行:
bash
scripts/generate.sh request.json > result.json # 或通过管道传输: cat request.json | scripts/generate.sh - > result.json - 提取图像(base64格式PNG):
bash
jq -r '.images[0]' result.json | base64 -d > out.png - 字段是包含
info、seed、all_prompts等信息的JSON字符串 — 可通过sampler_name解析。jq -r '.info | fromjson'
重要行为说明:
- 预固定:sd-webui/Forge会在应用
samples_format之前验证override_settings,因此如果服务器的持久化值不被支持(例如samples_format),txt2img任务会失败。avif会预先向generate.sh发送/sdapi/v1/options请求设置POST,同时会在请求中冗余注入samples_format=png。⚠️ 此预固定操作会将服务器的持久化默认值修改为override_settings.samples_format=png—"png"无法撤销此修改。如果用户与其他期望不同默认格式的客户端共享服务器,请在任务完成后手动恢复:override_settings_restore_afterwards。如果需要非PNG格式的输出,请在本地转换(见下文「转换为其他格式」)。scripts/options.sh set samples_format '"webp"' - 强制启用
generate.sh,因此其他override_settings_restore_afterwards: true键(模型checkpoint、模块、VAE)不会保留。override_settings - 生成任务是同步的 — POST请求会阻塞直到图像生成完成。脚本使用600秒的curl超时时间;可通过覆盖此设置。
SD_WEBUI_TIMEOUT=900 scripts/generate.sh ...
Converting to another format
转换为其他格式
If the user wants the output in a non-PNG format (WebP, AVIF, JPEG, etc.), do not try to re-enable a different on the server. Instead, convert locally while preserving the embedded sd-webui generation metadata:
samples_format- Check whether both and
format-converter.share available oncopy-info.sh(e.g.PATH).command -v format-converter.sh && command -v copy-info.sh - If both are present, run on the PNG — it calls
format-converter.shinternally to carry the parameters over. Runcopy-info.shto see the current usage.format-converter.sh -h - If either is missing, guide the user to install the helper project once: https://github.com/jim60105/sd-image-format-converter. It has system dependencies that must be set up manually, so it can't be auto-installed. After install, both scripts should be on and
PATHwill show usage.-h
如果用户需要非PNG格式的输出(WebP、AVIF、JPEG等),请勿尝试在服务器上重新启用其他。请在本地转换并保留sd-webui生成的嵌入元数据:
samples_format- 检查和
format-converter.sh是否都在copy-info.sh中(例如执行PATH)。command -v format-converter.sh && command -v copy-info.sh - 如果两者都存在,对PNG文件运行— 它会内部调用
format-converter.sh来传递参数。运行copy-info.sh查看使用说明。format-converter.sh -h - 如果缺少其中任意一个,请引导用户安装辅助项目:https://github.com/jim60105/sd-image-format-converter。该项目有必须手动配置的系统依赖,因此无法自动安装。安装完成后,两个脚本应在中,且
PATH会显示使用说明。-h
Tracking progress
跟踪进度
Call from another terminal (or background the call with first):
generate.sh&bash
scripts/progress.sh # one-shot, prints JSON
scripts/progress.sh --watch # poll every 1s until progress reaches 1.0 or state.job is empty
scripts/progress.sh --watch --interval 2
scripts/progress.sh --field progress # just the numeric 0..1 value
scripts/progress.sh --field state.jobEndpoint: . Key response fields:
GET /sdapi/v1/progress?skip_current_image=true- — float 0..1, fraction of current job complete.
progress - — estimated seconds remaining.
eta_relative - — current job name (empty string when idle).
state.job - /
state.sampling_step— current step index / total.state.sampling_steps - — base64 PNG preview of the in-progress image (omitted by the script via
current_imageto keep responses small; fetch raw withskip_current_image=trueif needed).curl
从另一个终端调用(或先将放入后台执行):
generate.sh&bash
scripts/progress.sh # 单次查询,输出JSON
scripts/progress.sh --watch # 每秒轮询一次,直到进度达到1.0或state.job为空
scripts/progress.sh --watch --interval 2
scripts/progress.sh --field progress # 仅输出0..1的数值进度
scripts/progress.sh --field state.job端点:。关键响应字段:
GET /sdapi/v1/progress?skip_current_image=true- — 0到1之间的浮点数,表示当前任务的完成比例。
progress - — 预计剩余秒数。
eta_relative - — 当前任务名称(空闲时为空字符串)。
state.job - /
state.sampling_step— 当前步数索引 / 总步数。state.sampling_steps - — 生成中图像的base64格式PNG预览(脚本通过
current_image省略此字段以减小响应体积;如需获取可直接使用skip_current_image=true调用)。curl
Cancelling
取消任务
bash
scripts/cancel.sh # POST /sdapi/v1/interrupt — stop current job, return current partial result
scripts/cancel.sh --skip # POST /sdapi/v1/skip — skip current job in a batchNote: is cooperative — it tells the sampler to stop at the next step. The pending call will return with whatever the model produced so far (often a usable but partial image). It does not raise an HTTP error on the txt2img call.
interruptgenerate.shbash
scripts/cancel.sh # POST /sdapi/v1/interrupt — 停止当前任务,返回当前已生成的部分结果
scripts/cancel.sh --skip # POST /sdapi/v1/skip — 跳过批量任务中的当前任务注意:是协作式的 — 它通知采样器在下一个步骤停止。正在执行的调用会返回模型当前生成的内容(通常是可用但未完成的图像)。此操作不会在txt2img调用中引发HTTP错误。
interruptgenerate.shGlobal options (advanced)
全局选项(高级)
scripts/options.shGET /sdapi/v1/optionsPOST /sdapi/v1/optionsbash
scripts/options.sh get # print all options as JSON
scripts/options.sh get sd_model_checkpoint # print one key
scripts/options.sh set sd_model_checkpoint '"<title>"' # set one key (value is JSON; string must be quoted)
scripts/options.sh set-json '{"k1":"v1","k2":"v2"}' # set multiple keys
scripts/options.sh refresh-checkpoints # POST /sdapi/v1/refresh-checkpointsPrefer inside the request over — is request-scoped and reverts after the call, while persists globally and affects every other client.
override_settingstxt2imgoptions setoverride_settingsoptions setscripts/options.shGET /sdapi/v1/optionsPOST /sdapi/v1/optionsbash
scripts/options.sh get # 输出所有选项的JSON
scripts/options.sh get sd_model_checkpoint # 输出单个键的值
scripts/options.sh set sd_model_checkpoint '"<title>"' # 设置单个键的值(值为JSON格式;字符串必须加引号)
scripts/options.sh set-json '{"k1":"v1","k2":"v2"}' # 设置多个键的值
scripts/options.sh refresh-checkpoints # POST /sdapi/v1/refresh-checkpoints优先在请求中使用而非 — 仅作用于当前请求,调用后会恢复原状,而会全局持久化,影响所有其他客户端。
txt2imgoverride_settingsoptions setoverride_settingsoptions setPrompt engineering
提示词工程
This skill does not generate or refine prompts. When the user asks for prompt help:
- Check whether another agent skill is available for prompt engineering (search by name: e.g. ,
sd-prompt-builder,danbooru-prompt). If so, delegate to it.image-prompt-* - Otherwise, ask the user for the prompt explicitly, or accept a natural-language description and pass it through verbatim as the field. Do not invent Danbooru tags or stylistic modifiers on your own.
prompt
此技能不负责生成或优化提示词。当用户请求提示词帮助时:
- 检查是否有其他Agent技能可用于提示词工程(按名称搜索:例如、
sd-prompt-builder、danbooru-prompt)。如果有,请将任务委托给该技能。image-prompt-* - 如果没有,请明确向用户索要提示词,或接受自然语言描述并直接将其作为字段传递。请勿自行添加Danbooru标签或风格修饰词。
prompt
References
参考资料
- — full sd-webui / Forge endpoint reference with request / response shapes for every endpoint this skill uses, plus useful adjacent ones (
references/api-endpoints.md,/sdapi/v1/memory, etc.)./sdapi/v1/png-info - — every
references/txt2img-parameters.mdrequest field including HiRes-fix, refiner, Forge-specific extensions (txt2img,forge_additional_modules,forge_inference_memory), andforge_presetkeys.override_settings
Read these only when constructing a non-trivial request or hitting an error that needs deeper investigation.
- — 完整的sd-webui / Forge端点参考,包含此技能使用的所有端点的请求/响应格式,以及其他有用的相邻端点(
references/api-endpoints.md、/sdapi/v1/memory等)。/sdapi/v1/png-info - — 所有
references/txt2img-parameters.md请求字段,包括高清修复(HiRes-fix)、细化器(refiner)、Forge专属扩展(txt2img、forge_additional_modules、forge_inference_memory)以及forge_preset键。override_settings
仅在构造非平凡请求或遇到需要深入调查的错误时参考这些文档。