# Stable Diffusion with LoRAs · Inpaint API

> 使用指定 Stable Diffusion 基础模型和 LoRAs，在黑白蒙版引导下进行图像修复

使用 `image_url` 和黑白 `mask_url` 编辑图像的部分区域，模型由 `model_name` 指定的 Stable Diffusion 模型提供。`noise_strength` 范围为 0 到 1。支持合并 LoRA、嵌入、ControlNet、IP adapter 和多个调度器，步数为 1 到 150。输出为 png 或 jpeg。

- Model id: `lora/inpaint`
- Made by: Open model
- Category: Image Editing
- Output: image
- Estimated price per run: $0.184 / image (cheapest run $0.184 (184 API credits))
- Run: `POST https://api.doitong.com/v1/run/lora/inpaint`
- Quote: `POST https://api.doitong.com/v1/quote/lora/inpaint`
- Docs page: https://doitong.com/zh/developers/models/lora/inpaint

## Pricing

Price: **$0.184 / image**. Estimated from the typical cost of one run, per output (`num_images`). The quote is exactly what the run charges.

The full example input below costs $0.184 = 184 API credits (1 image × 184 API credits).

Prices are the upstream price in USD, paid from the API balance in API credits (1000 API credits = 1 USD). `POST https://api.doitong.com/v1/quote/lora/inpaint` with the same JSON body returns the exact price for that input; the quote is exactly what a run charges. Invalid input is never charged and failed or canceled requests are refunded automatically.

## Input parameters

Send either the canonical name or the native field name (not both). Canonical names are the same across models.

