Model Wan2.5 – pengeditan gambar umum mengedit gambar berdasarkan prompt teks. Model ini mempertahankan konsistensi subjek selama pengeditan dan mendukung fusi multi-gambar dengan hingga tiga gambar referensi.
Mulai cepat: Panduan pengguna
Ikhtisar model
Fitur | Contoh input | Gambar Keluaran |
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 bunga 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 Model dan harga untuk setiap wilayah.
Prasyarat
Sebelum melakukan panggilan, dapatkan Kunci API dan atur 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. Panggilan lintas-wilayah akan menyebabkan kegagalan autentikasi atau kesalahan layanan.
HTTP
Pengeditan gambar memerlukan waktu untuk diselesaikan. API 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
China (Beijing): POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis
Setelah tugas dibuat, gunakan
task_idyang dikembalikan untuk menanyakan hasilnya. `task_id` berlaku selama 24 jam. Jangan membuat tugas duplikat. Sebagai gantinya, gunakan polling untuk mengambil hasilnya.
Parameter permintaan | Pengeditan gambar tunggal
Fusi multi-gambar
|
Header | |
Content-Type Tipe konten permintaan. Anda harus mengatur parameter ini ke | |
Authorization Kredensial otentikasi. API ini menggunakan Kunci API Model Studio untuk autentikasi. Contoh: `Bearer sk-xxxx`. | |
X-DashScope-Async Parameter ini digunakan untuk mengonfigurasi pemrosesan asinkron. Karena permintaan HTTP hanya mendukung pemrosesan asinkron, Anda harus mengatur parameter ini ke Penting Jika Anda tidak menyertakan header permintaan ini, pesan kesalahan "current user api does not support synchronous calls" akan dikembalikan. | |
Body permintaan | |
model Nama model. Untuk informasi lebih lanjut, lihat Daftar model dan harga. Contoh: wan2.5-i2i-preview. | |
input Konfigurasi input, termasuk prompt dan gambar. | |
parameters Mengontrol resolusi output, penulisan ulang prompt, watermark, dan opsi pemrosesan lainnya. |
Parameter respons | Respons suksesSimpan `task_id` untuk menanyakan status dan hasil tugas. Respons kesalahanPembuatan tugas gagal. Untuk informasi lebih lanjut, lihat Pesan kesalahan untuk menyelesaikan masalah. |
output Informasi output tugas. | |
request_id ID permintaan unik. Anda dapat menggunakan ID ini untuk melacak dan memecahkan masalah. | |
code Kode kesalahan. Parameter ini hanya dikembalikan saat permintaan gagal. Untuk informasi lebih lanjut, lihat Pesan kesalahan. | |
message Pesan kesalahan terperinci. Parameter ini hanya dikembalikan saat permintaan gagal. Untuk informasi lebih lanjut, lihat Pesan kesalahan. |
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 | Kueri hasil tugasGanti Kunci API bersifat spesifik wilayah. Dapatkan Kunci API. Untuk model di wilayah Beijing, ganti base_url dengan https://dashscope.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx |
Header | |
Authorization Kredensial otentikasi. API ini menggunakan Kunci API Model Studio untuk autentikasi. Contoh: `Bearer sk-xxxx`. | |
Parameter path URL | |
task_id ID tugas. |
Parameter respons | Eksekusi tugas berhasilURL gambar hanya disimpan selama 24 jam, lalu secara otomatis dihapus. Anda harus segera menyimpan gambar yang dihasilkan. Eksekusi tugas gagalJika tugas gagal, `task_status` diatur ke FAILED, dan kode serta pesan kesalahan disediakan. Untuk informasi lebih lanjut, lihat Pesan kesalahan untuk menyelesaikan masalah. Kegagalan parsial tugasModel dapat menghasilkan beberapa gambar dalam satu tugas. Jika setidaknya satu gambar berhasil dihasilkan, status tugas ditandai sebagai Kueri tugas kedaluwarsa`task_id` berlaku selama 24 jam. Setelah periode ini, kueri gagal dan mengembalikan pesan kesalahan berikut. |
output Informasi output tugas. | |
usage Statistik penggunaan. Hanya gambar yang berhasil dihasilkan yang dihitung untuk penagihan. | |
request_id ID permintaan unik. Anda dapat menggunakan ID ini untuk melacak dan memecahkan 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.
Python SDK
Pastikan versi SDK Python DashScope Anda adalah 1.25.2 atau lebih baru.
Versi yang lebih lama dapat menyebabkan kesalahan seperti 'url error, please check url!'. Untuk informasi lebih lanjut, lihat Instal atau upgrade SDK.
Panggilan 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 China (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 China (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
}
}
Panggilan 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 China (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 China (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 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 kueri 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 yang lebih lama dapat menyebabkan kesalahan seperti 'url error, please check url!'. Untuk informasi lebih lanjut, lihat Instal atau upgrade SDK.
Panggilan 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 China (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 China (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
}
}Panggilan 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 China (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 China (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 kueri 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 setelahnya.
Moderasi konten: Semua input (prompt dan gambar) serta output dimoderasi secara otomatis. Konten yang tidak sesuai memicu kesalahan `IPInfringementSuspect` atau `DataInspectionFailed`. Untuk informasi lebih lanjut, lihat Kode kesalahan.
Akses jaringan: Tautan gambar disimpan di Object Storage Service (OSS). Jika lingkungan Anda memblokir tautan OSS, tambahkan domain berikut ke daftar izin Anda:
# Daftar nama domain OSS dashscope-result-bj.oss-cn-beijing.aliyuncs.com dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com dashscope-result-sh.oss-cn-shanghai.aliyuncs.com dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com dashscope-result-zjk.oss-cn-zhangjiakou.aliyuncs.com dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com dashscope-result-hy.oss-cn-heyuan.aliyuncs.com dashscope-result-cd.oss-cn-chengdu.aliyuncs.com dashscope-result-gz.oss-cn-guangzhou.aliyuncs.com dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com
Kode kesalahan
Jika panggilan gagal, lihat Pesan kesalahan untuk troubleshooting.
FAQ
T: Saya sedang migrasi dari Wan 2.1. Perubahan API apa saja yang perlu saya ketahui?
J: Perbedaan utama:
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 panggilan model?
J: Metrik penggunaan (jumlah panggilan, tingkat keberhasilan, dll.) muncul di halaman Observasi Model (Singapura), Observasi Model (Beijing) dalam waktu satu jam setelah panggilan API. Untuk petunjuk, lihat Kueri tagihan dan manajemen biaya.



