Wan2.5 – 一般画像編集モデルは、テキストプロンプトを用いて画像を編集します。編集時に被写体の整合性を維持し、最大3枚の参照画像を用いた複数画像融合をサポートします。
クイックスタート: 画像編集 – Wan 2.5
モデル概要
機能 | 入力例 | 出力画像 |
単一画像編集 |
|
花柄のドレスを、襟と袖口に精巧な刺繍が施されたビンテージ風レースのロングドレスに変更します。 |
複数画像融合 |
|
画像 1 の目覚まし時計を、画像 2 のダイニングテーブル上の花瓶の隣に配置します。 |
モデル | 説明 | 出力画像仕様 |
wan2.5-i2i-preview | Wan 2.5 プレビュー 単一画像編集および複数画像融合をサポートします。 | 画像フォーマット:PNG。 画像解像度:
|
この API を呼び出す前に、各リージョンのモデル一覧および課金情報をご確認ください。
前提条件
API を呼び出す前に、API キーを取得し、環境変数として API キーをエクスポートしてください。SDK を使用して呼び出す場合は、DashScope SDK をインストールしてください。
北京リージョンおよびシンガポールリージョンでは、それぞれ専用のAPI キーおよびリクエストエンドポイントが用意されています。これらを混在して使用しないでください。クロスリージョンでの呼び出しは、認証失敗またはサービスエラーを引き起こします。
HTTP
画像編集には処理完了まで時間がかかります。この API は非同期呼び出しを採用しており、タスクを送信してタスク ID を取得した後、結果が準備されるまでポーリングを行います。
ヒント:タスクステータスが「SUCCEEDED」または「FAILED」に遷移するまで、5 秒間隔でポーリングすることを推奨します。
ステップ 1:タスクを送信してタスク ID を取得
シンガポール:POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis
北京:POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis
タスク作成後に、返された
task_idを使用して結果を照会できます。task_idの有効期限は 24 時間です。重複タスクを作成しないでください。代わりに、ポーリングにより結果を取得してください。初心者向けチュートリアルについては、「Postman」をご参照ください。
リクエストパラメーター | 単一画像編集
複数画像融合
|
ヘッダー | |
Content-Type リクエストのコンテンツタイプ。必ず | |
Authorization Model Studio API キーを使用した認証資格情報。 例: | |
X-DashScope-Async 非同期処理を有効化します。HTTP リクエストは非同期処理のみをサポートしているため、必ず 重要 このヘッダーを含めない場合、「current user api does not support synchronous calls」というエラーが返されます。 | |
リクエスト本文 | |
model モデル名。詳細については、「モデル一覧および課金情報」をご参照ください。 例:wan2.5-i2i-preview。 | |
input プロンプトなどの基本的な入力情報を指定します。 | |
parameters 出力解像度、プロンプトの書き換え、ウォーターマーク、その他の処理オプションを制御します。 |
レスポンスパラメーター | 正常終了時のレスポンス
エラー終了時のレスポンスタスク作成に失敗しました。問題を解決するには、「エラーコード」をご参照ください。 |
output タスクの出力情報。 | |
request_id リクエストの一意の識別子。トレースおよびトラブルシューティングに使用します。 | |
code エラーコード。リクエストが失敗した場合にのみ返されます。「エラーコード」をご参照ください。 | |
message 詳細なエラーメッセージ。リクエストが失敗した場合にのみ返されます。「エラーコード」をご参照ください。 |
ステップ 2:タスク ID を使用して結果をポーリング
シンガポール:GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}
北京:GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
ポーリングの推奨事項:画像生成には数分かかることがあります。結果を取得するには、10 秒などの適切なクエリ間隔でポーリング機構を使用することを推奨します。
タスクステータスの遷移:PENDING → RUNNING → SUCCEEDED または FAILED。
結果 URL: タスクが成功すると、イメージ URL が返されます。この URL は 24 時間 有効です。URL を取得した後は、直ちにイメージをダウンロードして、Object Storage Service (OSS) などの永続ストレージサービスに保存する必要があります。
リクエストパラメーター | タスク結果の照会
API キーはリージョンごとに異なります。「API キーのドキュメント」をご参照ください。 北京リージョンのモデルの場合は、base_url を |
ヘッダー | |
Authorization Model Studio API キーを使用した認証資格情報。 例: | |
URL パスパラメーター | |
task_id 照会対象のタスクの ID。 |
レスポンスパラメーター | タスクの正常終了画像 URL は 24 時間のみ保持され、その後自動的にパージされます。生成された画像は速やかに保存してください。 タスクの失敗タスクが失敗した場合、task_status は 部分的なタスク失敗このモデルは、1 回のタスクで複数の画像を生成できます。少なくとも 1 枚の画像が正常に生成された場合、タスクステータスは 有効期限切れのタスク照会
|
output タスクの出力情報。 | |
usage 出力統計が生成されます。成功した結果のみがカウントされます。 | |
request_id リクエストの一意の識別子。トレースおよびトラブルシューティングに使用します。 |
DashScope SDK
SDK のパラメーターはHTTP API と一致し、各プログラミング言語の規則に合わせて構造が調整されています。
画像編集には処理完了まで時間がかかります。SDK は内部でポーリングを処理し、同期および非同期の呼び出しモードの両方を提供します。
処理時間はキューの深さおよびサービス負荷に依存します。SDK は結果を自動的に待機します。
Python SDK
DashScope Python SDK のバージョンが 1.25.2 以降であることを確認してください。
それより古いバージョンでは、「url error, please check url!」などのエラーが発生する可能性があります。詳細については、「SDK のインストールまたはアップグレード」をご参照ください。
同期呼び出し
リクエスト例
この例では、パブリック URL、Base64 エンコーディング、ローカルファイルパスの 3 種類の方法で入力画像を提供する方法を示します。
import base64
import mimetypes
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import dashscope
import requests
from dashscope import ImageSynthesis
import os
# 以下はシンガポールリージョン用の URL です。中国(北京)リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:api_key="sk-xxx"
# シンガポールおよび中国(北京)リージョンの API キーは異なります。API キーの取得方法については、https://www.alibabacloud.com/help/en/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. パブリック URL の使用:パブリックにアクセス可能な画像に適しています。
2. ローカルファイルの使用:ローカル開発およびテストに適しています。
3. Base64 エンコーディングの使用:非公開画像や暗号化された通信が必要なシナリオに適しています。
"""
# [方法 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"
# [方法 2] ローカルファイルの使用(絶対パスおよび相対パスをサポート)
# 形式要件: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" # 実際のパスを指定してください
# [方法 3] Base64 エンコード画像の使用
# image_url_1 = encode_file("./image_1.png") # 実際のパスを指定してください
# image_url_2 = encode_file("./image_2.png") # 実際のパスを指定してください
print('----同期呼び出し中、しばらくお待ちください----')
rsp = ImageSynthesis.call(api_key=api_key,
model="wan2.5-i2i-preview",
prompt="Place the alarm clock from Image 1 next to the vase on the dining table in Image 2.",
images=[image_url_1, image_url_2],
negative_prompt="",
n=1,
# size="1280*1280",
prompt_extend=True,
watermark=False,
seed=12345)
print('レスポンス:%s' % rsp)
if rsp.status_code == HTTPStatus.OK:
# 現在のディレクトリに画像を保存
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('同期呼び出しに失敗しました。status_code:%s、code:%s、message:%s' %
(rsp.status_code, rsp.code, rsp.message))レスポンス例
URL は 24 時間で有効期限切れになります。画像は速やかにダウンロードしてください。
{
"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": "Place the alarm clock from Image 1 next to the vase on the dining table in Image 2.",
"actual_prompt": "Place the blue alarm clock from Image 1 to the right of the vase on the dining table in Image 2, near the edge of the tablecloth. Keep the alarm clock facing the camera, parallel to the table, with its shadow naturally cast on the table."
}
],
"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
}
}
非同期呼び出し
この例では、パブリック URL を使用して画像を渡します。
リクエスト例
import os
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import dashscope
import requests
from dashscope import ImageSynthesis
# 以下はシンガポールリージョン用の URL です。中国(北京)リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:api_key="sk-xxx"
# シンガポールおよび中国(北京)リージョンの API キーは異なります。API キーの取得方法については、https://www.alibabacloud.com/help/en/model-studio/get-api-key をご参照ください。
api_key = os.getenv("DASHSCOPE_API_KEY")
# パブリック画像 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('----タスクを作成----')
task_info = create_async_task()
print('----タスクを待機----')
wait_async_task(task_info)
# 非同期タスクを作成
def create_async_task():
rsp = ImageSynthesis.async_call(api_key=api_key,
model="wan2.5-i2i-preview",
prompt="Place the alarm clock from Image 1 next to the vase on the dining table in Image 2.",
images=[image_url_1, image_url_2],
negative_prompt="",
n=1,
# size="1280*1280",
prompt_extend=True,
watermark=False,
seed=12345)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output)
else:
print('失敗しました。status_code:%s、code:%s、message:%s' %
(rsp.status_code, rsp.code, rsp.message))
return rsp
# 非同期タスクの完了を待機
def wait_async_task(task):
rsp = ImageSynthesis.wait(task=task, api_key=api_key)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output)
# 現在のディレクトリにファイルを保存
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('失敗しました。status_code:%s、code:%s、message:%s' %
(rsp.status_code, rsp.code, rsp.message))
# 非同期タスクの状態を照会
def fetch_task_status(task):
status = ImageSynthesis.fetch(task=task, api_key=api_key)
print(status)
if status.status_code == HTTPStatus.OK:
print(status.output.task_status)
else:
print('失敗しました。status_code:%s、code:%s、message:%s' %
(status.status_code, status.code, status.message))
# 非同期タスクをキャンセル(PENDING ステータスのタスクのみキャンセル可能)
def cancel_task(task):
rsp = ImageSynthesis.cancel(task=task, api_key=api_key)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.task_status)
else:
print('失敗しました。status_code:%s、code:%s、message:%s' %
(rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
async_call()
レスポンス例
1. タスク作成リクエストのレスポンス例
{
"status_code": 200,
"request_id": "31b04171-011c-96bd-ac00-f0383b669cc7",
"code": "",
"message": "",
"output": {
"task_id": "4f90cf14-a34e-4eae-xxxxxxxx",
"task_status": "PENDING",
"results": []
},
"usage": null
}2. タスク照会リクエストのレスポンス例
URL は 24 時間で有効期限切れになります。画像は速やかにダウンロードしてください。
{
"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": "Place the alarm clock from Image 1 next to the vase on the dining table in Image 2.",
"actual_prompt": "Place the blue alarm clock from Image 1 to the right of the vase on the dining table in Image 2, near the edge of the tablecloth. Keep the alarm clock facing the camera, parallel to the table, with its shadow naturally cast on the table."
}
],
"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 SDK
DashScope Java SDK のバージョンが 2.22.2 以降であることを確認してください。
それより古いバージョンでは、「url error, please check url!」などのエラーが発生する可能性があります。詳細については、「SDK のインストールまたはアップグレード」をご参照ください。
同期呼び出し
リクエスト例
この例では、パブリック URL、Base64 エンコーディング、ローカルファイルパスの 3 種類の方法で入力画像を提供する方法を示します。
// 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 です。中国(北京)リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:apiKey="sk-xxx"
// シンガポールおよび中国(北京)リージョンの API キーは異なります。API キーの取得方法については、https://www.alibabacloud.com/help/en/model-studio/get-api-key をご参照ください。
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* 画像入力方法:
* 以下の 3 つの方法のいずれかを選択してください。
*
* 1. パブリック URL の使用:パブリックにアクセス可能な画像に適しています。
* 2. ローカルファイルの使用:ローカル開発およびテストに適しています。
* 3. Base64 エンコーディングの使用:非公開画像や暗号化された通信が必要なシナリオに適しています。
*/
//[方法 1] パブリック 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";
//[方法 2] ローカルファイルパス(file://+絶対パスまたは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
//[方法 3] 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() {
// パラメーターを設定
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("Place the alarm clock from Image 1 next to the vase on the dining table in Image 2.")
.images(imageUrls)
.n(1)
//.size("1280*1280")
.negativePrompt("")
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---同期呼び出し中、しばらくお待ちください----");
result = imageSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
/**
* ファイルを Base64 文字列にエンコードします。
* @param filePath ファイルパス。
* @return MIME_type を含む 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();
}
}レスポンス例
URL は 24 時間で有効期限切れになります。画像は速やかにダウンロードしてください。
{
"request_id": "d362685b-757f-4eac-bab5-xxxxxx",
"output": {
"task_id": "bfa7fc39-3d87-4fa7-b1e6-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"orig_prompt": "Place the alarm clock from Image 1 next to the vase on the dining table in Image 2.",
"actual_prompt": "Place the blue alarm clock from Image 1 to the right of the vase on the dining table in Image 2, near the edge of the tablecloth. Keep the front of the alarm clock facing the camera, parallel to the vase.",
"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
}
}非同期呼び出し
この例では、パブリック URL を使用して画像を渡します。
リクエスト例
// 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 です。中国(北京)リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:apiKey="sk-xxx"
// シンガポールおよび中国(北京)リージョンの API キーは異なります。API キーの取得方法については、https://www.alibabacloud.com/help/en/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() {
// パラメーターを設定
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("Place the alarm clock from Image 1 next to the vase on the dining table in Image 2.")
.images(imageUrls)
.n(1)
//.size("1280*1280")
.negativePrompt("")
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---非同期呼び出し中、しばらくお待ちください----");
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();
}
}レスポンス例
1. タスク作成リクエストのレスポンス例
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-542f97709ba8",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}2. タスク照会リクエストのレスポンス例
URL は 24 時間で有効期限切れになります。画像は速やかにダウンロードしてください。
{
"request_id": "d362685b-757f-4eac-bab5-xxxxxx",
"output": {
"task_id": "bfa7fc39-3d87-4fa7-b1e6-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"orig_prompt": "Place the alarm clock from Image 1 next to the vase on the dining table in Image 2.",
"actual_prompt": "Place the blue alarm clock from Image 1 to the right of the vase on the dining table in Image 2, near the edge of the tablecloth. Keep the front of the alarm clock facing the camera, parallel to the vase.",
"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
}
}制限事項
データ保持期間:タスク ID および画像 URL は 24 時間で有効期限切れとなり、その後はアクセスできなくなります。
コンテンツモデレーション:すべての入力(プロンプトおよび画像)および出力は自動的にモデレーションされます。準拠していないコンテンツは、IPInfringementSuspect または DataInspectionFailed エラーを引き起こします。「エラーメッセージ」をご参照ください。
エラーコード
モデル呼び出しが失敗してエラーメッセージが返された場合、「エラーメッセージ」をご参照ください。
よくある質問
Q:Wan2.1 から移行しています。どのような API 変更点に注意すればよいですか?
A:2 つのバージョン間でパラメーター設計が異なるため、調整が必要です。
Wan2.1 – 一般画像編集:
promptおよびfunctionの両方のパラメーターを指定する必要があります。Wan2.5 – 一般画像編集: 唯一の必須パラメーターは
promptです。すべての編集操作をテキスト命令で記述してください。functionパラメーターは非推奨であり、使用されません。
Q:モデル呼び出し回数を確認するにはどうすればよいですか?
A:呼び出し回数および成功率などの使用状況メトリックは、API 呼び出し後 1 時間以内に、モニタリング(シンガポール) または モニタリング(北京) ページに表示されます。「モデル呼び出し記録の確認方法」をご参照ください。