| Parameter | Canonical name | Type | Required | Default | Allowed values / range | Description |
|---|---|---|---|---|---|---|
| `model_name` |  | string | yes |  |  | 用于生成图像的基础模型，可通过 URL 或 HuggingFace ID 指定。 |
| `unet_name` |  | string \| null | no |  |  | 用于生成图像的自定义 U-Net 选择；请提供其 HuggingFace ID 或 URL。 |
| `variant` |  | string \| null | no |  |  | HuggingFace 模型变体选择；'fp16' 是其中一个示例。 |
| `prompt` |  | string | yes |  |  | 描述要生成的图像；请尽可能提供详细信息以获得最佳结果。 |
| `negative_prompt` |  | string | no | `` |  | 指定不需要的图像细节的负面提示词。可排除颜色、物体、场景或更细致的特征和质量，例如胡子、模糊或低分辨率。 |
| `prompt_weighting` |  | boolean | no | `false` |  | 提示词加权开关：true 会通过嵌入平均移除 77 token 限制，并启用加权语法。 |
| `image_url` | `image` | string (image URL) \| null | no |  |  | 用于图像到图像生成或修复的源图像 URL。 |
| `mask_url` | `mask` | string (image URL) \| null | no |  |  | 指向黑白图像的修复蒙版 URL。 |
| `noise_strength` |  | number | no | `0.5` | ≤ 1, > 0 | 控制添加的图像噪声，范围内 1.0 表示完全噪声，接近 0 的设置表示最小噪声。仅在提供 image_url 时生效。 |
| `loras` |  | array of object {path, scale} | no | `[]` |  | 其组合效果用于生成图像的 LoRA，数量不限。 |
| `loras[].path` |  | string | yes |  |  | LoRA 权重的位置，以 URL 或路径指定。 |
| `loras[].scale` |  | number | no | `1` | 0 – 4 | LoRA 权重合并到基础模型前应用的乘数。 |
| `embeddings` |  | array of object {path, tokens} | no | `[]` |  | 在图像生成期间应用的嵌入，用于将提示词 token 映射到嵌入权重。目前仅支持一个嵌入。 |
| `embeddings[].path` |  | string | yes |  |  | 通过 URL 或文件路径指定的嵌入权重。 |
| `embeddings[].tokens` |  | array of string \| null | no |  |  | 映射到嵌入权重的提示词 token。省略时会为每个嵌入文件向量创建一个 token，名称为 <s0>、<s1>、...；请在提示词中使用这些映射后的 token。 |
| `controlnets` |  | array of object {path, config_url, variant, image_url, mask_url, conditioning_scale, start_percentage, end_percentage, ip_adapter_index} | no | `[]` |  | 在生成期间的指定时间步将要应用于图像的 ControlNet，数量不限。 |
| `controlnets[].path` |  | string | yes |  |  | ControlNet 权重位置，可指定为 URL 或路径。 |
| `controlnets[].config_url` |  | string \| null | no |  |  | 可选的 URL，指向 ControlNet 的 config.json 文件。 |
| `controlnets[].variant` |  | string \| null | no |  |  | 与 Hugging Face 仓库键配合使用的可选变体。 |
| `controlnets[].image_url` |  | string (image URL) | yes |  |  | 作为 ControlNet 输入提供的图像 URL。 |
| `controlnets[].mask_url` |  | string (image URL) \| null | no |  |  | ControlNet 蒙版（如果提供），其尺寸必须与控制图像一致；宽度和高度都必须能被 32 整除。 |
| `controlnets[].conditioning_scale` |  | number | no | `1` | 0 – 2 | 合并到基础模型前应用于 ControlNet 权重的缩放。 |
| `controlnets[].start_percentage` |  | number | no | `0` | 0 – 1 | ControlNet 开始影响图像生成时所处的总时间步百分比。 |
| `controlnets[].end_percentage` |  | number | no | `1` | 0 – 1 | ControlNet 停止影响图像生成时所处的总时间步百分比。 |
| `controlnets[].ip_adapter_index` |  | integer \| null | no |  |  | InstantID ControlNet 的 IP adapter 索引选择；其他 ControlNet 不需要此设置。 |
| `controlnet_guess_mode` |  | boolean | no | `false` |  | 为 true 时，将 ControlNet 的应用限制为条件预测。 |
| `ip_adapter` |  | array of object {ip_adapter_image_url, ip_adapter_mask_url, path, model_subfolder, weight_name, insight_face_model_path, scale, scale_json, unconditional_noising_factor, image_projection_shortcut} | no | `[]` |  | 用于生成图像的 IP adapter。提供任何条目都需要 image_encoder_path。 |
| `ip_adapter[].ip_adapter_image_url` |  | string (image URL) \| array of image URL | yes |  |  | 作为 IP adapter 输入提供的图像 URL。 |
| `ip_adapter[].ip_adapter_mask_url` |  | string (image URL) \| null | no |  |  | IP adapter 蒙版（如果提供），其尺寸必须与 adapter 图像一致。 |
| `ip_adapter[].path` |  | string | yes |  |  | IP adapter 权重位置，指定为 URL 或路径。 |
| `ip_adapter[].model_subfolder` |  | string \| null | no |  |  | IP adapter 权重位置，指定为模型目录中的子文件夹。 |
| `ip_adapter[].weight_name` |  | string \| null | no |  |  | 权重文件名。 |
| `ip_adapter[].insight_face_model_path` |  | string \| null | no |  |  | InsightFace 模型权重位置，指定为 URL 或路径。 |
| `ip_adapter[].scale` |  | number | no | `1` | ≥ 0 | IP adapter 权重的缩放因子，在合并到基础模型之前应用。 |
| `ip_adapter[].scale_json` |  | object \| null | no |  |  | IP adapter 权重的缩放因子，在合并到基础模型之前应用。 |
| `ip_adapter[].unconditional_noising_factor` |  | number | no | `0` | 0 – 1 | 控制 IP adapter 无条件加噪的因子。 |
| `ip_adapter[].image_projection_shortcut` |  | boolean | no | `true` |  | 图像投影快捷方式设置，默认值为 True。FaceID plus V1 模型使用 False，FaceID plus V2 模型使用 True。 |
| `image_encoder_path` |  | string \| null | no |  |  | 通过 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 | no |  |  | image_encoder_path 中存放图像编码器权重的子目录。 |
| `image_encoder_weight_name` |  | string \| null | no | `pytorch_model.bin` |  | 按名称选择图像编码器权重，用于生成图像。 |
| `ic_light_model_url` |  | string \| null | no |  |  | 生成图像时使用的 IC Light 模型 URL。 |
| `ic_light_model_background_image_url` |  | string (image URL) \| null | no |  |  | 用于 IC Light 图像生成的模型兼容背景，以图像 URL 提供。 |
| `ic_light_image_url` |  | string (image URL) \| null | no |  |  | 使用 IC Light 模型生成时的输入图像 URL。 |
| `seed` |  | integer \| null | no |  |  | 用于在 Stable Diffusion 中复现图像的种子。保持模型版本、提示词和种子不变，即可在每次运行中精确复现图像。 |
| `num_inference_steps` |  | integer | no | `30` | 1 – 150 | 控制 Stable Diffusion 执行的生成步骤数；额外步骤可能会生成细节更丰富的最终图像。 |
| `guidance_scale` |  | number | no | `7.5` | 0 – 20 | 图像选择对提示词的遵循强度，以 CFG（Classifier Free Guidance）表示。 |
| `clip_skip` |  | integer | no | `0` | 0 – 2 | 跳过部分图像生成以加快渲染速度，但结果会略有不同。 |
| `scheduler` |  | enum (string) \| null | no |  | `DPM++ 2M`, `DPM++ 2M Karras`, `DPM++ 2M SDE`, `DPM++ 2M SDE Karras`, `Euler`, `Euler A`, `Euler (trailing timesteps)`, `LCM`, `LCM (trailing timesteps)`, `DDIM`, `TCD` | 用于对图像去噪的调度器或采样器。 |
| `timesteps` |  | object {method, array} | no | `{"array":[],"method":"default"}` |  | 去噪时间步计划覆盖值，与 sigmas 互斥。没有覆盖值时（默认情况），调度器会根据 num_inference_steps 计算时间步；提供自定义计划后，num_inference_steps 将无效。覆盖值要求调度器支持 set_timesteps 的 timesteps 参数。 |
| `timesteps.method` |  | enum (string) | no | `default` | `default`, `array` | 选择时间步的确定方式：'default' 为默认设置，允许调度器使用 `num_inference_steps`。如需自行提供时间步计划，请选择 'array'，并将计划放入 `array` 字段。 |
| `timesteps.array` |  | array of integer | no | `[]` |  | 所选方法为 'custom' 时应用的时间步计划。 |
| `sigmas` |  | object {method, array} | no | `{"array":[],"method":"default"}` |  | 去噪 sigma 计划覆盖值，与 timesteps 互斥。没有覆盖值时（默认情况），调度器会根据 num_inference_steps 计算 sigma；提供自定义计划后，num_inference_steps 将无效。覆盖值要求调度器支持 set_sigmas 的 sigmas 参数。 |
| `sigmas.method` |  | enum (string) | no | `default` | `default`, `array` | 选择 sigma 的确定方式：'default' 为默认设置，使用调度器自身的 sigma 值。如需自行提供 sigma 计划，请选择 'custom'，并将计划放入 `array` 字段。 |
| `sigmas.array` |  | array of number | no | `[]` |  | 所选方法为 'custom' 时应用的 sigma 计划。 |
| `prediction_type` |  | enum (string) | no | `epsilon` | `v_prediction`, `epsilon` | 选择生成图像时的预测类型；未选择其他类型时使用 `epsilon`。 |
| `rescale_betas_snr_zero` |  | boolean | no | `false` |  | 控制采样器是否启用 rescale_betas_snr_zero。 |
| `image_format` |  | enum (string) | no | `png` | `jpeg`, `png` | 结果图像的文件格式。 |
| `num_images` | `num_outputs` | integer | no | `1` | 1 – 8 | 设置单个请求生成的图像数量；批次越大，允许的生成时间越长。 |
| `enable_safety_checker` |  | boolean | no | `false` |  | 安全检查器激活状态；true 启用检查。 |
| `tile_width` |  | integer | no | `4096` | 128 – 4,096 | 设置图像生成期间每个图块的大小。 |
| `tile_height` |  | integer | no | `4096` | 128 – 4,096 | 设置图像生成期间每个图块的大小。 |
| `tile_stride_width` |  | integer | no | `2048` | 64 – 2,048 | 设置图像生成期间连续图块位置之间的间距。 |
| `tile_stride_height` |  | integer | no | `2048` | 64 – 2,048 | 设置图像生成期间连续图块位置之间的间距。 |
| `eta` |  | number | no | `0` | 0 – 1 | 生成图像时使用的 Eta 设置。 |
| `debug_latents` |  | boolean | no | `false` |  | 为 true 时保存潜变量以便调试。 |
| `debug_per_pass_latents` |  | boolean | no | `false` |  | 将此项设为 true 可启用逐轮调试，并保存每一轮的潜变量。 |

