This topic describes the input and output parameters of the Wanxiang - Image Inpainting model.
Related guide: Image Inpainting
-
This document applies only to the China (Beijing) region. You must use an API key from this region.
-
The wanx-x-painting model is currently available for free trial only. After your free quota is exhausted, you cannot invoke the model because paid usage is not supported. We recommend using Image Editing - Qwen or Image Editing - Wanxiang 2.1 as alternatives.
Model overview
Model preview

Model overview
|
Model |
Introduction |
|
wanx-x-painting |
The Wan image inpainting model generates content that corresponds to the text description in the smeared area based on the original image, the local area smear map, and the text prompt that you enter. The area outside the smeared area remains basically unchanged. |
Model description
|
Model |
Unit price |
Rate limit (shared by Alibaba Cloud account and RAM users) |
Free quota |
|
|
Request per second (RPS) for task submission |
Number of concurrent tasks |
|||
|
wanx-x-painting |
For free trial only. You cannot make calls after the free quota is used up. Please stay tuned for future updates. |
2 |
1 |
Free quota: 500 images Valid for 180 days after activation |
For more information, see Model billing and rate limiting.
Prerequisites
You can invoke the Image Inpainting API using HTTP or the DashScope SDK.
Before making a call, get an API key and export the API key as an environment variable.
To call the API using the SDK, install the DashScope SDK. The SDK is available for Python and Java.
HTTP call
Image models take a long time to process. To prevent timeouts, HTTP calls support only asynchronous result retrieval. Two requests are required:
-
Create a task to get a task ID: Send a request to create a task. The response returns a task ID (
task_id). -
Query the result using the task ID: Use the task ID from the previous step to query the task status and result. If the task is successful, the response returns an image URL that is valid for 24 hours.
After creation, the task enters a queue for scheduling. Call the query API to retrieve the task status and result.
Step 1: Create a task to get a task ID
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis
Request parameters |
Image inpainting
|
Request headers |
|
|
Content-Type The content type of the request. Must be |
|
|
Authorization Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx. |
|
|
X-DashScope-Async Enables asynchronous processing. HTTP requests support only asynchronous calls. Must be Important
If this request header is missing, the error "current user api does not support synchronous calls" is returned. |
|
Request body |
|
|
model The name of the model. Example: wanx-x-painting. |
|
|
input The basic input information, such as the prompt and image URLs. |
|
|
parameters The parameters for image processing. |
Response parameters |
Successful responseSave the
Error responseTask creation failed. See Error codes.
|
|
output The output information of the task. |
|
|
request_id Unique request identifier for tracing and troubleshooting. |
|
|
code Error code. Returned only for failed requests. See Error codes. |
|
|
message Detailed error message. Returned only for failed requests. See Error codes. |
Step 2: Query results by task ID
GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
Request parameters |
Query task resultsReplace If you use a model in the Singapore region, replace
|
Headers |
|
|
Authorization Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx. |
|
Path parameters |
|
|
task_id The ID of the task. |
Response parameters |
Success responseTask data (task status and image URLs) is retained for only 24 hours and then automatically purged. Save generated images promptly. Failure responseWhen a task fails,
Partial failure responseThe model can generate multiple images per task. If at least one succeeds, the task status is
|
|
output The task output. |
|
|
usage The output statistics. Only successful results are counted. |
|
|
request_id Unique request identifier for tracing and troubleshooting. |
DashScope SDK invocation
Install the latest DashScope SDK. See Install the SDK.
The DashScope SDK supports Python and Java.
SDK parameter names are mostly consistent with the HTTP API. Parameter structure varies by SDK language. For details, see the HTTP Invocation section.
Because image models take a long time to process, the underlying service is asynchronous. The SDK supports both synchronous and asynchronous calls.
Python SDK invocation
Synchronous call
Request example
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
prompt = "A dog wearing red glasses"
model = "wanx-x-painting"
task = "image2image"
extra_input = {
"base_image_url": "http://synthesis-source.oss-accelerate.aliyuncs.com/lingji/validation/mask2img/demo/source3.jpg",
"mask_image_url": "http://synthesis-source.oss-accelerate.aliyuncs.com/lingji/validation/mask2img/demo/glasses.png"
}
print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(model=model,
prompt=prompt,
n=1,
size='1024*1024',
task=task,
extra_input=extra_input)
if rsp.status_code == HTTPStatus.OK:
print(rsp)
# save file to current directory
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
Response example
{
"status_code": 200,
"request_id": "4126d9dd-e037-9f32-8d56-6d29ab3f9a06",
"code": null,
"message": "",
"output": {
"task_id": "b476bc4e-35c1-4c4e-a4d9-xxxxxxx",
"task_status": "SUCCEEDED",
"results": [{
"url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxxx.png"
}],
"submit_time": "2024-11-01 09:50:56.081",
"scheduled_time": "2024-11-01 09:50:56.104",
"end_time": "2024-11-01 09:51:22.740",
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
},
"usage": {
"image_count": 1
}
}
Asynchronous call
Request example
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
prompt = "A dog wearing red glasses"
model = "wanx-x-painting"
task = "image2image"
extra_input = {
"base_image_url": "http://synthesis-source.oss-accelerate.aliyuncs.com/lingji/validation/mask2img/demo/source3.jpg",
"mask_image_url": "http://synthesis-source.oss-accelerate.aliyuncs.com/lingji/validation/mask2img/demo/glasses.png"
}
def async_call():
print('----create task----')
task_info = create_async_task()
print('----wait task done then save image----')
wait_async_task(task_info)
# Create an asynchronous task
def create_async_task():
rsp = ImageSynthesis.async_call(model=model,
prompt=prompt,
n=1,
size='1024*1024',
task=task,
extra_input=extra_input)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output)
else:
print('create_async_task Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
return rsp
# Wait for the asynchronous task to complete
def wait_async_task(task):
rsp = ImageSynthesis.wait(task)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.task_status)
# save file to current directory
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
async_call()
Response example
1. Sample response for task creation
{
"status_code": 200,
"request_id": "31b04171-011c-96bd-ac00-f0383b669cc7",
"code": "",
"message": "",
"output": {
"task_id": "4f90cf14-a34e-4eae-xxxxxxxx",
"task_status": "PENDING",
"results": []
},
"usage": null
}
2. Sample response for querying task results
{
"status_code": 200,
"request_id": "d861d3ba-4b29-9491-abad-266ef4fb2f08",
"code": null,
"message": "",
"output": {
"task_id": "4f90cf14-a34e-4eae-xxxxxxxx",
"task_status": "SUCCEEDED",
"results": [{
"url": "https://dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com/xxxx.png"
}],
"submit_time": "2024-10-31 20:40:35.631",
"scheduled_time": "2024-10-31 20:40:35.684",
"end_time": "2024-10-31 20:41:02.700",
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
},
"usage": {
"image_count": 1
}
}
Java SDK invocation
Synchronous call
Request example
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
public class Main {
public void syncCall() {
String task = "image2image";
ImageSynthesis imageSynthesis = new ImageSynthesis(task);
ImageSynthesisParam param = genImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---sync call, please wait a moment----");
result = imageSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
private ImageSynthesisParam genImageSynthesis(){
HashMap<String,Object> extraInputMap = new HashMap<>();
extraInputMap.put("base_image_url", "http://synthesis-source.oss-accelerate.aliyuncs.com/lingji/validation/mask2img/demo/source3.jpg");
extraInputMap.put("mask_image_url", "http://synthesis-source.oss-accelerate.aliyuncs.com/lingji/validation/mask2img/demo/glasses.png");
String prompt = "A dog wearing red glasses";
String model = "wanx-x-painting";
return ImageSynthesisParam.builder()
.model(model)
.prompt(prompt)
.n(1)
.size("1024*1024")
.extraInputs(extraInputMap)
.build();
}
public static void main(String[] args){
Main text2Image = new Main();
text2Image.syncCall();
}
}
Response example
{
"request_id": "150edcda-05d5-9ffe-8803-84626d1db623",
"output": {
"task_id": "f2098ff0-146e-404c-bb25-xxxxxxxx",
"task_status": "SUCCEEDED",
"results": [{
"url": "https://dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com/xxxx.png"
}],
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
},
"usage": {
"image_count": 1
}
}
Asynchronous call
Request example
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
public class Main {
public void asyncCall() {
System.out.println("---create task----");
String taskId = this.createAsyncTask();
System.out.println("---wait task done then return image url----");
this.waitAsyncTask(taskId);
}
/**
* Create an asynchronous task
* @return taskId
*/
public String createAsyncTask() {
String task = "image2image";
ImageSynthesis imageSynthesis = new ImageSynthesis(task);
ImageSynthesisParam param = genImageSynthesis();
ImageSynthesisResult result = null;
try {
result = imageSynthesis.asyncCall(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
String taskId = result.getOutput().getTaskId();
System.out.println("taskId=" + taskId);
return taskId;
}
private ImageSynthesisParam genImageSynthesis(){
String prompt = "A dog wearing red glasses";
String model = "wanx-x-painting";
HashMap<String,Object> extraInputMap = new HashMap<>();
extraInputMap.put("base_image_url", "http://synthesis-source.oss-accelerate.aliyuncs.com/lingji/validation/mask2img/demo/source3.jpg");
extraInputMap.put("mask_image_url", "http://synthesis-source.oss-accelerate.aliyuncs.com/lingji/validation/mask2img/demo/glasses.png");
return ImageSynthesisParam.builder()
.model(model)
.prompt(prompt)
.n(1)
.size("1024*1024")
.extraInputs(extraInputMap)
.build();
}
/**
* Wait for the asynchronous task to complete
* @param taskId Task ID
* */
public void waitAsyncTask(String taskId) {
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
// If you have set the DASHSCOPE_API_KEY in the system environment variable, the apiKey can be null.
result = imageSynthesis.wait(taskId, null);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result.getOutput()));
System.out.println(JsonUtils.toJson(result.getUsage()));
}
public static void main(String[] args){
Main text2Image = new Main();
text2Image.asyncCall();
}
}
Response example
1. Sample response for task creation
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-542f97709ba8",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}
2. Sample response for querying task results
Content of the output field:
{
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "SUCCEEDED",
"results": [{
"url": "https://dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com/xxxx.png"
}],
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
}
Content of the usage field:
{
"image_count": 1
}
Error codes
If the model call fails and returns an error message, see Error codes for resolution.
FAQ
Model Billing and Rate Limiting
Free quota
-
Description: The free quota applies only to successfully generated output images. Input images or failed model processing do not consume the free quota.
-
How to get: It is automatically granted when you activate Model Studio. Valid for 90 days.
-
Account scope: Shared between your Alibaba Cloud account and its RAM users.
-
For more details, see Free quota for new users.
Limited-time free trial
-
If billing shows a limited-time free trial, the model is in public preview. You cannot use the model after the free quota runs out.
Billing details
-
If a clear unit price is shown — for example, CNY 0.2 per second — the model is commercially available. You must pay after the free quota expires or is fully consumed.
-
Billing scope: Charges apply only to successfully generated output images. Other scenarios are not billed.
-
Billing method: Billing is applied to your Alibaba Cloud account. RAM users cannot be billed independently. Your Alibaba Cloud account must cover all associated charges. To view billing information, go to the Bills page.
-
Recharge: Go to the Expenses and Costs console.
-
View invocation metrics: Go to the Monitoring page.
-
For more billing questions, see Billing Items.
Rate limiting
-
Rate limit scope: Shared between your Alibaba Cloud account and its RAM users.
Common Issues with Image Inpainting API
-
What are the restrictions on the mask image (`mask_image`) for the input image?
-
Only image URLs are supported. Base64-encoded image data is not supported.
-
The mask image must have the same resolution as the input image.
-
The sample mask image in this document has a white background. However, the mask image is not required to have a white background. You can specify other colors using the
mask_colorfield.
-
-
How can I obtain the mask image for the input image?
You can use Photoshop or other image editing tools to draw on the original image to obtain the mask image.
-
When I use the Image Inpainting feature, what should I do if the quality of the output image outside the painted area is not ideal?
You can use the inpainting feature of General Image Editing to regenerate the image.