This topic describes the input and output parameters of the Wanx-General Image Editing model.
- Image stylization: global stylization and local stylization.
- Image content editing: instruction-based editing (add or modify image content through instructions only, without specifying a region), inpainting (add, delete, or modify image content in a specified region), and text watermark removal (Chinese and English).
- Image size and resolution optimization: outpainting (proportional outpainting) and image super-resolution (HD upscaling).
- Image color processing: image colorization (converting black-and-white or grayscale images into color images).
- Reference-image-based generation: line art to image (extract the line art of the input image first, and then generate an image based on the line art) and cartoon character reference to image.
Model overview
Model | Unit price | Rate limit (shared by the primary account and RAM sub-accounts) | |
|---|---|---|---|
RPS limit on the task submission API | Number of tasks being processed simultaneously | ||
wanx2.1-imageedit | $0.020070/image | 2 | 2 |
Model effects
Model feature | Input image | Input prompt | Output image |
|---|---|---|---|
Global stylization | ![]() | Convert to French picture book style | ![]() |
Local stylization | ![]() | Turn the house into a wooden plank style. | ![]() |
Instruction-based editing | ![]() | Change her hair to red. | ![]() |
Local repainting | Input image ![]() Input image with the masked area (the white area indicates the mask) ![]() | A ceramic rabbit holding a ceramic flower. | Output image ![]() |
Text watermark removal | ![]() | Remove text from the image. | ![]() |
Image outpainting | ![]() | A green fairy. | ![]() |
Image super-resolution | Blurred image ![]() | Image super-resolution. | Clear image ![]() |
Image colorization | ![]() | A blue background with yellow leaves. | ![]() |
Sketch-to-image | Input image ![]() | A living room in Scandinavian minimalist style. | Extract the sketch from the original image and generate an image ![]() |
Generating images from a cartoon reference | Input reference image (cartoon character) ![]() | The cartoon character cautiously pokes its head out to peek at a sparkling blue gem in the room. | Output image ![]() |
Prerequisites
The Wanx-general image editing API supports calls over HTTP and with DashScope SDKs.
Before calling the API, you need to obtain and configure an API Key and then configure the API Key as an environment variable.
To call the API with an SDK, please install the DashScope SDK. Currently, the SDK supports Python and Java.
Please replace DASHSCOPE_API_HOST in the sample code with the obtained API Host.
HTTP invocation
Image models take a long time to process. To avoid request timeouts, HTTP invocation only supports retrieving model results asynchronously. You need to send two requests:
- Create a task to obtain the task ID: First send a task creation request, which returns a task ID (task_id).
- Query the result by task ID: Use the task ID obtained in the previous step to query the task status and result. When the task is executed successfully, the image URL is returned, which remains valid for 24 hours.
General image editing models take about 5 to 15 seconds. The actual time depends on the number of queued tasks and network conditions. Please be patient when obtaining the results.
Step 1: Create a task to obtain the task ID
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis
When you make the call, replace {WorkspaceId} with the actual workspace ID.
Request parametersRequest headersContent-Typestring(Required)Request content type. This parameter must be set to application/json.Authorizationstring(Required)Request authentication. The API uses the Alibaba Cloud Bailian API Key for authentication. Example value: Bearer sk-xxxx.X-DashScope-Asyncstring(Required)Asynchronous processing configuration parameter. HTTP requests support only asynchronous calls and must be set to enable.Request bodymodelstring (Required)Model name. Example value: wanx2.1-imageedit.input object (Required)Basic input information, such as the prompt.
Property prompt string(Required)The prompt used to describe the elements and visual features that you want in the generated image.Both Chinese and English are supported, with a length of no more than 800 characters. Each Chinese character or letter counts as one character, and any excess is automatically truncated.Prompts differ between functions. We recommend that you refer to the prompt techniques for the specific function.function string(Required)The image editing function. Currently supported functions:
string (Required)The URL or Base64-encoded data of the input image.Image limits:
string (Optional)Required only when function is set to description_edit_with_mask (local repainting). In other cases, leave it unspecified.The URL or Base64-encoded data of the mask area image.You can pass in a publicly accessible URL (HTTP/HTTPS) or a Base64-encoded string. For more information, see value passing methods.Requirements for the mask area image:
object (Optional)Image processing parameters.
Property
n integer (Optional)The number of images to generate. Range 1~4, default 1.seedinteger(Optional)The random seed used to control the randomness of generated content. Value range: [0, 2147483647]. If not specified, it is automatically generated; using the same value keeps results stable.watermark bool (Optional)Whether to add a watermark. The watermark is located in the lower-right corner of the image, with the text "AI Generated".
|
|
Response parametersoutputobjectTask output information.
Property task_id stringTask ID. The validity period for query is 24 hours.task_status stringTask status.
Enumerated values
stringThe unique identifier of the request. It can be used for request detail tracing and troubleshooting.codestringThe error code returned when the request fails. This parameter is not returned when the request succeeds. For more information, see Error codes.messagestringThe detailed error information returned when the request fails. This parameter is not returned when the request succeeds. For more information, see Error codes. |
Please save the task_id, which is used to query the task status and results. |
Step 2: Query results by task ID
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
When you make the call, replace {WorkspaceId} with the actual workspace ID.
Request parametersRequest headersAuthorizationstring(Required)Request authentication. The API uses the Alibaba Cloud Bailian API Key for authentication. Example value: Bearer sk-xxxx.URL path parameterstask_idstring(Required)Task ID. |
Please replace 86ecf553-d340-4e21-xxxxxxxxx with the actual task_id. |
Response parametersoutputobjectTask output information.
Property task_id stringTask ID. The validity period for query is 24 hours.task_status stringTask status.
Enumerated values
stringThe time when the task was submitted. The time zone is UTC+8, and the format is YYYY-MM-DD HH:mm:ss.SSS.scheduled_time stringTask execution time. The time zone is UTC+8, and the format is YYYY-MM-DD HH:mm:ss.SSS.end_time stringTask completion time. The time zone is UTC+8, and the format is YYYY-MM-DD HH:mm:ss.SSS.results array objectThe task result list, including image URLs and error messages about partially failed tasks.
Data structure objectTask result statistics.
Property TOTAL integerThe total number of tasks.SUCCEEDED integerThe number of tasks whose task status is successful.FAILED integerThe number of tasks whose task status is failed.stringThe error code returned when the request fails. This parameter is not returned when the request succeeds. For more information, see Error codes.messagestringThe detailed error information returned when the request fails. This parameter is not returned when the request succeeds. For more information, see Error codes.objectOutput information statistics. Only successful results are counted.
Property image_count integerThe number of images successfully generated by the model. Billing formula: Fee = Image Count × Unit price.stringThe unique identifier of the request. It can be used for request detail tracing and troubleshooting. |
Task data (such as task status and image URLs) is retained for only 24 hours and is automatically cleared after the timeout. Make sure to save the generated images in a timely manner. |
Call the DashScope SDK
Make sure that you have installed the latest version of the DashScope SDK first; otherwise, errors may occur during running.
The DashScope SDK currently supports Python and Java.
The parameter names of the SDK are basically the same as those of the HTTP API, and the parameter structure depends on the SDK encapsulation of each language. For parameter descriptions, see HTTP calls.
Because video model processing takes a long time, the underlying service is provided in an asynchronous manner. The SDK encapsulates this at the upper layer and supports both synchronous and asynchronous calls.
General image editing models take about 5 to 15 seconds. The actual time depends on the number of queued tasks and network conditions. Please be patient when obtaining the results.
Call the Python SDK
When you use the Python SDK to process image files, the following three methods are supported for entering images. Choose one based on your scenario.
- Public URL: a publicly accessible image URL (HTTP/HTTPS).
- Base64 encoding: a string obtained after the file is Base64-encoded, in the format of
data:{MIME_type};base64,{base64_data}. - Local file path: you can pass in the absolute path or relative path of the file. See the following table to pass in the correct file path.
System | File path to pass in | Example (absolute path) | Example (relative path) |
|---|---|---|---|
Linux or macOS | file://{Absolute or relative path of the file} | file:///home/images/test.png | file://./images/test.png |
Windows | file://D:/images/test.png | file://./images/test.png |
Sample Code
pip install -U dashscope. For more information, see Install SDK.- Synchronous Call
- Asynchronous Call
Request example
Response example
The URL is valid for 24 hours. Download the image promptly.
Java SDK calls
When you use the Java SDK to process image files, you can input images in the following three ways. Choose one based on your scenario.
- Public URL: a publicly accessible image URL (HTTP/HTTPS).
- Base64 encoding: a string obtained after Base64-encoding the file, in the format
data:{MIME_type};base64,{base64_data}. - Local file path: only the absolute path of the file is supported. Refer to the table below and pass in the correct file path.
System | File path to pass in | Examples |
|---|---|---|
Linux or macOS | file://{Absolute path of the file} | file:///home/images/test.png |
Windows | file:///{Absolute path of the file} | file:///D:/images/test.png |
Sample Code
- Synchronous Call
- Asynchronous Call
Request example
Response example
The URL is valid for 24 hours. Download the image promptly.
Error codes
If the model call fails and returns an error message, see Error codes for troubleshooting.
This API also has specific status codes, as shown below.
HTTP status code | API error code (code) | API error message (message) | Description |
|---|---|---|---|
400 | InvalidParameter | InvalidParameter | Invalid request parameters. |
400 | IPInfringementSuspect | Input data is suspected of being involved in IP infringement. | The input data (such as the prompt or image) is suspected of intellectual property infringement. Check the input to ensure it does not contain content that may pose infringement risks. |
400 | DataInspectionFailed | Input data may contain inappropriate content. | The input data (such as the prompt or image) may contain sensitive content. Modify the input and try again. |
500 | InternalError | InternalError | Service exception. Retry first to rule out transient issues. |
Input image notes
Value passing methods
Input images support multiple string formats. The support for different calling methods is shown in the following table.
Call method | HTTP | Python SDK | Java SDK |
|---|---|---|---|
Supported input image methods |
|
|
|
- Provide a publicly accessible image URL. HTTP or HTTPS protocols are supported.
- Example value:
https://xxxx/img.png.
data:{MIME_type};base64,{base64_data} format.
- For the conversion code, see Sample Code.
- {MIME_type}: the media type of the image, which must match the file format.
- {base64_data}: the Base64-encoded string of the image file.
-
MIME type mappings:
Image format
MIME Type
JPEG
image/jpeg
JPG
image/jpeg
PNG
image/png
BMP
image/bmp
TIFF
image/tiff
WEBP
image/webp
-
Example value:
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABDg......". Note: the preceding Base64 string is truncated for demonstration purposes. In actual use, make sure to pass the complete encoded string.
- HTTP calls do not support local file paths. Only the Python SDK and Java SDK support them.
- For the rules on passing local file paths, see Python SDK calls and Java SDK calls.




