File parameters (`image`, `mask`, `ic_light_model_background_image_url`, `ic_light_image_url`) take a public `https://` URL, a `data:` URI up to 10 MB, or the `file_url` of an upload from `POST /files`.

## Example input

Required parameters only:

```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"
}
```

A fuller example:

```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"
}
```

## Run it

Set `DOITONG_API_KEY` to a key from https://doitong.com/developers/dashboard#keys. `?wait=20` returns the finished request in the same call when it is ready within 20 seconds; otherwise poll `GET /requests/{id}` (it also accepts `?wait=`), or pass `webhook_url`.

### curl

```bash
# 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/inpaint?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"
```

### JavaScript

```javascript
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/inpaint?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 + ")");
```

### Python

```python
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/inpaint", 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"])
```

### MCP

The MCP server at `https://api.doitong.com/v1/mcp` exposes the tools `search_models`, `get_model`, `quote`, `run`, `get_request`, `cancel_request`, `list_requests`, `create_upload` and `get_account`. A `run` call for this model:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "run",
    "arguments": {
      "model_id": "lora/inpaint",
      "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
    }
  }
}
```

## Response

Every call returns a request object. `status` is one of `queued`, `running`, `succeeded`, `failed`, `canceled`. `outputs` lists the generated files with URLs on our storage (kept forever, or 7 days with `?storage=temporary`; `storage` says which); `output` is the model's own result object with the same URLs.

```json
{
  "id": "req_8k2m4q7x1z9c3v5b6n0p2r4t",
  "object": "request",
  "model": "lora/inpaint",
  "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": 184,
    "usd": "0.184",
    "charged": 184,
    "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"
  }
}
```

### Output fields (`output`)

| Field | Type | Description |
|---|---|---|
| `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 | 为调试而存储的逐轮潜变量数据。 |

