Stable Diffusion with LoRAs
集成
模型 id
lora
# Run the model; wait up to 20 s for the finished result in the same call
curl -X POST "https://api.doitong.com/v1/run/lora?wait=20" \
-H "Authorization: Bearer $DOITONG_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
}'
# Still "queued" or "running"? Poll with the id from the response:
curl "https://api.doitong.com/v1/requests/REQUEST_ID?wait=20" \
-H "Authorization: Bearer $DOITONG_API_KEY"
const API = "https://api.doitong.com/v1";
const headers = {
"Authorization": "Bearer " + process.env.DOITONG_API_KEY,
"Content-Type": "application/json",
};
// Run the model; wait up to 20 s for the finished result in the same call
let res = await fetch(API + "/run/lora?wait=20", {
method: "POST",
headers,
body: JSON.stringify({
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
}),
});
let request = await res.json();
if (!res.ok) throw new Error(request.error.code + ": " + request.error.message);
// Not finished yet: long-poll until it is
while (request.status === "queued" || request.status === "running") {
res = await fetch(API + "/requests/" + request.id + "?wait=20", { headers });
request = await res.json();
}
if (request.status !== "succeeded") throw new Error(JSON.stringify(request.error));
console.log(request.outputs.map((o) => o.url), request.cost.credits + " API credits ($" + request.cost.usd + ")");
import os
import requests
API = "https://api.doitong.com/v1"
headers = {"Authorization": "Bearer " + os.environ["DOITONG_API_KEY"]}
payload = {
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field",
}
# Run the model; wait up to 20 s for the finished result in the same call
r = requests.post(API + "/run/lora", params={"wait": 20}, json=payload, headers=headers)
request = r.json()
if not r.ok:
raise RuntimeError(request["error"]["code"] + ": " + request["error"]["message"])
# Not finished yet: long-poll until it is
while request["status"] in ("queued", "running"):
request = requests.get(API + "/requests/" + request["id"], params={"wait": 20}, headers=headers).json()
if request["status"] != "succeeded":
raise RuntimeError(request["error"])
print([o["url"] for o in request["outputs"]], request["cost"]["credits"], "API credits", "$" + request["cost"]["usd"])
# 1. Connect once (Claude Code; Cursor, VS Code, Claude Desktop: https://doitong.com/zh-CN/developers/docs/mcp)
claude mcp add --transport http doitong-models https://api.doitong.com/v1/mcp \
--header "Authorization: Bearer $DOITONG_API_KEY"
# 2. Your agent calls the "run" tool with:
{
"model_id": "lora",
"input": {
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
}
}
通过 Doitong API 调用 Stable Diffusion with LoRAs 模型(lora)。智能体文档:https://doitong.com/zh-CN/developers/models/lora.md
POST https://api.doitong.com/v1/run/lora?wait=20
Authorization: Bearer $DOITONG_API_KEY
Content-Type: application/json
{
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
}
如果响应状态为 "queued" 或 "running",请轮询 GET https://api.doitong.com/v1/requests/REQUEST_ID?wait=20,直到状态变为 "succeeded";文件位于 outputs[].url。使用相同请求体 POST https://api.doitong.com/v1/quote/lora,可在运行前返回确切价格。
此请求: ≈$0.057 57 API 积分 在此页面运行
你的新 API 密钥。 它只会在此时显示,并且已填入下方的代码和 API 密钥字段中。请妥善保管:切勿将其放入在浏览器中运行的代码里。
构建请求
控件根据模型架构生成。修改控件时,代码和价格会同步更新。
POST
/run/lora?wait=20
报价 → $0.057
# Run the model; wait up to 20 s for the finished result in the same call
curl -X POST "https://api.doitong.com/v1/run/lora?wait=20" \
-H "Authorization: Bearer $DOITONG_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
}'
# Still "queued" or "running"? Poll with the id from the response:
curl "https://api.doitong.com/v1/requests/REQUEST_ID?wait=20" \
-H "Authorization: Bearer $DOITONG_API_KEY"
const API = "https://api.doitong.com/v1";
const headers = {
"Authorization": "Bearer " + process.env.DOITONG_API_KEY,
"Content-Type": "application/json",
};
// Run the model; wait up to 20 s for the finished result in the same call
let res = await fetch(API + "/run/lora?wait=20", {
method: "POST",
headers,
body: JSON.stringify({
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
}),
});
let request = await res.json();
if (!res.ok) throw new Error(request.error.code + ": " + request.error.message);
// Not finished yet: long-poll until it is
while (request.status === "queued" || request.status === "running") {
res = await fetch(API + "/requests/" + request.id + "?wait=20", { headers });
request = await res.json();
}
if (request.status !== "succeeded") throw new Error(JSON.stringify(request.error));
console.log(request.outputs.map((o) => o.url), request.cost.credits + " API credits ($" + request.cost.usd + ")");
import os
import requests
API = "https://api.doitong.com/v1"
headers = {"Authorization": "Bearer " + os.environ["DOITONG_API_KEY"]}
payload = {
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field",
}
# Run the model; wait up to 20 s for the finished result in the same call
r = requests.post(API + "/run/lora", params={"wait": 20}, json=payload, headers=headers)
request = r.json()
if not r.ok:
raise RuntimeError(request["error"]["code"] + ": " + request["error"]["message"])
# Not finished yet: long-poll until it is
while request["status"] in ("queued", "running"):
request = requests.get(API + "/requests/" + request["id"], params={"wait": 20}, headers=headers).json()
if request["status"] != "succeeded":
raise RuntimeError(request["error"])
print([o["url"] for o in request["outputs"]], request["cost"]["credits"], "API credits", "$" + request["cost"]["usd"])
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "run",
"arguments": {
"model_id": "lora",
"input": {
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
},
"wait_seconds": 20
}
}
}
关于 Stable Diffusion with LoRAs
使用 `model_name` 中通过 URL 或 HuggingFace ID 指定的基础模型,根据文本提示词生成图像。可合并多个 `loras`,并支持嵌入、ControlNet、IP adapter 和 IC Light 输入。采样器选项包括多种调度器,步数为 1 到 150。生成 1 到 8 张 png 或 jpeg 图像。
参数
发送规范名称或原生名称之一,不要同时发送两者。 规范名称
名称类型
默认值允许值
描述
model_name必填
类型string
用于生成图像的基础模型,可通过 URL 或 HuggingFace ID 指定。
unet_name可选
类型string | null
用于生成图像的自定义 U-Net 选择;请提供其 HuggingFace ID 或 URL。
variant可选
类型string | null
HuggingFace 模型变体选择;'fp16' 是其中一个示例。
prompt必填
类型string
描述要生成的图像;尽可能提供详细信息以获得最佳结果。
negative_prompt可选
类型string
默认值
指定不需要的图像细节的负面提示词。可排除颜色、对象、场景或更细致的特征和质量,例如胡须、模糊或低分辨率。
prompt_weighting可选
类型boolean
默认值false
提示词加权开关:true 会通过嵌入平均移除 77 Token 限制,并启用加权语法。
loras可选
类型object[]
默认值[]
其组合效果用于生成图像的 LoRA,数量不限。
loras[].path必填
类型string
LoRA 权重的位置,以 URL 或路径指定。
loras[].scale可选
类型number
默认值1
0 – 4
合并到基础模型前应用于 LoRA 权重的倍数。
embeddings可选
类型object[]
默认值[]
图像生成期间应用的嵌入,用于将提示词 Token 映射到嵌入权重。目前仅支持一个嵌入。
embeddings[].path必填
类型string
通过 URL 或文件路径指定的嵌入权重。
embeddings[].tokens可选
类型string[]
映射到嵌入权重的提示词 Token。省略时会为每个嵌入文件向量创建一个 Token,命名为 <s0>、<s1>、...;请在提示词中使用这些映射后的 Token。
controlnets可选
类型object[]
默认值[]
生成期间在指定时间步应用于图像的 ControlNet,数量不限。
controlnets[].path必填
类型string
ControlNet 权重位置,可指定为 URL 或路径。
controlnets[].config_url可选
类型string | null
可选的 URL,指向 ControlNet 的 config.json 文件。
controlnets[].variant可选
类型string | null
与 Hugging Face 仓库密钥配合使用的可选变体。
controlnets[].image_url必填
类型url · image
作为 ControlNet 输入提供的图像 URL。
controlnets[].mask_url可选
类型url · image
ControlNet 蒙版(如提供,必须与控制图像尺寸一致);宽度和高度都必须能被 32 整除。
controlnets[].conditioning_scale可选
类型number
默认值1
0 – 2
ControlNet 权重合并到基础模型前应用的缩放。
controlnets[].start_percentage可选
类型number
默认值0
0 – 1
ControlNet 开始影响图像生成时所处的总时间步百分比。
controlnets[].end_percentage可选
类型number
默认值1
0 – 1
ControlNet 停止影响图像生成时所处的总时间步百分比。
controlnets[].ip_adapter_index可选
类型integer | null
通过索引为 InstantID ControlNet 选择 IP 适配器;其他 ControlNet 无需此设置。
controlnet_guess_mode可选
类型boolean
默认值false
为 true 时,将 ControlNet 的应用限制为条件预测。
ip_adapter可选
类型object[]
默认值[]
用于生成图像的 IP 适配器。提供任何条目都需要 image_encoder_path。
ip_adapter[].ip_adapter_image_url必填
类型url · image
作为 IP 适配器输入提供的图像 URL。
ip_adapter[].ip_adapter_mask_url可选
类型url · image
IP 适配器蒙版(如提供,其尺寸必须与适配器图像一致)。
ip_adapter[].path必填
类型string
IP 适配器权重位置,以 URL 或路径指定。
ip_adapter[].model_subfolder可选
类型string | null
IP 适配器权重位置,以模型目录中的子文件夹指定。
ip_adapter[].weight_name可选
类型string | null
权重文件名。
ip_adapter[].insight_face_model_path可选
类型string | null
InsightFace 模型权重位置,以 URL 或路径指定。
ip_adapter[].scale可选
类型number
默认值1
≥ 0
IP 适配器权重的缩放因子,在合并到基础模型之前应用。
ip_adapter[].scale_json可选
类型object | null
IP 适配器权重的缩放因子,在合并到基础模型之前应用。
ip_adapter[].unconditional_noising_factor可选
类型number
默认值0
0 – 1
控制 IP 适配器无条件加噪的因子。
ip_adapter[].image_projection_shortcut可选
类型boolean
默认值true
图像投影快捷设置,默认值为 True。FaceID plus V1 模型使用 False,FaceID plus V2 模型使用 True。
image_encoder_path可选
类型string | null
通过 HTTPS URL 或 Hugging Face ID 指定的图像编码器,其兼容性由 IP-Adapter 权重决定:SD1.5 使用 image_encoder_subfolder='models/image_encoder',而 h94/IP-Adapter SDXL 使用 h94/IP-Adapter 和 image_encoder_subfolder='sdxl_models/image_encoder'。只要 ip_adapter 包含值,就必须提供编码器。
image_encoder_subfolder可选
类型string | null
image_encoder_path 中存放图像编码器权重的子目录。
image_encoder_weight_name可选
类型string | null
默认值pytorch_model.bin
按名称选择用于生成图像的图像编码器权重。
ic_light_model_url可选
类型string | null
生成图像时使用的 IC Light 模型 URL。
ic_light_model_background_image_url可选
类型url · image
用于 IC Light 图像生成的模型兼容背景,以图像 URL 提供。
ic_light_image_url可选
类型url · image
使用 IC Light 模型生成时的输入图像 URL。
seed可选
类型integer | null
用于在 Stable Diffusion 中复现图像的种子。保持模型版本、提示词和种子不变,即可在每次运行中完全复现图像。
image_size可选
类型object
默认值square_hd
square_hdsquareportrait_4_3portrait_16_9landscape_4_3landscape_16_9
输出图像尺寸,可从预设中选择,或指定自定义宽度和高度。两个自定义尺寸都必须能被 8 整除。
num_inference_steps可选
类型integer
默认值30
1 – 150
控制 Stable Diffusion 执行的生成步数;增加步数可能得到细节更丰富的最终图像。
guidance_scale可选
类型number
默认值7.5
0 – 20
图像选择的提示词遵循强度,以 CFG(Classifier Free Guidance)表示。
clip_skip可选
类型integer
默认值0
0 – 2
跳过部分图像生成以加快渲染速度,但结果会略有不同。
scheduler可选
类型enum
DPM++ 2MDPM++ 2M KarrasDPM++ 2M SDEDPM++ 2M SDE KarrasEulerEuler AEuler (trailing timesteps)LCMLCM (trailing timesteps)DDIMTCD
用于对图像去噪的调度器或采样器。
timesteps可选
类型object
默认值{"array":[],"method":"default"}
去噪时间步计划覆盖项,与 sigmas 互斥。没有覆盖项(默认)时,调度器根据 num_inference_steps 计算时间步;提供自定义计划后,num_inference_steps 不再生效。覆盖项要求调度器支持 set_timesteps 的 timesteps 参数。
timesteps.method可选
类型enum
默认值default
defaultarray
选择时间步的确定方式:'default'(默认设置)允许调度器使用 `num_inference_steps`。如需自行提供时间步计划,请选择 'array',并将计划放入 `array` 字段。
timesteps.array可选
类型integer[]
默认值[]
所选方法为 'custom' 时应用的时间步计划。
sigmas可选
类型object
默认值{"array":[],"method":"default"}
去噪 sigma 计划覆盖项,与 timesteps 互斥。没有覆盖项(默认)时,调度器根据 num_inference_steps 计算 sigma;提供自定义计划后,num_inference_steps 不再生效。覆盖项要求调度器支持 set_sigmas 的 sigmas 参数。
sigmas.method可选
类型enum
默认值default
defaultarray
选择 sigma 的确定方式:'default'(默认设置)使用调度器自身的 sigma 值。如需自行提供 sigma 计划,请选择 'custom',并将计划放入 `array` 字段。
sigmas.array可选
类型number[]
默认值[]
所选方法为 'custom' 时应用的 sigma 计划。
prediction_type可选
类型enum
默认值epsilon
v_predictionepsilon
选择生成图像的预测类型;未选择其他类型时使用 `epsilon`。
rescale_betas_snr_zero可选
类型boolean
默认值false
控制采样器是否启用 rescale_betas_snr_zero。
image_format可选
类型enum
默认值png
jpegpng
生成图像的文件格式。
num_images可选
num_outputs
类型integer
默认值1
1 – 8
设置单个请求生成的图像数量;批次越大,允许的生成时间越长。
enable_safety_checker可选
类型boolean
默认值false
安全检查器激活状态;true 启用检查。
tile_width可选
类型integer
默认值4096
128 – 4,096
设置图像生成期间每个图块的大小。
tile_height可选
类型integer
默认值4096
128 – 4,096
设置图像生成期间每个图块的大小。
tile_stride_width可选
类型integer
默认值2048
64 – 2,048
设置图像生成期间连续图块位置之间的间距。
tile_stride_height可选
类型integer
默认值2048
64 – 2,048
设置图像生成期间连续图块位置之间的间距。
eta可选
类型number
默认值0
0 – 1
生成图像时使用的 Eta 设置。
debug_latents可选
类型boolean
默认值false
为 true 时保存用于调试的潜变量。
debug_per_pass_latents可选
类型boolean
默认值false
将此项设为 true 可启用逐轮调试,并保存每一轮的潜变量。
必填
规范名称,也可接受
文件参数接受公开的 https:// URL、最大 10 MB 的 data: URI,或上传文件的 file_url。 文件
输出
GET /requests/req_8k2m4q7x1z9c3v5b6n0p2r4t
{
"id": "req_8k2m4q7x1z9c3v5b6n0p2r4t",
"object": "request",
"model": "lora",
"status": "succeeded",
"created_at": "2026-10-20T12:00:00Z",
"started_at": "2026-10-20T12:00:02Z",
"completed_at": "2026-10-20T12:00:09Z",
"queue_position": null,
"cost": {
"credits": 57,
"usd": "0.057",
"charged": 57,
"refunded": 0
},
"input": {
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
},
"output": {
"images": [
{
"url": "https://content.doitong.com/dev-api/2026/10/20/req_8k2m4q7x1z9c3v5b6n0p2r4t/0-output.jpeg",
"content_type": "image/jpeg",
"file_name": "0-output.jpeg",
"file_size": 1843200,
"width": 1024,
"height": 768
}
],
"seed": 42,
"has_nsfw_concepts": [
false
],
"debug_latents": {
"url": "https://content.doitong.com/dev-api/2026/10/20/req_8k2m4q7x1z9c3v5b6n0p2r4t/0-output.jpeg",
"content_type": "image/jpeg",
"file_name": "0-output.jpeg",
"file_size": 1843200
},
"debug_per_pass_latents": {
"url": "https://content.doitong.com/dev-api/2026/10/20/req_8k2m4q7x1z9c3v5b6n0p2r4t/0-output.jpeg",
"content_type": "image/jpeg",
"file_name": "0-output.jpeg",
"file_size": 1843200
}
},
"outputs": [
{
"type": "image",
"url": "https://content.doitong.com/dev-api/2026/10/20/req_8k2m4q7x1z9c3v5b6n0p2r4t/0-output.jpeg",
"content_type": "image/jpeg",
"file_size": 1843200,
"width": 1024,
"height": 768,
"stored": true
}
],
"error": null,
"metrics": {
"inference_seconds": 6.8
},
"urls": {
"self": "https://api.doitong.com/v1/requests/req_8k2m4q7x1z9c3v5b6n0p2r4t",
"cancel": "https://api.doitong.com/v1/requests/req_8k2m4q7x1z9c3v5b6n0p2r4t/cancel"
}
}
文件由你选择每个 outputs[].url 都是我们存储中的副本:可永久保存(按 GB-月付费),也可免费保存 7 天,由账户设置或 ?storage= 决定。
所有模型的结构一致图像、视频和音频的字段均为 type、url、content_type、width、height 和 duration。output 是模型自身的结果对象。
输出字段
- images
- array of object {url, content_type, file_name, file_size, width, height}生成图像的文件信息。
- seed
- integer图像生成种子:如果输入未提供种子,则包含随机选择的值;否则重复使用所提供的值。
- has_nsfw_concepts
- array of boolean指示生成的图像中是否出现 NSFW 概念。
- debug_latents
- object {url, content_type, file_name, file_size} | null为调试而存储的潜变量数据。
- debug_per_pass_latents
- object {url, content_type, file_name, file_size} | null为调试而存储的逐轮潜变量数据。
其他 Stable Diffusion with LoRAs 变体
更多模型:文本生成图像
对于 AI 代理:此页面的 Markdown 版本位于 https://doitong.com/zh-CN/developers/models/lora.md. 所有模型和指南: https://doitong.com/developers/llms.txt







