Wan モデルを使用して、テキスト指示で画像を編集します。マルチ画像の入出力、画像融合、被写体維持、オブジェクト検出をサポートしています。
クイックスタート
wan2.7-image-pro を使用して、2 つの入力画像とテキストプロンプトから編集済み画像を生成します。
プロンプト:画像 2 のグラフィティを画像 1 の車にスプレーペイントする
入力画像 1 | 入力画像 2 | 出力画像 (wan2.7-image-pro) |
|
|
|
呼び出しを行う前に、API キーを取得し、API キーを環境変数としてエクスポートしてください。SDK を使用して呼び出しを行うには、DashScope SDK をインストールしてください。
同期呼び出し
DashScope Python SDK のバージョンが 1.25.15 以降、DashScope Java SDK のバージョンが 2.22.13 以降であることを確認してください。
Python
リクエスト例
import os
import base64
import mimetypes
import urllib.request
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message
# 以下はシンガポールリージョンの base_url です。base_url はリージョンによって異なります。
dashscope.base_http_api_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:api_key="sk-xxx"
# API キーはリージョンによって異なります。API キーを取得するには、https://www.alibabacloud.com/help/model-studio/get-api-key をご参照ください
api_key = os.getenv("DASHSCOPE_API_KEY")
# --- 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}"
"""
画像入力方法:
以下は 3 つの画像入力方法です。いずれか 1 つを選択してください。
1. パブリック URL を使用 - パブリックにアクセス可能な画像に適しています。
2. ローカルファイルを使用 - ローカルでの開発およびテストに適しています。
3. Base64 エンコーディングを使用 - プライベート画像や暗号化された伝送が必要なシナリオに適しています。
"""
# [方法 1] パブリック画像 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"
# [方法 2] ローカルファイルを使用 (絶対パスと相対パスをサポート)
# image_1 = "file:///path/to/your/car.png"
# image_2 = "file:///path/to/your/paint.png"
# [方法 3] Base64 エンコードされた画像を使用
# image_1 = encode_file("/path/to/your/car.png")
# image_2 = encode_file("/path/to/your/paint.png")
message = Message(
role="user",
content=[
{"text": "Spray the graffiti from image 2 onto the car in image 1"},
{"image": image_1},
{"image": image_2},
],
)
print("----sync call, please wait a moment----")
rsp = ImageGeneration.call(
model="wan2.7-image-pro",
api_key=api_key,
messages=[message],
watermark=False,
n=1,
size="2K", # wan2.7-image-pro は、テキストからの画像生成でのみ 4K 解像度をサポートします。画像編集とマルチ画像生成は最大 2K 解像度をサポートします。
)
# 結果の画像 URL を抽出し、画像をローカルファイルに保存します。
if rsp.status_code == 200:
for i, choice in enumerate(rsp.output.choices):
for j, content in enumerate(choice["message"]["content"]):
if content.get("type") == "image":
image_url = content["image"]
file_name = f"output_{i}_{j}.png"
# 結果の URL は 24 時間有効です。速やかにダウンロードしてください。
urllib.request.urlretrieve(image_url, file_name)
print(f"Image saved to {file_name}")
else:
print(f"Failed: status_code={rsp.status_code}, message={rsp.message}")
レスポンス例
URL は 24 時間有効です。速やかに画像をダウンロードしてください。
{
"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
リクエスト例
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 です。base_url はリージョンによって異なります。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:apiKey="sk-xxx"
// API キーはリージョンによって異なります。API キーを取得するには、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 {
/*
* 画像入力方法の説明:
* 以下に 3 つの画像入力方法が提供されています。いずれか 1 つを選択してください。
* 1. パブリック URL を使用:パブリックにアクセス可能な画像に適しています。
* 2. ローカルファイルを使用:ローカルでの開発およびテストに適しています。
* 3. Base64 エンコーディングを使用:プライベート画像や暗号化された伝送が必要なシナリオに適しています。
*/
// 方法 1:パブリック画像 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";
// 方法 2:ローカルファイルを使用します。絶対パスと相対パスの両方がサポートされています。
// フォーマット:file:// + ファイルパス
// String image1 = "file:///path/to/your/car.png";
// String image2 = "file:///path/to/your/paint.png";
// 方法 3: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", "Spray the graffiti from image 2 onto the car in image 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();
}
}
レスポンス例
URL は 24 時間有効です。速やかに保存してください。
{
"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
リクエスト例
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": "Spray-paint the graffiti from image 2 onto the car in image 1"}
]
}
]
},
"parameters": {
"size": "2K",
"n": 1,
"watermark": false
}
}'
レスポンス例
{
"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"
}非同期呼び出し
DashScope Python SDK のバージョンが 1.25.15 以降、DashScope Java SDK のバージョンが 2.22.13 以降であることを確認してください。
Python
リクエスト例
import os
import base64
import mimetypes
import urllib.request
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message
from http import HTTPStatus
# 以下はシンガポールリージョンの base_url です。base_url はリージョンによって異なります。
dashscope.base_http_api_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:api_key="sk-xxx"
# API キーはリージョンによって異なります。API キーを取得するには、https://www.alibabacloud.com/help/model-studio/get-api-key をご参照ください
api_key = os.getenv("DASHSCOPE_API_KEY")
# --- 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}"
"""
画像入力方法:
以下に 3 つの画像入力方法が提供されています。いずれか 1 つを選択してください。
1. パブリック URL を使用 - パブリックにアクセス可能な画像に適しています。
2. ローカルファイルを使用 - ローカルでの開発およびテストに適しています。
3. Base64 エンコーディングを使用 - プライベート画像や暗号化された伝送が必要なシナリオに適しています。
"""
# [方法 1] パブリック画像 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"
# [方法 2] ローカルファイルを使用 (絶対パスと相対パスをサポート)
# image_1 = "file:///path/to/your/car.png"
# image_2 = "file:///path/to/your/paint.png"
# [方法 3] 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...")
message = Message(
role="user",
content=[
{"text": "Spray the graffiti from image 2 onto the car in image 1."},
{"image": image_1},
{"image": image_2},
],
)
response = ImageGeneration.async_call(
model="wan2.7-image-pro",
api_key=api_key,
messages=[message],
watermark=False,
n=1,
size="2K", # wan2.7-image-pro は、テキストからの画像生成シナリオでのみ 4K 解像度をサポートします。画像編集とコラージュ生成は最大 2K 解像度をサポートします。
)
if response.status_code == 200:
print("Task created successfully:", response)
return response
else:
raise Exception(f"Failed to create task: {response.code} - {response.message}")
# タスクの完了を待ちます。
def wait_for_completion(task_response):
print("Waiting for task completion...")
status = ImageGeneration.wait(task=task_response, api_key=api_key)
if status.output.task_status == "SUCCEEDED":
print("Task succeeded!")
# 結果の画像 URL を抽出し、画像をローカルファイルに保存します。
for i, choice in enumerate(status.output.choices):
for j, content in enumerate(choice["message"]["content"]):
if content.get("type") == "image":
image_url = content["image"]
file_name = f"output_{i}_{j}.png"
# 結果の URL は 24 時間有効です。速やかに画像をダウンロードしてください。
urllib.request.urlretrieve(image_url, file_name)
print(f"Image saved to {file_name}")
else:
raise Exception(f"Task failed with status: {status.output.task_status}")
# 非同期タスクに関する情報を取得します。
def fetch_task_status(task):
print("Fetching task status...")
status = ImageGeneration.fetch(task=task, api_key=api_key)
if status.status_code == HTTPStatus.OK:
print("Task status:", status.output.task_status)
print("Response details:", status)
else:
print(f"Failed to fetch status: {status.code} - {status.message}")
# 非同期タスクをキャンセルします。
def cancel_task(task):
print("Canceling task...")
response = ImageGeneration.cancel(task=task, api_key=api_key)
if response.status_code == HTTPStatus.OK:
print("Task canceled successfully:", response.output.task_status)
else:
print(f"Failed to cancel task: {response.code} - {response.message}")
# メインの実行フロー。
if __name__ == "__main__":
task = create_async_task()
wait_for_completion(task)
レスポンス例
-
タスク作成のレスポンス例
{ "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 } } -
タスク結果のクエリに対するレスポンス例
URL は 24 時間有効です。速やかに画像をダウンロードしてください。
{ "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
リクエスト例
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 です。base_url はリージョンによって異なります。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:apiKey="sk-xxx"
// API キーはリージョンによって異なります。API キーを取得するには、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 {
/*
* 画像入力方法の説明:
* 以下に 3 つの画像入力方法が提供されています。いずれか 1 つを選択できます。
* 1. パブリック URL を使用 - パブリックにアクセス可能な画像に適しています。
* 2. ローカルファイルを使用 - ローカルでの開発およびテストに適しています。
* 3. Base64 エンコーディングを使用 - プライベート画像を含むシナリオや、暗号化された伝送が必要なシナリオに適しています。
*/
// [方法 1] パブリック画像 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";
// [方法 2] ローカルファイルを使用 (絶対パスと相対パスをサポート)
// 必須フォーマット:file:// + ファイルパス
// String image1 = "file:///path/to/your/car.png";
// String image2 = "file:///path/to/your/paint.png";
// [方法 3] 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", "Spray-paint the graffiti from image 2 onto the car in image 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("Task creation result:");
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();
}
}
レスポンス例
-
タスク作成のレスポンス例
{ "requestId": "ccf4b2f4-bf30-9e13-9461-3a28c6a7bxxx", "output": { "task_id": "8811b4a4-00ac-4aa2-a2fd-017d3b90cxxx", "task_status": "PENDING" }, "status_code": 200, "code": "", "message": "" } -
タスク結果のクエリに対するレスポンス例
URL は 24 時間有効です。速やかに保存してください。
{ "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
ステップ 1:タスクを作成してタスク 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": "Spray-paint the graffiti from image 2 onto the car in image 1"}
]
}
]
},
"parameters": {
"size": "2K",
"n": 1,
"watermark": false
}
}'
レスポンス例
{
"output": {
"task_status": "PENDING",
"task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
},
"request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}ステップ 2:タスク ID で結果をクエリ
前のステップで取得した task_id を使用して、API を通じてタスクステータスをポーリングし、task_status が SUCCEEDED または FAILED になるまで続けます。
{task_id} を、前の API 呼び出しで返された task_id の値に置き換えます。task_id は 24 時間クエリに有効です。
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"レスポンス例
画像 URL は 24 時間有効です。速やかに画像をダウンロードしてください。
{
"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 は、異なる API エンドポイントとパラメーターを使用します。
モデルの選択
wan2.7-image-pro および wan2.7-image (推奨):精密な編集や複数の整合性のある画像の生成に最適です。
精密な局所編集:特定の領域を選択して要素を移動、置換、または追加します。e コマースのレタッチやデザイン調整に最適です。
マルチパネル生成:1 回の呼び出しで複数のスタイルが統一された画像を生成します。コミックの絵コンテや製品シリーズに最適です。
wan2.6-image:テキスト/画像の混合または複数の参照を使用した様式化された編集。画像内にテキストを生成し、最大 4 つの参照画像を受け入れます。
wan2.5-i2i-preview:単純な画像編集やマルチ画像融合に適しています。
デモギャラリー
画像から画像セットへ
入力画像 | 出力画像 |
|
|
|
|
インタラクティブ編集
入力画像 | 出力画像 |
|
画像 1 に基づいて編集します。ボックス 1 で選択されたラズベリーをレモンに、ボックス 2 のラズベリーをイチゴに、ボックス 3 のラズベリーをブルーベリーに置き換えます。結果は元の画像と調和するように統合され、参照ボックスと数字は含めず、残りのコンテンツは変更しないでください。 |
|
画像 1 から選択したパターンを画像 2 の選択した領域に配置します。 |
マルチ画像融合
入力画像 | 出力画像 |
|
画像 1 の少年と画像 2 の犬のポートレートを撮影します。少年は犬を抱きしめており、二人ともとても幸せそうです。スタジオの柔らかな照明、青いテクスチャの背景。 |
|
画像 1 のドレスを画像 2 の鳥の色を使って再配色します。芸術的にしますが、ドレスのスタイルとモデルは変更しないでください。 |
被写体の特徴維持
入力画像 | 出力画像 |
|
「季節の移り変わり」をテーマにしたポラロイド写真 4 枚セットを生成してください。各写真は公園の木の下の同じ場所で撮影されていますが、それぞれ春、夏、秋、冬の風景を示しています。人物の服装も季節に合わせてください:春は薄手のジャケット、夏は半袖シャツ、秋はトレンチコート、冬はマフラーと厚手のコート。この写真セットをダイニングテーブルの上に置いてください。 |
検出とセグメンテーション
入力画像 | 出力画像 |
|
画像内のラップトップと目覚まし時計を検出し、バウンディングボックスを描画し、「laptop」と「clock」とラベル付けします。 |
|
画像内のガラスカップをセグメント化します。 |
要素の抽出
入力画像 | 出力画像 |
|
アップロードされた写真から衣料品を抽出し、純白の背景に平置きで配置します。リアルなディテールと素材の質感を維持します。ファッション e コマーススタイルで、衣料品のディスプレイに適しています。 |
テキスト編集
入力画像 | 出力画像 |
|
画像からすべてのウォーターマークを削除します。 |
|
砂の上に手で「Time for Holiday?」とさりげなく書きます。 |
|
18 を 29 に、JUNE を SEPTEMBER に変更します。 |
カメラと視点の編集
入力画像 | 出力画像 |
|
人物の特徴を変えずに、正面、側面、背面のビューを生成します。 |
|
この写真を魚眼レンズで再撮影します。 |
入力仕様
入力画像の仕様
仕様 | wan2.7-image-pro, wan2.7-image | wan2.6-image | wan2.5-i2i-preview |
入力画像数 | 0 から 9 (0 はテキストからの画像生成モードに対応) | 画像編集:1 から 4 / テキストと画像の混合:0 から 1 | 1 から 3 |
画像フォーマット | JPEG、JPG、PNG (アルファチャンネルは非対応)、BMP、WEBP | JPEG、JPG、PNG (アルファチャンネルは非対応)、BMP、WEBP | JPEG、JPG、PNG (アルファチャンネルは非対応)、BMP、WEBP |
画像の幅と高さの範囲 | [240, 8000] ピクセル | [240, 8000] ピクセル | [384, 5000] ピクセル |
ファイルサイズ | ≤ 20 MB | ≤ 10 MB | ≤ 10 MB |
アスペクト比 | [1:8, 8:1] | 無制限 | [1:4, 4:1] |
画像入力順序
プロンプト内の画像番号は配列の位置に対応します:最初の画像は「画像 1」、2 番目は「画像 2」です。「[image 1]」や「[image 2]」のようなマーカーも使用できます。
{
"content": [
{"text": "編集指示、例:画像 1 の目覚まし時計を画像 2 の食卓の花瓶の隣に置く"},
{"image": "https://example.com/image1.png"},
{"image": "https://example.com/image2.png"}
]
}入力画像 | 出力画像 | ||
画像 1 |
画像 2 |
プロンプト:画像 1 を画像 2 に移動 |
プロンプト:画像 2 を画像 1 に移動 |
画像入力方法
以下のいずれかの方法で画像を渡します:
主な機能
1. 指示追従 (プロンプト)
パラメーター:messages.content.text または input.prompt (必須)、negative_prompt (オプション)。
text または prompt (ポジティブプロンプト):出力画像の内容、被写体、シーン、スタイル、照明、構図を記述します。
negative_prompt (ネガティブプロンプト):「ぼやけた」や「余分な指」など、不要なコンテンツを指定します。
パラメーター | wan2.7-image-pro, wan2.7-image | wan2.6-image | wan2.5-i2i-preview |
text | 必須、最大 5,000 文字 | 必須、最大 2,000 文字 | 非対応 |
prompt | 非対応 | 非対応 | 必須、最大 2,000 文字 |
negative_prompt | 非対応 | 対応、最大 500 文字 | 対応、最大 500 文字 |
2. インテリジェントなプロンプトリライトを有効にする
パラメーター:parameters.prompt_extend (bool, デフォルトは true)。
短いプロンプトを拡張して画質を向上させますが、応答時間が増加します。
ベストプラクティス:
有効にする:プロンプトが簡潔または広範な場合。
無効にする:細かいディテールの制御、詳細な記述、または遅延の影響を受けやすいシナリオの場合。
prompt_extendをfalseに設定します。
パラメーター | wan2.7-image-pro, wan2.7-image | wan2.6-image | wan2.5-i2i-preview |
prompt_extend | 非対応 | 対応 (画像編集モードのみ) | 対応 |
3. 出力画像の解像度を設定する
パラメーター:parameters.size (string)、形式は "width*height" です。
パラメーター | wan2.7-image-pro, wan2.7-image | wan2.6-image | wan2.5-i2i-preview |
size | 方法 1:出力画像の解像度を指定する (推奨) 編集モード (少なくとも 1 つの画像が渡された場合) では、オプションの出力解像度ティアは
方法 2:生成される画像の幅と高さのピクセル値を指定する
テキストからの画像生成シナリオの wan2.7-image-pro のみ 4K 解像度をサポートします。 | 方法 1:入力画像の比率を参照する (推奨) 編集モード (
方法 2:生成される画像の幅と高さのピクセル値を指定する
実際の出力画像のピクセル値は、指定された値に最も近い 16 の倍数になります。 | 生成される画像の幅と高さのピクセル値の指定のみをサポート
|
4. インタラクティブな精密編集
parameters.bbox_list を使用して、編集する特定の領域を選択します。wan2.7-image-pro および wan2.7-image のみでサポートされています。
リストの長さ:入力画像の数と一致する必要があります。編集が不要な画像には空のリスト
[]を使用します。座標形式:
[x1, y1, x2, y2](左上の x、左上の y、右下の x、右下の y)。座標は絶対ピクセル値で、原点 (0, 0) は左上、x 軸は右、y 軸は下です。数量制限:画像ごとに最大 2 つのバウンディングボックス。
例:3 つの入力画像があり、画像 1 には 2 つのバウンディングボックスがあり、画像 2 にはなし
[
[[0, 0, 12, 12], [25, 25, 100, 100]], # 画像 1 (2 つのボックス)
[], # 画像 2 (ボックスなし)
[[10, 10, 50, 50]] # 画像 3 (1 つのボックス)
]課金とレート制限
無料クォータと価格:モデルリストと価格。
レート制限については、通義万相 (Wanxiang) をご参照ください。
課金:
正常に生成された画像ごとに料金が発生します。API が
task_statusをSUCCEEDEDとして返した場合にのみ課金されます。モデルの呼び出しが失敗した場合や処理エラーが発生した場合は、料金は発生せず、無料クォータも消費されません。
API リファレンス
各モデルは異なるエンドポイントとリクエスト構造を使用します:
モデル | エンドポイント (シンガポールリージョンの例) |
| 同期 API: 非同期 API:
|
| 非同期 API:
|
wan2.7/wan2.6では、messagesフォーマットを使用し、messages[].content配列のimageパラメーターでイメージを、textパラメーターでプロンプトを渡します。wan2.5:input.images配列で画像を、input.promptパラメーターでプロンプトを渡します。
wan2.7-image-pro, wan2.7-image, wan2.6-image | wan2.5-i2i-preview |
| |
入出力パラメーターについては、Wan2.7 - 画像生成と編集、Wan2.6 - 画像生成と編集、Wanxiang – 一般画像編集 2.5 をご参照ください。




































