Model reference-to-video Wan menerima input multimodal dan menghasilkan video interaksi karakter tunggal atau multi-karakter dengan menjadikan orang atau objek sebagai protagonis.
Lihat juga: Panduan pengguna
Ketersediaan
Model, URL endpoint, dan Kunci API harus berada di wilayah yang sama. Pemanggilan lintas wilayah akan gagal.
- Pilih model: Konfirmasi wilayah model tersebut.
- Pilih URL: Gunakan URL endpoint untuk wilayah yang sesuai. URL HTTP didukung.
- Konfigurasikan Kunci API: Pilih wilayah dan Dapatkan Kunci API, lalu Konfigurasikan Kunci API sebagai Variabel lingkungan.
CatatanKode contoh dalam topik ini berlaku untuk wilayah Singapura.
PentingAlibaba Cloud Model Studio telah merilis domain khusus ruang kerja untuk wilayah China (Beijing) dan Singapura. Domain khusus baru ini memberikan performa lebih unggul dan stabilitas lebih tinggi untuk permintaan inferensi. Kami merekomendasikan migrasi ke domain baru:
- China (Beijing): dari
https://dashscope.aliyuncs.comkehttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com - Singapura: dari
https://dashscope-intl.aliyuncs.comkehttps://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
{WorkspaceId} adalah ID ruang kerja Anda, yang dapat ditemukan pada halaman Detail Ruang Kerja di Konsol Alibaba Cloud Model Studio. Domain yang ada tetap berfungsi penuh.
HTTP
PentingIni adalah API lawas yang hanya mendukung model wan2.6.
Tugas generasi video biasanya memerlukan waktu 1–5 menit. API menggunakan panggilan asinkron dua langkah: "buat tugas → polling hasil". Detailnya sebagai berikut:
Langkah 1: Buat tugas
Singapura
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
AS (Virginia)
POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Frankfurt
POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
China (Beijing)
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
Catatan
- Setelah tugas dibuat, gunakan
task_idyang dikembalikan untuk mengkueri hasilnya.task_idberlaku selama 24 jam. Jangan membuat tugas duplikat. Sebagai gantinya, gunakan polling untuk mengambil hasilnya. - Untuk panduan pemula, lihat Panggil API dengan Postman atau cURL.
Parameter permintaanHeaderContent-Type Tipe konten permintaan. Harus Authorization Mengotentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx. X-DashScope-Async Mengaktifkan pemrosesan asinkron. Permintaan HTTP hanya mendukung panggilan asinkron. Harus PentingJika header permintaan ini tidak ada, kesalahan "current user api does not support synchronous calls" akan dikembalikan. Body permintaanmodel Model yang digunakan. Lihat Harga model untuk model yang tersedia dan harganya. Contoh: wan2.6-r2v-flash. input Parameter input seperti prompt. parameters Parameter generasi video seperti resolusi, penulisan ulang prompt, dan watermark. | Interaksi multi-karakter (gambar referensi dan video)Teruskan URL gambar dan video melalui Interaksi multi-karakter (video referensi)Teruskan beberapa URL video melalui Karakter tunggalTeruskan satu URL video melalui Hasilkan video tanpa suaraHanya Untuk menghasilkan video tanpa suara, Anda harus secara eksplisit mengatur |
Parameter responsoutput Output tugas. request_id Pengenal permintaan unik untuk pelacakan dan troubleshooting. code Kode kesalahan. Hanya dikembalikan untuk permintaan yang gagal. Lihat Kode kesalahan. message Pesan kesalahan detail. Hanya dikembalikan untuk permintaan yang gagal. Lihat Kode kesalahan. | Respons berhasilSimpan Respons errorPembuatan tugas gagal. Lihat Kode kesalahan. |
Langkah 2: Ambil hasil tugas
Singapura
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
AS (Virginia)
GET https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
Frankfurt
GET https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
China (Beijing)
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
Catatan
- Rekomendasi polling: Generasi video memerlukan beberapa menit. Gunakan mekanisme polling dengan interval yang wajar, misalnya 15 detik.
- Transisi status tugas: PENDING → RUNNING → SUCCEEDED atau FAILED.
- Tautan hasil: Setelah tugas berhasil, URL video yang berlaku selama 24 jam dikembalikan. Unduh dan simpan video ke penyimpanan permanen, seperti OSS.
task_idmasa berlaku: 24 jam. Setelah periode ini, kueri mengembalikan status tugas sebagaiUNKNOWN.
Parameter permintaanHeaderAuthorization Mengotentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx. Parameter pathtask_id ID tugas. | Ambil hasil tugasGanti |
Parameter responsoutput Output tugas. usage Statistik penggunaan. Hanya menghitung hasil yang berhasil. request_id Pengenal permintaan unik untuk pelacakan dan troubleshooting. | Tugas berhasilURL video hanya berlaku selama 24 jam dan kemudian secara otomatis dihapus. Segera simpan video yang dihasilkan. Tugas gagalSaat tugas gagal, Tugas kedaluwarsa
|
DashScope SDK
Parameter SDK mengikuti konvensi penamaan yang sama dengan API HTTP, dengan wrapper khusus bahasa.
Tugas reference-to-video biasanya memerlukan waktu 1–5 menit. SDK membungkus alur kerja asinkron HTTP dan mendukung panggilan sinkron maupun asinkron.
Waktu pemrosesan aktual bergantung pada antrian tugas dan beban server.
Python
PentingPastikan versi DashScope Python SDK Anda 1.25.16 atau lebih baru sebelum menjalankan kode berikut.
Versi SDK yang usang dapat menyebabkan error seperti "url error, please check url!". Lihat Instal SDK untuk memperbarui.
Atur base_http_api_url berdasarkan wilayah model:
Singapura
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
China (Beijing)
dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1'
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
Frankfurt
dashscope.base_http_api_url = 'https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1'
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
Sinkron
Panggilan sinkron memblokir hingga generasi video selesai dan hasil dikembalikan.
Contoh permintaan
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os
# URL wilayah Singapura. Gunakan URL untuk wilayah Anda.
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# Jika DASHSCOPE_API_KEY tidak diatur, ganti baris berikut dengan: api_key="sk-xxx"
# Kunci API bersifat spesifik wilayah. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_sync_call_r2v():
# Panggilan sinkron: memblokir hingga hasil siap
print('please wait...')
rsp = VideoSynthesis.call(
api_key=api_key,
model='wan2.6-r2v-flash',
prompt='Character2 sits in a chair by the window, holding character3, playing a soothing American country folk song next to character4. Character1 says to Character2: “that sounds great”',
reference_urls=[
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20260205/aacgyk/wan-r2v-role1.mp4",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20260205/mmizqq/wan-r2v-role2.mp4",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png"
],
shot_type='multi',
audio=True,
size='1280*720',
duration=10,
watermark=True)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_sync_call_r2v()
Asinkron
Panggilan asinkron mengembalikan ID tugas segera. Anda harus melakukan polling atau menunggu hingga tugas selesai.
Contoh permintaan
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
# URL wilayah Singapura. Gunakan URL untuk wilayah Anda.
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# Jika DASHSCOPE_API_KEY tidak diatur, ganti baris berikut dengan: api_key="sk-xxx"
# Kunci API bersifat spesifik wilayah. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_async_call_r2v_26():
# Panggilan asinkron: mengembalikan task_id
rsp = VideoSynthesis.async_call(
api_key=api_key,
model='wan2.6-r2v-flash',
prompt='Character2 sits in a chair by the window, holding character3, playing a soothing American country folk song next to character4. Character1 says to Character2: “that sounds great”',
reference_urls=[
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20260205/aacgyk/wan-r2v-role1.mp4",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20260205/mmizqq/wan-r2v-role2.mp4",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png"
],
shot_type='multi',
audio=True,
size='1280*720',
duration=10,
watermark=True)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print("task_id: %s" % rsp.output.task_id)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
# Ambil status tugas
status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
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))
# Tunggu hingga tugas selesai
rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.video_url)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
sample_async_call_r2v_26()
Java
PentingPastikan versi DashScope Java SDK Anda 2.22.14 atau lebih baru sebelum menjalankan kode berikut.
Versi SDK yang usang dapat menyebabkan error seperti "url error, please check url!". Lihat Instal SDK untuk memperbarui.
Atur baseHttpApiUrl berdasarkan wilayah model:
Singapura
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
China (Beijing)
Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
Frankfurt
Constants.baseHttpApiUrl = "https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1";
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
Sinkron
Panggilan sinkron memblokir hingga generasi video selesai dan hasil dikembalikan.
Contoh permintaan
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
import java.util.ArrayList;
import java.util.List;
public class Ref2Video26 {
static {
// URL wilayah Singapura. Gunakan URL untuk wilayah Anda.
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// Jika DASHSCOPE_API_KEY tidak diatur, ganti baris berikut dengan: apiKey="sk-xxx"
// Kunci API bersifat spesifik wilayah. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void ref2video26() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
List<String> referenceUrls = new ArrayList<>();
referenceUrls.add("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20260205/aacgyk/wan-r2v-role1.mp4");
referenceUrls.add("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20260205/mmizqq/wan-r2v-role2.mp4");
referenceUrls.add("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png");
referenceUrls.add("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png");
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-r2v-flash")
.prompt("Character2 sits in a chair by the window, holding character3, playing a soothing American country folk song next to character4. Character1 says to Character2: “that sounds great”")
.referenceUrls(referenceUrls)
.shotType(VideoSynthesis.ShotType.MULTI)
.audio(Boolean.TRUE)
.size("1280*720")
.duration(10)
.watermark(Boolean.TRUE)
.build();
System.out.println("please wait...");
VideoSynthesisResult result = vs.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
ref2video26();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
Asinkron
Panggilan asinkron mengembalikan ID tugas segera. Anda harus melakukan polling atau menunggu hingga tugas selesai.
Contoh permintaan
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisListResult;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
import java.util.ArrayList;
import java.util.List;
public class Ref2Video26Async {
static {
// URL wilayah Singapura. Gunakan URL untuk wilayah Anda.
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// Jika DASHSCOPE_API_KEY tidak diatur, ganti baris berikut dengan: apiKey="sk-xxx"
// Kunci API bersifat spesifik wilayah. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void asyncRef2video26() throws ApiException, NoApiKeyException, InputRequiredException, InterruptedException {
VideoSynthesis vs = new VideoSynthesis();
List<String> referenceUrls = new ArrayList<>();
referenceUrls.add("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20260205/aacgyk/wan-r2v-role1.mp4");
referenceUrls.add("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20260205/mmizqq/wan-r2v-role2.mp4");
referenceUrls.add("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png");
referenceUrls.add("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png");
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-r2v-flash")
.prompt("Character2 sits in a chair by the window, holding character3, playing a soothing American country folk song next to character4. Character1 says to Character2: “that sounds great”")
.referenceUrls(referenceUrls)
.shotType(VideoSynthesis.ShotType.MULTI)
.audio(Boolean.TRUE)
.size("1280*720")
.duration(10)
.watermark(Boolean.TRUE)
.build();
// Kirim tugas asinkron
VideoSynthesisResult result = vs.asyncCall(param);
System.out.println("task_id: " + result.getOutput().getTaskId());
System.out.println(JsonUtils.toJson(result));
// Tunggu hingga tugas selesai
result = vs.wait(result, null);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
asyncRef2video26();
} catch (ApiException | NoApiKeyException | InputRequiredException | InterruptedException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
Kode kesalahan
Jika pemanggilan model gagal dan mengembalikan pesan kesalahan, lihat Kode kesalahan untuk solusinya.