Model pengeditan gambar umum Wan2.5 mengedit gambar berdasarkan prompt teks, mempertahankan konsistensi subjek selama pengeditan, serta mendukung fusi multi-gambar dengan hingga tiga gambar referensi.
Mulai cepat: Pengeditan Gambar – Wan 2.5
Ikhtisar model
Fitur | Contoh input | Gambar output |
Pengeditan gambar tunggal |
|
Ubah gaun bermotif bunga menjadi gaun panjang renda bergaya vintage dengan detail bordir indah pada kerah dan manset. |
Fusi multi-gambar |
|
Letakkan jam alarm dari Gambar 1 di samping vas di atas meja makan pada Gambar 2. |
Model | Deskripsi | Spesifikasi gambar output |
wan2.5-i2i-preview | Pratinjau Wan 2.5 Mendukung pengeditan gambar tunggal dan fusi multi-gambar. | Format gambar: PNG. Resolusi gambar:
|
Sebelum memanggil API ini, tinjau daftar model dan harga untuk setiap wilayah.
Prasyarat
Sebelum melakukan panggilan, dapatkan Kunci API dan ekspor Kunci API sebagai Variabel lingkungan. Untuk melakukan panggilan menggunakan SDK, instal SDK DashScope.
Wilayah Beijing dan Singapura memiliki Kunci API dan titik akhir permintaan yang terpisah. Jangan menggunakannya secara bergantian karena panggilan lintas-wilayah akan menyebabkan kegagalan otentikasi atau kesalahan layanan.
HTTP
Pengeditan gambar memerlukan waktu untuk diselesaikan. API ini menggunakan panggilan asinkron: kirim tugas untuk mendapatkan ID tugas, lalu lakukan polling hingga hasil siap.
Tips: Lakukan polling setiap 5 detik hingga status tugas berubah menjadi SUCCEEDED atau FAILED.
Langkah 1: Kirim tugas dan ambil ID tugas
Singapura: POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis
Beijing: POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis
Setelah tugas dibuat, gunakan
task_idyang dikembalikan untuk menanyakan hasilnya.task_idberlaku selama 24 jam. Jangan membuat tugas duplikat. Sebagai gantinya, gunakan polling untuk mengambil hasilnya.Untuk tutorial pemula, lihat Postman.
Parameter permintaan | Pengeditan gambar tunggal
Fusi multi-gambar
|
Header | |
Content-Type Tipe konten permintaan. Harus berupa | |
Authorization Kredensial otentikasi menggunakan Kunci API Model Studio. Contoh: | |
X-DashScope-Async Mengaktifkan pemrosesan asinkron. Harus diatur ke Penting Mengembalikan kesalahan "current user api does not support synchronous calls" jika tidak disertakan. | |
Body permintaan | |
model Nama model. Untuk informasi lebih lanjut, lihat daftar model dan harga. Contoh: wan2.5-i2i-preview. | |
input Menentukan informasi input dasar, seperti prompt. | |
parameters Mengontrol resolusi output, penulisan ulang prompt, watermark, dan opsi pemrosesan lainnya. |
Parameter respons | Respons suksesSimpan Respons kesalahanPembuatan tugas gagal. Lihat kode kesalahan untuk mengatasi masalah. |
output Informasi output tugas. | |
request_id Pengidentifikasi unik untuk permintaan. Gunakan untuk pelacakan dan troubleshooting masalah. | |
code Kode kesalahan. Hanya dikembalikan ketika permintaan gagal. Lihat kode kesalahan untuk detailnya. | |
message Pesan kesalahan detail. Hanya dikembalikan ketika permintaan gagal. Lihat kode kesalahan untuk detailnya. |
Langkah 2: Lakukan polling untuk hasil menggunakan ID tugas
Singapura: GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}
Beijing: GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
Saran polling: Pembuatan gambar dapat memakan waktu beberapa menit. Kami menyarankan Anda menggunakan mekanisme polling dengan interval permintaan yang wajar, misalnya 10 detik, untuk mengambil hasilnya.
Transisi status tugas: PENDING → RUNNING → SUCCEEDED atau FAILED.
URL hasil: Setelah tugas berhasil, URL gambar dikembalikan. URL tersebut berlaku selama 24 jam. Setelah Anda mengambil URL tersebut, segera unduh dan simpan gambarnya ke layanan penyimpanan permanen, seperti Object Storage Service (OSS).
Parameter permintaan | Hasil Kueri TugasGanti Kunci API bersifat spesifik wilayah. Lihat dokumentasi Kunci API untuk detailnya. Untuk model di wilayah Beijing, ganti base_url dengan |
Header | |
Authorization Kredensial otentikasi menggunakan Kunci API Model Studio. Contoh: | |
Parameter path URL | |
task_id ID tugas yang akan ditanyakan. |
Parameter respons | Eksekusi tugas berhasilURL gambar hanya disimpan selama 24 jam lalu secara otomatis dihapus. Segera simpan gambar yang dihasilkan. Eksekusi tugas gagalKetika tugas gagal, Kegagalan parsial tugasModel dapat menghasilkan beberapa gambar dalam satu tugas. Jika setidaknya satu gambar berhasil dihasilkan, status tugas ditandai sebagai Permintaan tugas kedaluwarsa
|
output Informasi output tugas. | |
usage Statistik output yang dihasilkan. Hanya hasil yang berhasil yang dihitung. | |
request_id Pengidentifikasi unik untuk permintaan. Gunakan untuk pelacakan dan troubleshooting masalah. |
DashScope SDK
Parameter SDK mencerminkan API HTTP, dengan struktur yang disesuaikan dengan konvensi masing-masing bahasa.
Pengeditan gambar memerlukan waktu. SDK menangani polling secara internal dan menawarkan mode panggilan sinkron maupun asinkron.
Waktu pemrosesan tergantung pada kedalaman antrian dan beban layanan. SDK menunggu hasil secara otomatis.
Python SDK
Pastikan versi SDK Python DashScope Anda adalah 1.25.2 atau lebih baru.
Versi sebelumnya dapat menyebabkan kesalahan seperti 'url error, please check url!'. Untuk informasi lebih lanjut, lihat Instal atau upgrade SDK.
Sinkron
Contoh permintaan
Contoh ini menunjukkan tiga cara untuk memberikan gambar input: URL publik, encoding Base64, dan jalur file lokal.
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
# Berikut adalah URL untuk wilayah Singapura. Jika Anda menggunakan model di wilayah Tiongkok (Beijing), ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: api_key="sk-xxx"
# Kunci API untuk wilayah Singapura dan Tiongkok (Beijing) berbeda. Dapatkan Kunci API: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
# --- Input gambar: Gunakan encoding Base64 ---
# Format encoding Base64 adalah 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("Unsupported or unrecognized image format")
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}"
"""
Metode input gambar:
Pilih salah satu dari tiga metode berikut.
1. Gunakan URL publik - Cocok untuk gambar yang dapat diakses publik.
2. Gunakan file lokal - Cocok untuk pengembangan dan pengujian lokal.
3. Gunakan encoding Base64 - Cocok untuk gambar pribadi atau skenario yang memerlukan transmisi terenkripsi.
"""
# [Metode 1] Gunakan URL gambar publik
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"
# [Metode 2] Gunakan file lokal (mendukung jalur absolut dan relatif)
# Persyaratan format: file:// + jalur file
# Contoh (jalur absolut):
# image_url_1 = "file://" + "/path/to/your/image_1.png" # Linux/macOS
# image_url_2 = "file://" + "C:/path/to/your/image_2.png" # Windows
# Contoh (jalur relatif):
# image_url_1 = "file://" + "./image_1.png" # Gunakan jalur aktual Anda
# image_url_2 = "file://" + "./image_2.png" # Gunakan jalur aktual Anda
# [Metode 3] Gunakan gambar yang diencode Base64
# image_url_1 = encode_file("./image_1.png") # Gunakan jalur aktual Anda
# image_url_2 = encode_file("./image_2.png") # Gunakan jalur aktual Anda
print('----sync call, please wait a moment----')
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('response: %s' % rsp)
if rsp.status_code == HTTPStatus.OK:
# Simpan gambar di direktori saat ini
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))Contoh respons
URL kedaluwarsa setelah 24 jam. Unduh gambar segera.
{
"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
}
}
Asinkron
Contoh ini menggunakan URL publik untuk mengirim gambar.
Contoh permintaan
import os
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import dashscope
import requests
from dashscope import ImageSynthesis
# Berikut adalah URL untuk wilayah Singapura. Jika Anda menggunakan model di wilayah Tiongkok (Beijing), ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: api_key="sk-xxx"
# Kunci API untuk wilayah Singapura dan Tiongkok (Beijing) berbeda. Dapatkan Kunci API: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
# Gunakan URL gambar publik
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)
# Buat tugas asinkron
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('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
return rsp
# Tunggu hingga tugas asinkron selesai
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)
# Simpan file ke direktori saat ini
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
# Dapatkan informasi tugas asinkron
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('Failed, status_code: %s, code: %s, message: %s' %
(status.status_code, status.code, status.message))
# Batalkan tugas asinkron. Hanya tugas dalam status PENDING yang dapat dibatalkan.
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('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
async_call()
Contoh respons
1. Contoh respons untuk permintaan pembuatan tugas
{
"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. Contoh respons untuk permintaan penanyakan tugas
URL kedaluwarsa setelah 24 jam. Unduh gambar segera.
{
"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
Pastikan versi SDK Java DashScope Anda adalah 2.22.2 atau lebih baru.
Versi sebelumnya dapat menyebabkan kesalahan seperti 'url error, please check url!'. Untuk informasi lebih lanjut, lihat Instal atau upgrade SDK.
Sinkron
Contoh permintaan
Contoh ini menunjukkan tiga cara untuk memberikan gambar input: URL publik, encoding Base64, dan jalur file lokal.
// 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 {
// Berikut adalah URL untuk wilayah Singapura. Jika Anda menggunakan model di wilayah Tiongkok (Beijing), ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: apiKey="sk-xxx"
// Kunci API untuk wilayah Singapura dan Tiongkok (Beijing) berbeda. Dapatkan Kunci API: https://www.alibabacloud.com/help/en/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* Metode input gambar:
* Pilih salah satu dari tiga metode berikut.
*
* 1. Gunakan URL publik - Cocok untuk gambar yang dapat diakses publik.
* 2. Gunakan file lokal - Cocok untuk pengembangan dan pengujian lokal.
* 3. Gunakan encoding Base64 - Cocok untuk gambar pribadi atau skenario yang memerlukan transmisi terenkripsi.
*/
//[Metode 1] URL Publik
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";
//[Metode 2] Jalur file lokal (file://+jalur absolut atau file:///+jalur absolut)
// 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
//[Metode 3] Encoding Base64
// static String imageUrl_1 = encodeFile("/your/path/to/image_1.png");
// static String imageUrl_2 = encodeFile("/your/path/to/image_2.png");
// Atur daftar gambar yang akan diedit
static List<String> imageUrls = new ArrayList<>();
static {
imageUrls.add(imageUrl_1);
imageUrls.add(imageUrl_2);
}
public static void syncCall() {
// Atur parameter
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("---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));
}
/**
* Mengencode file menjadi string Base64.
* @param filePath Jalur file.
* @return String Base64 dalam format: data:{MIME_type};base64,{base64_data}
*/
public static String encodeFile(String filePath) {
Path path = Paths.get(filePath);
if (!Files.exists(path)) {
throw new IllegalArgumentException("File does not exist: " + filePath);
}
// Deteksi tipe MIME
String mimeType = null;
try {
mimeType = Files.probeContentType(path);
} catch (IOException e) {
throw new IllegalArgumentException("Cannot detect file type: " + filePath);
}
if (mimeType == null || !mimeType.startsWith("image/")) {
throw new IllegalArgumentException("Unsupported or unrecognized image format");
}
// Baca konten file dan encode
byte[] fileBytes = null;
try{
fileBytes = Files.readAllBytes(path);
} catch (IOException e) {
throw new IllegalArgumentException("Cannot read file content: " + filePath);
}
String encodedString = Base64.getEncoder().encodeToString(fileBytes);
return "data:" + mimeType + ";base64," + encodedString;
}
public static void main(String[] args) {
syncCall();
}
}Contoh respons
URL kedaluwarsa setelah 24 jam. Unduh gambar segera.
{
"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
}
}Asinkron
Contoh ini menggunakan URL publik untuk mengirim gambar.
Contoh permintaan
// 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 {
// Berikut adalah URL untuk wilayah Singapura. Jika Anda menggunakan model di wilayah Tiongkok (Beijing), ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: apiKey="sk-xxx"
// Kunci API untuk wilayah Singapura dan Tiongkok (Beijing) berbeda. Dapatkan Kunci API: https://www.alibabacloud.com/help/en/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
//URL Publik
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";
// Atur daftar gambar yang akan diedit
static List<String> imageUrls = new ArrayList<>();
static {
imageUrls.add(imageUrl_1);
imageUrls.add(imageUrl_2);
}
public static void asyncCall() {
// Atur parameter
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("---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();
// Jika Anda telah mengatur DASHSCOPE_API_KEY sebagai variabel lingkungan, Anda dapat mengosongkan apiKey.
ImageSynthesisResult result = is.fetch(taskId, apiKey);
System.out.println(result.getOutput());
System.out.println(result.getUsage());
}
public static void main(String[] args) {
asyncCall();
}
}Contoh respons
1. Contoh respons untuk permintaan pembuatan tugas
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-542f97709ba8",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}2. Contoh respons untuk permintaan penanyakan tugas
URL kedaluwarsa setelah 24 jam. Unduh gambar segera.
{
"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
}
}Batasan
Retensi data: ID tugas dan URL gambar kedaluwarsa setelah 24 jam dan tidak dapat diakses setelah itu.
Moderasi konten: Semua input (prompt dan gambar) serta output dimoderasi secara otomatis. Konten yang tidak memenuhi ketentuan memicu kesalahan `IPInfringementSuspect` atau `DataInspectionFailed`. Lihat Pesan kesalahan.
Kode kesalahan
Jika pemanggilan model gagal dan mengembalikan pesan kesalahan, lihat Pesan kesalahan untuk solusinya.
FAQ
T: Saya sedang migrasi dari Wan2.1. Perubahan API apa saja yang perlu saya ketahui?
J: Penyesuaian diperlukan karena desain parameter berbeda antara kedua versi tersebut.
Wan2.1 – pengeditan gambar umum: Memerlukan parameter
promptdanfunction.Wan2.5 – pengeditan gambar umum: Hanya memerlukan parameter
prompt. Jelaskan semua operasi pengeditan dalam instruksi teks. Parameterfunctionsudah tidak digunakan lagi dan tidak digunakan lagi.
T: Bagaimana cara melihat jumlah pemanggilan model?
J: Metrik penggunaan, seperti jumlah panggilan dan tingkat keberhasilan, muncul di halaman Monitoring (Singapura) atau Monitoring (Beijing) dalam waktu satu jam setelah pemanggilan API. Untuk petunjuknya, lihat Cara melihat catatan pemanggilan model?.



