The Wan image editing model series supports multi-image input and multi-image output, enabling capabilities such as image editing, multi-image fusion, subject feature preservation, and object detection and segmentation through text instructions.
QuickStart
This example demonstrates how to use the wan2.7-image-pro model to generate an edited image based on two input images and a prompt.
Prompt: spray the graffiti from image 2 onto the car in image 1
Input image 1 | Input image 2 | Output image (wan2.7-image-pro) |
|---|---|---|
|
|
|
Before you make a call, first obtain and configure an API Key, and then configure the API Key in environment variables. To make calls through an SDK, install the DashScope SDK.
Synchronous call
ImportantMake sure the DashScope Python SDK version is at least 2.1.0, and the DashScope Java SDK version is at least 2.22.13.
Python
Request example
import os
import base64
import mimetypes
import urllib.request
import dashscope
# 以下为新加坡地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的region取值不同。
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
# --- Base64编码函数 ---
# base64编码格式为 data:{MIME_type};base64,{base64_data}
def encode_file(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
if not mime_type or not mime_type.startswith("image/"):
raise ValueError("不支持或无法识别的图像格式")
with open(file_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
return f"data:{mime_type};base64,{encoded_string}"
"""
图像输入方式说明:
以下提供了三种图片输入方式,三选一即可
1. 使用公网URL - 适合已有公开可访问的图片
2. 使用本地文件 - 适合本地开发测试
3. 使用Base64编码 - 适合私有图片或需要加密传输的场景
"""
# 【方式一】使用公网图片 URL
image_1 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"
image_2 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"
# 【方式二】使用本地文件(支持绝对路径和相对路径)
# image_1 = "file:///path/to/your/car.png"
# image_2 = "file:///path/to/your/paint.png"
# 【方式三】使用Base64编码的图片
# image_1 = encode_file("/path/to/your/car.png")
# image_2 = encode_file("/path/to/your/paint.png")
print("----sync call, please wait a moment----")
# generate 为一步式调用(提交+等待),直接返回已完成的任务结果
job = client.images.generate(
model="wan2.7-image-pro",
prompt="把图2的涂鸦喷绘在图1的汽车上",
# 参考图列表,支持本地文件 如 "file:///path/to/your/car.png"
image_urls=[image_1, image_2],
watermark=False,
n=1,
size="2K", # wan2.7-image-pro仅文生图场景支持4K分辨率,图像编辑和组图生成支持最高2K分辨率
)
# 提取结果图片URL并保存到本地
for i, image_url in enumerate(job.image_urls):
file_name = f"output_{i}.png"
# 结果URL有效期为24小时,请及时下载
urllib.request.urlretrieve(image_url, file_name)
print(f"Image saved to {file_name}")
Response example
The URL is valid for 24 hours. Download the image in time.
{
"status_code": 200,
"request_id": "81d868c6-6ce1-92d8-a90d-d2ee71xxxxxx",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
"type": "image"
}
]
}
}
],
"audio": null,
"finished": true
},
"usage": {
"input_tokens": 18790,
"output_tokens": 2,
"characters": 0,
"image_count": 1,
"size": "2985*1405",
"total_tokens": 18792
}
}
Java
Request example
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* wan2.7-image-pro 图像编辑 - 同步调用示例
*/
public class Main {
static {
// 以下为新加坡地域的URL,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的URL不同。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:apiKey="sk-xxx"
// 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
// --- Base64编码函数 ---
// base64编码格式为 data:{MIME_type};base64,{base64_data}
public static String encodeFile(String filePath) throws IOException {
byte[] fileContent = Files.readAllBytes(Paths.get(filePath));
String base64String = Base64.getEncoder().encodeToString(fileContent);
String mimeType = Files.probeContentType(Paths.get(filePath));
return "data:" + mimeType + ";base64," + base64String;
}
public static void basicCall() throws ApiException, NoApiKeyException, UploadFileException, IOException {
/*
* 图像输入方式说明:
* 以下提供了三种图片输入方式,三选一即可
* 1. 使用公网URL - 适合已有公开可访问的图片
* 2. 使用本地文件 - 适合本地开发测试
* 3. 使用Base64编码 - 适合私有图片或需要加密传输的场景
*/
// 【方式一】使用公网图片 URL
String image1 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp";
String image2 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp";
// 【方式二】使用本地文件(支持绝对路径和相对路径)
// 格式要求:file:// + 文件路径
// String image1 = "file:///path/to/your/car.png";
// String image2 = "file:///path/to/your/paint.png";
// 【方式三】使用Base64编码的图片
// String image1 = encodeFile("/path/to/your/car.png");
// String image2 = encodeFile("/path/to/your/paint.png");
// 构建多图输入消息
ImageGenerationMessage message = ImageGenerationMessage.builder()
.role("user")
.content(Arrays.asList(
// 支持多图输入,可以提供多张参考图片
Collections.singletonMap("text", "把图2的涂鸦喷绘在图1的汽车上"),
Collections.singletonMap("image", image1),
Collections.singletonMap("image", image2)
)).build();
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(apiKey)
.model("wan2.7-image-pro")
.messages(Collections.singletonList(message))
.n(1)
.size("2K") // wan2.7-image-pro仅文生图场景支持4K分辨率,图像编辑和组图生成支持最高2K分辨率
.build();
ImageGeneration imageGeneration = new ImageGeneration();
ImageGenerationResult result = null;
try {
System.out.println("---sync call for image editing, please wait a moment----");
result = imageGeneration.call(param);
} catch (ApiException | NoApiKeyException | UploadFileException e) {
throw new RuntimeException(e.getMessage());
}
// 提取结果图片URL并保存到本地
for (int i = 0; i < result.getOutput().getChoices().size(); i++) {
List<Map<String, Object>> contents = result.getOutput().getChoices().get(i)
.getMessage().getContent();
for (int j = 0; j < contents.size(); j++) {
if ("image".equals(contents.get(j).get("type"))) {
String imageUrl = (String) contents.get(j).get("image");
String fileName = "output_" + i + "_" + j + ".png";
// 结果URL有效期为24小时,请及时下载
try (InputStream in = new URL(imageUrl).openStream()) {
Files.copy(in, Paths.get(fileName), StandardCopyOption.REPLACE_EXISTING);
}
System.out.println("Image saved to " + fileName);
}
}
}
}
public static void main(String[] args) throws ApiException, NoApiKeyException, UploadFileException, IOException {
basicCall();
}
}
Response example
The URL is valid for 24 hours. Download and save the image in time.
{
"requestId": "1bf6173a-e8de-9f75-94d3-5e618f875xxx",
"usage": {
"input_tokens": 18790,
"output_tokens": 2,
"total_tokens": 18792,
"image_count": 1,
"size": "2985*1405"
},
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
"type": "image"
}
]
}
}
],
"finished": true
},
"status_code": 200,
"code": "",
"message": ""
}
curl
Request example
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"model": "wan2.7-image-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"},
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"},
{"text": "把图2的涂鸦喷绘在图1的汽车上"}
]
}
]
},
"parameters": {
"size": "2K",
"n": 1,
"watermark": false
}
}'
Response example
{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": [
{
"image": "https://dashscope-xxx.oss-xxx.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
}
],
"role": "assistant"
}
}
],
"finished": true
},
"usage": {
"image_count": 1,
"input_tokens": 10867,
"output_tokens": 2,
"size": "1488*704",
"total_tokens": 10869
},
"request_id": "71dfc3c6-f796-9972-97e4-bc4efc4faxxx"
}
Asynchronous call
ImportantMake sure the DashScope Python SDK version is at least 2.1.0, and the DashScope Java SDK version is at least 2.22.13.
Python
Request example
import os
import base64
import mimetypes
import urllib.request
import dashscope
# 以下为新加坡地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的region取值不同。
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
# --- Base64编码函数 ---
# base64编码格式为 data:{MIME_type};base64,{base64_data}
def encode_file(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
if not mime_type or not mime_type.startswith("image/"):
raise ValueError("不支持或无法识别的图像格式")
with open(file_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
return f"data:{mime_type};base64,{encoded_string}"
"""
图像输入方式说明:
以下提供了三种图片输入方式,三选一即可
1. 使用公网URL - 适合已有公开可访问的图片
2. 使用本地文件 - 适合本地开发测试
3. 使用Base64编码 - 适合私有图片或需要加密传输的场景
"""
# 【方式一】使用公网图片 URL
image_1 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"
image_2 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"
# 【方式二】使用本地文件(支持绝对路径和相对路径)
# image_1 = "file:///path/to/your/car.png"
# image_2 = "file:///path/to/your/paint.png"
# 【方式三】使用Base64编码的图片
# image_1 = encode_file("/path/to/your/car.png")
# image_2 = encode_file("/path/to/your/paint.png")
# 创建异步任务
def create_async_task():
print("Creating async task...")
job = client.images.jobs.create(
model="wan2.7-image-pro",
prompt="把图2的涂鸦喷绘在图1的汽车上",
extra_input={'images': [image_1, image_2]},
watermark=False,
n=1,
size="2K", # wan2.7-image-pro仅文生图场景支持4K分辨率,图像编辑和组图生成支持最高2K分辨率
)
print("Task created successfully:", job.task_id, job.status)
return job
# 等待任务完成(指数退避轮询,默认总预算24小时;任务失败会抛出DashScopeError)
def wait_for_completion(job):
print("Waiting for task completion...")
done = client.images.jobs.wait(job)
print("Task succeeded!")
# 提取结果图片URL并保存到本地
for i, image_url in enumerate(done.image_urls):
file_name = f"output_{i}.png"
# 结果URL有效期为24小时,请及时下载
urllib.request.urlretrieve(image_url, file_name)
print(f"Image saved to {file_name}")
# 获取异步任务信息
def fetch_task_status(task_id):
print("Fetching task status...")
snapshot = client.images.jobs.fetch(task_id)
print("Task status:", snapshot.status)
# 取消异步任务,只有处于PENDING状态的任务才可以取消
def cancel_task(task_id):
print("Canceling task...")
client.images.jobs.cancel(task_id)
# 主执行流程
if __name__ == "__main__":
job = create_async_task()
wait_for_completion(job)
Response example
- Response example for task creation
{
"status_code": 200,
"request_id": "4fb3050f-de57-4a24-84ff-e37ee5xxxxxx",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": null,
"audio": null,
"task_id": "127ec645-118f-4884-955d-0eba8dxxxxxx",
"task_status": "PENDING"
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"characters": 0
}
}
- Response example for querying task results
The URL is valid for 24 hours. Download the image in time.
{
"status_code": 200,
"request_id": "3b99aae5-d26f-9059-8dd0-ee9ca4804xxx",
"code": null,
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
"type": "image"
}
]
}
}
],
"audio": null,
"task_id": "127ec645-118f-4884-955d-0eba8dxxxxxx",
"task_status": "SUCCEEDED",
"submit_time": "2026-03-31 22:58:47.646",
"scheduled_time": "2026-03-31 22:58:47.683",
"end_time": "2026-03-31 22:58:59.642",
"finished": true
},
"usage": {
"input_tokens": 18711,
"output_tokens": 2,
"characters": 0,
"size": "2985*1405",
"total_tokens": 18713,
"image_count": 1
}
}
Java
Request example
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* wan2.7-image-pro 图像编辑 - 异步调用示例
*/
public class Main {
static {
// 以下为新加坡地域的URL,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的URL不同。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:apiKey="sk-xxx"
// 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
// --- Base64编码函数 ---
// base64编码格式为 data:{MIME_type};base64,{base64_data}
public static String encodeFile(String filePath) throws IOException {
byte[] fileContent = Files.readAllBytes(Paths.get(filePath));
String base64String = Base64.getEncoder().encodeToString(fileContent);
String mimeType = Files.probeContentType(Paths.get(filePath));
return "data:" + mimeType + ";base64," + base64String;
}
public static void asyncCall() throws ApiException, NoApiKeyException, UploadFileException, IOException {
/*
* 图像输入方式说明:
* 以下提供了三种图片输入方式,三选一即可
* 1. 使用公网URL - 适合已有公开可访问的图片
* 2. 使用本地文件 - 适合本地开发测试
* 3. 使用Base64编码 - 适合私有图片或需要加密传输的场景
*/
// 【方式一】使用公网图片 URL
String image1 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp";
String image2 = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp";
// 【方式二】使用本地文件(支持绝对路径和相对路径)
// 格式要求:file:// + 文件路径
// String image1 = "file:///path/to/your/car.png";
// String image2 = "file:///path/to/your/paint.png";
// 【方式三】使用Base64编码的图片
// String image1 = encodeFile("/path/to/your/car.png");
// String image2 = encodeFile("/path/to/your/paint.png");
// 构建多图输入消息
ImageGenerationMessage message = ImageGenerationMessage.builder()
.role("user")
.content(Arrays.asList(
// 支持多图输入,可以提供多张参考图片
Collections.singletonMap("text", "把图2的涂鸦喷绘在图1的汽车上"),
Collections.singletonMap("image", image1),
Collections.singletonMap("image", image2)
)).build();
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(apiKey)
.model("wan2.7-image-pro")
.n(1)
.size("2K") // wan2.7-image-pro仅文生图场景支持4K分辨率,图像编辑和组图生成支持最高2K分辨率
.messages(Arrays.asList(message))
.build();
ImageGeneration imageGeneration = new ImageGeneration();
ImageGenerationResult result = null;
try {
System.out.println("---async call for image editing, creating task----");
result = imageGeneration.asyncCall(param);
} catch (ApiException | NoApiKeyException | UploadFileException e) {
throw new RuntimeException(e.getMessage());
}
System.out.println("任务创建结果:");
System.out.println(JsonUtils.toJson(result));
String taskId = result.getOutput().getTaskId();
// 等待任务完成
waitTask(taskId);
}
public static void waitTask(String taskId) throws ApiException, NoApiKeyException, IOException {
ImageGeneration imageGeneration = new ImageGeneration();
System.out.println("\n---waiting for task completion----");
ImageGenerationResult result = imageGeneration.wait(taskId, apiKey);
// 提取结果图片URL并保存到本地
for (int i = 0; i < result.getOutput().getChoices().size(); i++) {
List<Map<String, Object>> contents = result.getOutput().getChoices().get(i)
.getMessage().getContent();
for (int j = 0; j < contents.size(); j++) {
if ("image".equals(contents.get(j).get("type"))) {
String imageUrl = (String) contents.get(j).get("image");
String fileName = "output_" + i + "_" + j + ".png";
// 结果URL有效期为24小时,请及时下载
try (InputStream in = new URL(imageUrl).openStream()) {
Files.copy(in, Paths.get(fileName), StandardCopyOption.REPLACE_EXISTING);
}
System.out.println("Image saved to " + fileName);
}
}
}
}
public static void main(String[] args) throws ApiException, NoApiKeyException, UploadFileException, IOException {
asyncCall();
}
}
Response example
- Response example for task creation
{
"requestId": "ccf4b2f4-bf30-9e13-9461-3a28c6a7bxxx",
"output": {
"task_id": "8811b4a4-00ac-4aa2-a2fd-017d3b90cxxx",
"task_status": "PENDING"
},
"status_code": 200,
"code": "",
"message": ""
}
- Response example for querying task results
The URL is valid for 24 hours. Download and save the image in time.
{
"requestId": "60a08540-f1c1-9e76-8cd3-d5949db8cxxx",
"usage": {
"input_tokens": 18711,
"output_tokens": 2,
"total_tokens": 18713,
"image_count": 1,
"size": "2985*1405"
},
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
"type": "image"
}
]
}
}
],
"task_id": "8811b4a4-00ac-4aa2-a2fd-017d3b90cxxx",
"task_status": "SUCCEEDED",
"finished": true,
"submit_time": "2026-03-31 19:57:58.840",
"scheduled_time": "2026-03-31 19:57:58.877",
"end_time": "2026-03-31 19:58:11.563"
},
"status_code": 200,
"code": "",
"message": ""
}
curl
Step 1: Create a task to obtain the task ID
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "X-DashScope-Async: enable" \
--data '{
"model": "wan2.7-image-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"},
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"},
{"text": "把图2的涂鸦喷绘在图1的汽车上"}
]
}
]
},
"parameters": {
"size": "2K",
"n": 1,
"watermark": false
}
}'
Response example{
"output": {
"task_status": "PENDING",
"task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
},
"request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}
Step 2: Query the result by task ID
Use the task_id obtained in the previous step to poll the task status via the API until task_status becomes SUCCEEDED or FAILED.
Replace {task_id} entirely with the value of task_id returned by the API in the previous step. task_id is valid for query for 24 hours, and replace {WorkspaceId} with your actual Workspace ID.
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Response exampleThe image URL is valid for 24 hours. Download the image in a timely manner.
{
"request_id": "810fa5f5-334c-91f3-aaa4-ed89cf0caxxx",
"output": {
"task_id": "a81ee7cb-014c-473d-b842-76e98311cxxx",
"task_status": "SUCCEEDED",
"submit_time": "2026-03-26 17:16:01.663",
"scheduled_time": "2026-03-26 17:16:01.716",
"end_time": "2026-03-26 17:16:22.961",
"finished": true,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-xxx.oss-xxx.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
}
]
}
}
]
},
"usage": {
"size": "2976*1408",
"total_tokens": 11017,
"image_count": 1,
"output_tokens": 2,
"input_tokens": 11015
}
}
wan2.5-i2i-preview uses a different API endpoint and parameter passing method. Its calling examples are as follows:
Click to view the wan2.5-i2i-preview calling examples
Synchronous call
ImportantEnsure that the DashScope Python SDK version is no earlier than 1.25.2 and the DashScope Java SDK version is no earlier than 2.22.2.
If the version is too low, errors such as "url error, please check url!" may be triggered. Refer to Install or upgrade the SDK to update.
Python
This example supports three image input methods: public URL, Base64 encoding, and local file path.
Request example
import base64
import mimetypes
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import dashscope
import requests
import os
# 以下为新加坡地域的配置。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的region取值不同。
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 新加坡和北京地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
# --- 输入图片:使用 Base64 编码 ---
# base64编码格式为 data:{MIME_type};base64,{base64_data}
def encode_file(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
if not mime_type or not mime_type.startswith("image/"):
raise ValueError("不支持或无法识别的图像格式")
with open(file_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
return f"data:{mime_type};base64,{encoded_string}"
"""
图像输入方式说明:
以下提供了三种图片输入方式,三选一即可
1. 使用公网URL - 适合已有公开可访问的图片
2. 使用本地文件 - 适合本地开发测试
3. 使用Base64编码 - 适合私有图片或需要加密传输的场景
"""
# 【方式一】使用公网图片 URL
image_url_1 = "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp"
image_url_2 = "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"
# 【方式二】使用本地文件(支持绝对路径和相对路径)
# 格式要求:file:// + 文件路径
# 示例(绝对路径):
# image_url_1 = "file://" + "/path/to/your/image_1.png" # Linux/macOS
# image_url_2 = "file://" + "C:/path/to/your/image_2.png" # Windows
# 示例(相对路径):
# image_url_1 = "file://" + "./image_1.png" # 以实际路径为准
# image_url_2 = "file://" + "./image_2.png" # 以实际路径为准
# 【方式三】使用Base64编码的图片
# image_url_1 = encode_file("./image_1.png") # 以实际路径为准
# image_url_2 = encode_file("./image_2.png") # 以实际路径为准
print('----sync call, please wait a moment----')
# generate 为一步式调用(提交+等待),直接返回已完成的任务结果
job = client.images.generate(model="wan2.5-i2i-preview",
prompt="将图1中的闹钟放置到图2的餐桌的花瓶旁边位置",
extra_input={'images': [image_url_1, image_url_2]},
negative_prompt="",
n=1,
# size="1280*1280",
prompt_extend=True,
watermark=False,
seed=12345)
print('response: %s' % job)
# 在当前目录下保存图片
for result in job.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)
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{
"status_code": 200,
"request_id": "8ad45834-4321-44ed-adf5-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "3aff9ebd-35fc-4339-98a3-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"orig_prompt": "将图1中的闹钟放置到图2的餐桌的花瓶旁边位置",
"actual_prompt": "将图1中的蓝色闹钟放置在图2餐桌的花瓶右侧,靠近桌布边缘的位置,保持闹钟朝向镜头,与桌面平行,阴影自然投射于桌面。"
}
],
"submit_time": "2025-10-23 16:18:16.009",
"scheduled_time": "2025-10-23 16:18:16.040",
"end_time": "2025-10-23 16:19:09.591",
"task_metrics": {
"TOTAL": 1,
"FAILED": 0,
"SUCCEEDED": 1
}
},
"usage": {
"image_count": 1
}
}
Java
This example supports three image input methods: public URL, Base64 encoding, and local file path.
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.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
public class Image2Image {
static {
// 以下为新加坡地域URL,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的URL不同。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:apiKey="sk-xxx"
// 新加坡和北京地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* 图像输入方式说明:三选一即可
*
* 1. 使用公网URL - 适合已有公开可访问的图片
* 2. 使用本地文件 - 适合本地开发测试
* 3. 使用Base64编码 - 适合私有图片或需要加密传输的场景
*/
//【方式一】公网URL
static String imageUrl_1 = "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp";
static String imageUrl_2 = "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp";
//【方式二】本地文件路径(file://+绝对路径 or file:///+绝对路径)
// static String imageUrl_1 = "file://" + "/your/path/to/image_1.png"; // Linux/macOS
// static String imageUrl_2 = "file:///" + "C:/your/path/to/image_2.png"; // Windows
//【方式三】Base64编码
// static String imageUrl_1 = encodeFile("/your/path/to/image_1.png");
// static String imageUrl_2 = encodeFile("/your/path/to/image_2.png");
// 设置待编辑的图片列表
static List<String> imageUrls = new ArrayList<>();
static {
imageUrls.add(imageUrl_1);
imageUrls.add(imageUrl_2);
}
public static void syncCall() {
// 设置parameters参数
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", false);
parameters.put("seed", 12345);
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.5-i2i-preview")
.prompt("将图1中的闹钟放置到图2的餐桌的花瓶旁边位置")
.images(imageUrls)
.n(1)
//.size("1280*1280")
.negativePrompt("")
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
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));
}
/**
* 将文件编码为Base64字符串
* @param filePath 文件路径
* @return Base64字符串,格式为 data:{MIME_type};base64,{base64_data}
*/
public static String encodeFile(String filePath) {
Path path = Paths.get(filePath);
if (!Files.exists(path)) {
throw new IllegalArgumentException("文件不存在: " + filePath);
}
// 检测MIME类型
String mimeType = null;
try {
mimeType = Files.probeContentType(path);
} catch (IOException e) {
throw new IllegalArgumentException("无法检测文件类型: " + filePath);
}
if (mimeType == null || !mimeType.startsWith("image/")) {
throw new IllegalArgumentException("不支持或无法识别的图像格式");
}
// 读取文件内容并编码
byte[] fileBytes = null;
try{
fileBytes = Files.readAllBytes(path);
} catch (IOException e) {
throw new IllegalArgumentException("无法读取文件内容: " + filePath);
}
String encodedString = Base64.getEncoder().encodeToString(fileBytes);
return "data:" + mimeType + ";base64," + encodedString;
}
public static void main(String[] args) {
syncCall();
}
}
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{
"request_id": "d362685b-757f-4eac-bab5-xxxxxx",
"output": {
"task_id": "bfa7fc39-3d87-4fa7-b1e6-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"orig_prompt": "将图1中的闹钟放置到图2的餐桌的花瓶旁边位置",
"actual_prompt": "将图1中的蓝色闹钟放置在图2餐桌的花瓶右侧,靠近桌布边缘的位置,保持闹钟正面朝向镜头,与花瓶平行摆放。",
"url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"
}
],
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
},
"usage": {
"image_count": 1
}
}
Asynchronous call
ImportantEnsure that the DashScope Python SDK version is no earlier than 1.25.2 and the DashScope Java SDK version is no earlier than 2.22.2.
If the version is too low, errors such as "url error, please check url!" may be triggered. Refer to Install or upgrade the SDK to update.
Python
This example uses the public URL method to pass in images.
Request example
import os
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import dashscope
import requests
# 以下为新加坡地域的配置。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的region取值不同。
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 新加坡和北京地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
# 使用公网图片 URL
image_url_1 = "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp"
image_url_2 = "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"
def async_call():
print('----create task----')
task_info = create_async_task()
print('----wait task----')
wait_async_task(task_info)
# 创建异步任务
def create_async_task():
job = client.images.jobs.create(model="wan2.5-i2i-preview",
prompt="将图1中的闹钟放置到图2的餐桌的花瓶旁边位置",
extra_input={'images': [image_url_1, image_url_2]},
negative_prompt="",
n=1,
# size="1280*1280",
prompt_extend=True,
watermark=False,
seed=12345)
print(job)
print(job.task_id, job.status)
return job
# 等待异步任务结束(指数退避轮询,默认总预算24小时;任务失败会抛出DashScopeError)
def wait_async_task(task):
done = client.images.jobs.wait(task)
print(done)
print(done.status)
# save file to current directory
for result in done.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)
# 获取异步任务信息
def fetch_task_status(task):
snapshot = client.images.jobs.fetch(task)
print(snapshot)
print(snapshot.status)
# 取消异步任务,只有处于PENDING状态的任务才可以取消
def cancel_task(task):
job = client.images.jobs.cancel(task)
print(job)
if __name__ == '__main__':
async_call()
Response example
- Response example 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
}
- Response example for querying task results
The url is valid for 24 hours. Download the image in a timely manner.
{
"status_code": 200,
"request_id": "8ad45834-4321-44ed-adf5-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "3aff9ebd-35fc-4339-98a3-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"orig_prompt": "将图1中的闹钟放置到图2的餐桌的花瓶旁边位置",
"actual_prompt": "将图1中的蓝色闹钟放置在图2餐桌的花瓶右侧,靠近桌布边缘的位置,保持闹钟朝向镜头,与桌面平行,阴影自然投射于桌面。"
}
],
"submit_time": "2025-10-23 16:18:16.009",
"scheduled_time": "2025-10-23 16:18:16.040",
"end_time": "2025-10-23 16:19:09.591",
"task_metrics": {
"TOTAL": 1,
"FAILED": 0,
"SUCCEEDED": 1
}
},
"usage": {
"image_count": 1
}
}
Java
By default, this example uses the public URL method to pass in images.
Request example
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisListResult;
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.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Image2Image {
static {
// 以下为新加坡地域URL,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的URL不同。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:apiKey="sk-xxx"
// 新加坡和北京地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
//公网URL
static String imageUrl_1 = "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp";
static String imageUrl_2 = "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp";
// 设置待编辑的图片列表
static List<String> imageUrls = new ArrayList<>();
static {
imageUrls.add(imageUrl_1);
imageUrls.add(imageUrl_2);
}
public static void asyncCall() {
// 设置parameters参数
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", false);
parameters.put("seed", 12345);
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.5-i2i-preview")
.prompt("将图1中的闹钟放置到图2的餐桌的花瓶旁边位置")
.images(imageUrls)
.n(1)
//.size("1280*1280")
.negativePrompt("")
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---async call, please wait a moment----");
result = imageSynthesis.asyncCall(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
String taskId = result.getOutput().getTaskId();
System.out.println("taskId=" + taskId);
try {
result = imageSynthesis.wait(taskId, apiKey);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
System.out.println(JsonUtils.toJson(result.getOutput()));
}
public static void listTask() throws ApiException, NoApiKeyException {
ImageSynthesis is = new ImageSynthesis();
AsyncTaskListParam param = AsyncTaskListParam.builder().build();
param.setApiKey(apiKey);
ImageSynthesisListResult result = is.list(param);
System.out.println(result);
}
public void fetchTask(String taskId) throws ApiException, NoApiKeyException {
ImageSynthesis is = new ImageSynthesis();
// 如果已设置 DASHSCOPE_API_KEY 为环境变量,apiKey 可为空。
ImageSynthesisResult result = is.fetch(taskId, apiKey);
System.out.println(result.getOutput());
System.out.println(result.getUsage());
}
public static void main(String[] args) {
asyncCall();
}
}
Response example
- Response example for task creation
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-542f97709ba8",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}
- Response example for querying task results
The url is valid for 24 hours. Download the image in a timely manner.
{
"request_id": "d362685b-757f-4eac-bab5-xxxxxx",
"output": {
"task_id": "bfa7fc39-3d87-4fa7-b1e6-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"orig_prompt": "将图1中的闹钟放置到图2的餐桌的花瓶旁边位置",
"actual_prompt": "将图1中的蓝色闹钟放置在图2餐桌的花瓶右侧,靠近桌布边缘的位置,保持闹钟正面朝向镜头,与花瓶平行摆放。",
"url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"
}
],
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
},
"usage": {
"image_count": 1
}
}
curl
This example consists of two steps: creating a task and querying the result.
Note
- For asynchronous calls, you must set the Header parameter
X-DashScope-Asynctoenable. - The
task_idof an asynchronous task can be queried within 24 hours; after that, the task status becomesUNKNOWN.
Step 1: Send a task creation request
This request returns a task ID (task_id).
Request example
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis' \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wan2.5-i2i-preview",
"input": {
"prompt": "将图1中的闹钟放置到图2的餐桌的花瓶旁边位置",
"images": [
"https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp",
"https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"
]
},
"parameters": {
"n": 1
}
}'
Response example{
"output": {
"task_status": "PENDING",
"task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
},
"request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}
Step 2: Query the result by task ID
Use the task_id obtained in the previous step to poll the task status via the API until task_status becomes SUCCEEDED or FAILED.
Replace {task_id} entirely with the value of task_id returned by the API in the previous step. task_id is valid for query for 24 hours, and replace {WorkspaceId} with your actual Workspace ID.
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Response exampleThe image URL is valid for 24 hours. Download the image in a timely manner.
{
"request_id": "d1f2a1be-9c58-48af-b43f-xxxxxx",
"output": {
"task_id": "7f4836cd-1c47-41b3-b3a4-xxxxxx",
"task_status": "SUCCEEDED",
"submit_time": "2025-09-23 22:14:10.800",
"scheduled_time": "2025-09-23 22:14:10.825",
"end_time": "2025-09-23 22:15:23.456",
"results": [
{
"orig_prompt": "将图1中的闹钟放置到图2的餐桌的花瓶旁边位置",
"url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"
}
],
"task_metrics": {
"TOTAL": 1,
"FAILED": 0,
"SUCCEEDED": 1
}
},
"usage": {
"image_count": 1
}
}
Model Selection
-
wan2.7-image-pro and wan2.7-image (recommended): suitable for scenarios that require high editing precision or need to generate multiple images with coherent content.
- Precise local editing: select a specified region in the image, then move, replace, or add new elements to the objects in that region. Applicable to e-commerce photo retouching and design draft adjustments
- Multi-frame continuous image generation: outputs multiple images with a consistent style at once, applicable to comic storyboarding, product series images, and sequential story images
-
wan2.6-image: suitable for stylized editing scenarios with mixed text and images or multiple reference images. It can generate corresponding text content when generating images, and supports up to 4 reference images as input.
-
wan2.5-i2i-preview: suitable for simple image editing and multi-image fusion.
For the input and output specifications of each model, see Input image specifications and Output image resolution.
Showcases
Image-to-image set generation
Input image | Output image |
|---|---|
|
|
|
|
Click to view the prompt
Case 1: Portrait photography
基础人物设定:一位 20 岁的东亚男性,头发是卷卷的半长发,文艺气质,五官立体,眉眼清秀,穿着简约白色 T 恤或浅蓝色衬衫,少年感,自然气质。
1. 民国文人风 (Republic Era Scholar)
提示词:
[基础面部描述] 人物形象为参考图1,身穿深青色长衫,佩戴圆框金丝眼镜,手持一把折扇,背景是老旧的上海书房,木质书架,暖黄色调,复古胶片质感,柔和的侧光,尘埃在光束中飞舞,文化气息,沉静内敛,哈苏中画幅,85mm 镜头,高分辨率,电影感调色,王家卫风格。
道具: 折扇 / 线装书 / 圆框眼镜
色调: 暖黄 / 深青 / sepia
2. 英伦绅士风 (British Gentleman)
提示词:
[基础面部描述] 人物形象为参考图1,穿着深灰色粗花呢西装三件套,佩戴复古机械腕表,手持高脚红酒杯,并看向酒杯,背景是古典图书馆或私人俱乐部,深色皮革沙发,伦勃朗光,暗调氛围,优雅高贵,冷峻眼神,细节丰富,纹理清晰,英国贵族气质,8k 分辨率,时尚杂志大片。
道具: 红酒杯 / 烟斗 / 机械表
色调: 深灰 / 酒红 / 暗金
3. 90s 港风复古 (90s HK Retro)
提示词:
[基础面部描述] 人物形象为参考图1,穿着水洗牛仔夹克或花衬衫,头发微乱,双手抱胸,背景是夜晚的霓虹灯牌街道,模糊的光斑,高颗粒感,色彩浓郁,红蓝撞色,王家卫风格,情绪化,迷离眼神,闪光灯直出效果,怀旧氛围,【全身镜头】。
色调: 霓虹红 / 深蓝 / 胶片绿
4. 新中式禅意 (New Chinese Zen)
提示词:
[基础面部描述]人物形象为参考图1,人物淡淡露齿笑, 穿着改良式白色中式立领上衣,手持折枝梅花,背景是极简的留白墙面或竹林,阳光洒在墙面上留下斑驳光影,清冷色调,宁静致远,东方美学,皮肤通透,高颗粒感,哑光,构图简洁,光影层次丰富,高端摄影,禅意氛围。
道具: 梅花枝
色调: 白 / 墨绿 / 浅灰
5. 复古艺术家 (Vintage Artist)
提示词:
[基础面部描述] 人物形象为参考图1,穿着沾有颜料的白色衬衫,系着棕色皮围裙,手持画笔或调色板,背景是干净的工作室,光线明亮,色彩斑斓的光影,专注的神情,看向手中颜料,不看镜头,头发略显凌乱,艺术气息,印象派色调,质感强烈。
道具: 画笔 / 调色板 / 素描本
色调: 暖光 / 多彩颜料 / 棕色
6. 经典黑白电影 (Classic Noir B&W)
提示词:
[基础面部描述] 人物形象为参考图1,穿着黑色高领毛衣,手持一根香烟,戴着黑色礼帽,背景是阴影交错的楼梯或走廊,高对比度黑白摄影,硬光照明,强烈的阴影,神秘感,冷硬派侦探风格,面部轮廓分明,皮肤纹理极致清晰,经典电影剧照,永恒感,侧脸特写,艺术摄影。
道具: 手杖 / 礼帽 / 墨镜
色调: 黑白 / 高对比度
Case 2: Visual design
图1:一张商业级产品摄影主视觉封面图,正视全景构图,一款复古未来主义风格的无线头戴式耳机悬浮于几何石膏体之上,耳机呈现完全对称美学,材质为香槟金金属与奶油白外壳,背景为深度虚化的温暖室内光影,光线柔和地勾勒出产品轮廓,画面留白处具有极强的呼吸感,营造静谧的听觉暗示,8k超高清分辨率,极简高级感。
图2:100mm微距镜头拍摄的产品材质特写,极近距离聚焦于耳机的伸缩臂连接处,清晰展示香槟金拉丝铝合金的金属纹理与CNC精密精割倒角,一道锐利的侧逆光在金属边缘形成星芒高光,背景深暗以突出金属的工业精密感,画质极度锐利,无噪点。
图3:极近距离的微距材质特写,聚焦于摩卡色蛋白皮耳罩的表面,通过侧光展现皮革细腻的毛孔纹理、柔软的按压褶皱与透气孔细节,传达极致的亲肤佩戴舒适度与回弹感,光影层次丰富,色调温暖湿润,超高清微距摄影。
图4:艺术化的产品爆炸视图,将复古未来主义耳机的内部发声单元、降噪芯片、电池模块与外部的胡桃木装饰片、金属框架进行悬浮拆解展示,背景为深邃的科技蓝,内部元件呈现半透明的全息科技质感,强调内部精密工艺与现代科技的结合,高科技商业海报风格。
图5:35mm人文镜头拍摄的佩戴场景图,特写模特的下颌线与颈部,展示佩戴这款香槟金耳机时的完美贴合度,自然暖调夕阳光从侧后方射入形成轮廓光,发丝边缘透着金光,模特肤色呈现健康自然的质感,营造沉浸式听歌的松弛生活感,背景为模糊的居家环境。
图6:致敬建筑光影的静物摄影,将耳机放置于极简的灰色混凝土桌面上,午后阳光透过百叶窗投下条纹状的硬光影,光影切过哑光奶油白机身与香槟金框架,形成明暗强烈的几何构成,凸显机身的立体廓形与材质对比,冷暖色调对撞,极简主义构图。
图7:俯视平铺构图的色彩方案展示图,并排陈列该系列三款不同配色的耳机,分别为银白、黑金、蓝铜配色,背景为肌理感极强的灰色羊毛毡布,柔和顶光照明,强调CMF设计的多样性与材质的细腻触感,画面整洁有序,设计杂志风格。
图8:品牌生活方式的全家福静物摄影,复古未来主义耳机被收纳在配套的精致皮箱旁,桌面上摆放着黑胶唱片机、一张正在旋转的黑胶唱片与一杯冒着热气的咖啡,背景有暖色调的氛围灯渲染,深胡桃木色调为主,传递慢生活与高保真音质结合的品牌生活哲学,电影感叙事光影。
Interactive editing
Input image | Output image |
|---|---|
|
Place the pattern framed in image 1 at the framed area in image 2 |
Multi-image fusion
Input image | Output image |
|---|---|
|
Take a portrait photo of the man in image 1 and the dog in image 2, with the man holding the dog in his arms and both of them looking happy, under soft studio lighting against a blue textured background |
|
Recolor the dress in image 1 based on the colors of the bird in image 2, with an artistic feel, keeping the dress style and the model unchanged |
Subject feature preservation
Input image | Output image |
|---|---|
|
Please generate a set of four instant photos arranged in a 2x2 grid with a "Seasonal Changes" theme. Each photo is taken at the same location, under a tree in a park, but depicts one of the four seasons: spring, summer, autumn, or winter. The person's clothing should also match the season: a light jacket in spring, short sleeves in summer, a trench coat in autumn, and a scarf and heavy coat in winter. Place this set of photos on a dining table. |
Detection and segmentation
Input image | Output image |
|---|---|
|
Detect the laptop and alarm clock in the image, draw boxes around them and label them "laptop" and "clock" |
|
Segment the glass in the image |
Element extraction
Input image | Output image |
|---|---|
|
Extract outfit items from the uploaded photo, arrange them in a flat-lay layout on a pure white background, preserving realistic details and material textures, in a fashion e-commerce style, suitable for clothing display. |
Text editing
Input image | Output image |
|---|---|
|
Remove watermarks from the entire image |
|
Write "Time for Holiday?" by hand in the sand on the beach |
|
Change 18 to 29 and JUNE to SEPTEMBER |
Camera and perspective editing
Input image | Output image |
|---|---|
|
Keep the person's features unchanged and generate the front view, side view, and back view |
|
Retake this photo with a fisheye lens |
Input instructions
Input image specifications
Type | wan2.7-image-pro、wan2.7-image | wan2.6-image | wan2.5-i2i-preview |
|---|---|---|---|
Number of input images | 0 to 9 images (0 images corresponds to the text-to-image mode) | Image editing: 1 to 4 images / Image-text composition: 0 to 1 images | 1 to 3 images |
Image Format | JPEG, JPG, PNG (transparency channel not supported), BMP, WEBP | JPEG, JPG, PNG (transparency channel not supported), BMP, WEBP | JPEG, JPG, PNG (transparency channel not supported), BMP, WEBP |
Image width and height range | [240, 8000] pixels | [240, 8000] pixels | [384, 5000] pixels |
File Size | ≤ 20MB | ≤ 10MB | ≤ 10MB |
Aspect Ratio | [1:8, 8:1] | Unlimited | [1:4, 4:1] |
Image input order
When multiple images are input, the image order is defined by their order in the array. Therefore, the image numbers referenced in the prompt must correspond one-to-one with the order in the image array. For example: the first image in the array is "Image 1", the second is "Image 2", or you can use marker forms such as "[Image 1]" and "[Image 2]".
{
"content": [
{"text": "编辑指令,如:将图1中的闹钟放置到图2的餐桌的花瓶旁边位置"},
{"image": "https://example.com/image1.png"},
{"image": "https://example.com/image2.png"}
]
}
Input image | Output image | ||
|---|---|---|---|
Image 1 |
Image 2 |
Prompt: Move Image 1 onto Image 2 |
Prompt: Move Image 2 onto Image 1 |
Image input methods
Images can be passed in using the following methods:
Method 2: Base64 encoding
Convert the image file into a Base64-encoded string and concatenate it in the following format: data:{MIME_type};base64,{base64_data}.
-
Example value:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABDg......(only a fragment is shown due to length limits). When making the call, you must pass in the complete string. -
{base64_data}: The Base64-encoded string of the image file.
-
{MIME_type}: The media type of the image, which must match the file format.
Image Format
MIME Type
JPEG
image/jpeg
JPG
image/jpeg
PNG
image/png
BMP
image/bmp
WEBP
image/webp
-
Applicable scenarios: local images, private images, or scenarios that require encrypted transmission.
Method 3: Local file path (SDK only)
-
Python SDK: Supports both absolute and relative paths of files. The file path rules are as follows:
System
Input file path
Example (absolute path)
Example (relative path)
Linux or macOS
file://{absolute or relative file path}
file:///home/images/test.png
file://./images/test.png
Windows
file://D:/images/test.png
file://./images/test.png
-
Java SDK: Only supports absolute paths of files. The file path rules are as follows:
System
Input file path
Example (absolute path)
Linux or macOS
file://{absolute file path}
file:///home/images/test.png
Windows
file:///{absolute file path}
file:///D:/images/test.png
-
Applicable scenarios: Suitable for quick testing in a local development environment.
Key capabilities
1. Instruction following (prompt)
Parameters: messages.content.text or input.prompt (required), and negative_prompt (optional).
- text \ prompt (positive prompt): Describes the content, subject, scene, style, lighting, and composition you want to see in the image.
- negative_prompt (negative prompt): Describes the content you do not want to appear in the image, such as "blur" or "extra fingers". It is only used to help optimize generation quality.
Parameter | wan2.7-image-pro、wan2.7-image | wan2.6-image | wan2.5-i2i-preview |
|---|---|---|---|
text | Required, up to 5000 characters | Required, up to 2000 characters | Not supported |
prompt | Not supported | Not supported | Required, up to 2000 characters |
negative_prompt | Not supported | Supported, up to 500 characters | Supported, up to 500 characters |
2. Enable intelligent prompt rewriting
Parameter: parameters.prompt_extend (bool, defaults to true).
This feature automatically expands and optimizes short prompts to improve output image quality. Enabling this feature adds extra processing time.
Best practices:
- Recommended to enable: When the input prompt is brief or broad, this feature can improve image quality.
- Recommended to disable: If you need to control image details, have already provided a detailed description, or are sensitive to response latency. Please explicitly set the
prompt_extendparameter tofalse.
Parameter | wan2.7-image-pro、wan2.7-image | wan2.6-image | wan2.5-i2i-preview |
|---|---|---|---|
prompt_extend | Not supported | Supported (image editing mode only) | Supported |
3. Set the output image resolution
Parameter: parameters.size (string), in the format "width*height".
ImportantThe same tier 1K is defined differently across models: the wan2.7 series outputs a total pixel count close to 10241024, while wan2.6-image is close to 12801280. Pay attention to the differences in output resolution when switching models.
| Parameter | wan2.7-image-pro、wan2.7-image | wan2.6-image | wan2.5-i2i-preview |
|---|---|---|---|
size | Method 1: Specify the resolution of the output image (recommended) In edit mode (with at least one image provided), the available output resolution tiers are
| Method 1: Reference the aspect ratio of the input image (recommended) In edit mode (
| Only specifying the width and height pixel values of the generated image is supported
|
4. Interactive precise editing
The parameters.bbox_list parameter boxes the objects or areas in the image that need editing, achieving more accurate editing results. Only wan2.7-image-pro and wan2.7-image support this.
- Correspondence: The list length must match the number of input images. If an image does not need editing, pass an empty list
[]in the corresponding position. - Coordinate format:
[x1, y1, x2, y2](top-left x, top-left y, bottom-right x, bottom-right y), using absolute pixel coordinates of the original image, with the top-left corner at (0, 0), the x-axis pointing right, and the y-axis pointing down. If you use a vision model (such as qwen3.6-plus) to locate the target area, it returns normalized coordinates [0, 999]. Convert them to absolute pixel coordinates using the auxiliary code below before passing them in. - Quantity limit: A single image supports at most 2 bounding boxes.
Example: 3 images are input, where the 2nd image has no box selection and the 1st image has two box selections:
[
[[0, 0, 12, 12], [25, 25, 100, 100]],
[],
[[10, 10, 50, 50]]
]
Click to view the invocation example
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"model": "wan2.7-image-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{"image": "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp"},
{"image": "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"},
{"text": "把图1的闹钟放在图2的框选的位置,保持场景和光线融合自然"}
]
}
]
},
"parameters": {
"bbox_list": [[],[[989, 515, 1138, 681]]],
"size": "2K",
"n": 1,
"watermark": false
}
}'
How to determine the coordinates of the editing area
Drag the mouse on the image to draw a box, which is precise and intuitive:
# 安装依赖:pip install opencv-python
import cv2
import urllib.request
# 下载示例图片(替换为您自己的图片 URL 或本地路径)
image_url = "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"
urllib.request.urlretrieve(image_url, "example.webp")
# 读取图片并弹出交互窗口
img = cv2.imread("example.webp")
# 在弹出的窗口中用鼠标拖拽画框,按 Enter 确认选区,按 Esc 取消
x, y, w, h = cv2.selectROI("Draw bounding box (Enter=confirm, Esc=cancel)", img)
cv2.destroyAllWindows()
# 将 OpenCV 返回的 (x, y, w, h) 转换为 bbox_list 所需的 [x1, y1, x2, y2] 格式
# 坐标系:原点在图片左上角,x 轴向右,y 轴向下,单位为像素
bbox = [x, y, x + w, y + h]
print(f"框选坐标: {bbox}") # 将此坐标传入 parameters.bbox_list
Method 2: Vision understanding modelUse qwen3.6-plus to automatically identify the coordinates of the target area. Simply describe the target in natural language to obtain the coordinates:
# 安装依赖:pip install dashscope pillow
import os
import json
import dashscope
from PIL import Image
import urllib.request
# 以下为新加坡地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的region取值不同。
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
def get_bbox_list(image, prompt):
"""
通过 qwen3.6-plus 识别图片中的目标区域,返回绝对像素坐标列表。
Args:
image: 图片 URL 或本地路径(本地路径格式为 "file:///absolute/path.png")
prompt: 自然语言描述,如 "咖啡杯"、"盘子里所有的水果"、"盘子正中间的水果"
Returns:
[[x1, y1, x2, y2], ...] 绝对像素坐标,可直接传入 bbox_list
"""
# 将用户描述与返回格式指令拼接
full_prompt = (
prompt + "\n"
"请根据以上描述,返回对应区域的坐标。\n"
"最多返回2个区域,优先返回最匹配的目标。\n"
"严格按照JSON二维列表格式返回:[[x1, y1, x2, y2], ...]\n"
"每组坐标:[左上角x, 左上角y, 右下角x, 右下角y]\n"
"坐标系以图片左上角为(0,0),x轴向右,y轴向下。\n"
"如果只有一个区域,也必须使用二维列表:[[x1, y1, x2, y2]]\n"
"只返回JSON列表,不要返回其他任何内容。"
)
messages = [
{'role': 'user',
'content': [
{'image': image},
{'text': full_prompt}
]}
]
response = client.multimodal.chat.create(
model='qwen3.6-plus',
messages=messages,
)
text = response.output_text
text = text.replace("```json", "").replace("```", "").strip()
coords = json.loads(text)
# 兼容模型返回一维列表 [x1,y1,x2,y2] 的情况
if coords and not isinstance(coords[0], list):
coords = [coords]
# 获取图片尺寸,用于坐标转换
if image.startswith("file://"):
local_path = image[len("file://"):]
img = Image.open(local_path)
else:
tmp_path = "temp_bbox_image"
urllib.request.urlretrieve(image, tmp_path)
img = Image.open(tmp_path)
width, height = img.size
# qwen3.6-plus 等 Qwen3-VL 系列模型返回归一化坐标 [0, 999],此处转换为绝对像素坐标
bbox_list = []
for box in coords:
bbox_list.append([
int(box[0] / 1000 * width),
int(box[1] / 1000 * height),
int(box[2] / 1000 * width),
int(box[3] / 1000 * height)
])
return bbox_list
# === 使用示例 ===
image_url = "https://img.alicdn.com/imgextra/i3/O1CN01ewUWhg1eS3VqJ3wap_!!6000000003869-49-tps-2048-2048.webp"
# 按名称选取目标
bbox = get_bbox_list(image_url, "咖啡杯") # [[x1, y1, x2, y2]]
# 按位置描述选取目标
bbox = get_bbox_list(image_url, "盘子正中间的水果") # [[x1, y1, x2, y2]]
# 描述一个区域
bbox = get_bbox_list(image_url, "薰衣草盆栽")
# 结果可作为 bbox_list 数组中的元素
# 注意:单张图片最多支持 2 个边界框
Billing and rate limits
-
For the model free quota and billing unit price, see Model list and prices.
-
For model rate limits, see Wan.
-
Billing details:
- Billing is based on the number of images successfully generated. You are billed only after the API returns
task_statusasSUCCEEDEDand the images are successfully generated. - Failed model calls or processing errors incur no charges and do not consume the free quota.
- Billing is based on the number of images successfully generated. You are billed only after the API returns
API reference
Each model uses different endpoints and request structures:
Model | Endpoint (with the Singapore region as an example) |
|---|---|
| Synchronous endpoint: Asynchronous endpoint: When calling, replace |
| Asynchronous endpoint: When calling, replace |
wan2.7/wan2.6:messagesformat. In themessages[].contentarray, images are passed viaimage, and prompts viatext.wan2.5: Images are passed via theinput.imagesarray, and prompts viainput.prompt
"input": {
"messages": [
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"},
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"},
{"text": "把图2的涂鸦喷绘在图1的汽车上"}
]
}
]
}
"input": {
"prompt": "将图1中的闹钟放置到图2的餐桌的花瓶旁边位置",
"images": [
"https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp",
"https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"
]
}
For input and output parameters, see Wan-Image Generation and Editing 2.7 API reference, Wan-Image Generation and Editing 2.6 API reference, and Wan-Universal Image Editing 2.5 API reference.


