## Related models

- [Stable Diffusion with LoRAs](https://doitong.com/developers/models/lora.md) (`lora`): $0.057 / image
- [Stable Diffusion with LoRAs · Image to Image](https://doitong.com/developers/models/lora/image-to-image.md) (`lora/image-to-image`): $0.264 / image
- [FLUX.1 Kontext \[pro\]](https://doitong.com/developers/models/flux-pro/kontext.md) (`flux-pro/kontext`): $0.04 / image
- [GPT Image 2.5 Edit](https://doitong.com/developers/models/openai/gpt-image-2.5/flare/edit.md) (`openai/gpt-image-2.5/flare/edit`): from $0.12 / image
- [Nano Banana 2 Edit](https://doitong.com/developers/models/nano-banana-2/edit.md) (`nano-banana-2/edit`): from $0.06 / image
- [Nano Banana Pro Edit](https://doitong.com/developers/models/nano-banana-pro/edit.md) (`nano-banana-pro/edit`): from $0.15 / image
- [Qwen Image 3 Edit](https://doitong.com/developers/models/alibaba/qwen-image-3/edit.md) (`alibaba/qwen-image-3/edit`): from $0.04 / image
- [Seedream 5.0 Pro Edit](https://doitong.com/developers/models/bytedance/seedream/v5/pro/edit.md) (`bytedance/seedream/v5/pro/edit`): from $0.0675 / run of output image

## Links

- HTML page: https://doitong.com/developers/models/lora/inpaint
- All models and guides for AI agents: https://doitong.com/developers/llms.txt
- OpenAPI 3.1 with this model's typed request body: https://doitong.com/developers/openapi.json?model=lora/inpaint
- Errors: https://doitong.com/developers/docs/errors
- Model details as JSON: https://api.doitong.com/v1/models/lora/inpaint
