Model text-to-video Wan menghasilkan video yang mulus dari text prompts.
Referensi: Panduan pengguna
Ketersediaan
Sesuaikan wilayah model, URL endpoint, dan Kunci API Anda. Panggilan lintas-wilayah akan gagal.
-
Pilih model: Verifikasi ketersediaan model di wilayah target Anda.
-
Pilih URL: Gunakan URL endpoint untuk wilayah yang sesuai. Protokol HTTP dan HTTPS didukung.
-
Konfigurasikan Kunci API: Pilih wilayah, dapatkan Kunci API, dan konfigurasikan dalam Variabel lingkungan.
-
Instal SDK: Untuk memanggil API melalui SDK, instal DashScope SDK.
Kode contoh dalam topik ini menggunakan wilayah Singapura.
Model Studio telah merilis domain khusus ruang kerja untuk wilayah China (Beijing) dan Singapura. Domain khusus baru ini memberikan performa unggul dan stabilitas lebih tinggi untuk permintaan inferensi. Kami menyarankan 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 Model Studio. Domain lama tetap berfungsi penuh.
HTTP (wan2.7)
Antarmuka ini menggunakan protokol baru dan hanya mendukung wan2.7.
Tugas text-to-video memerlukan waktu 1–5 menit. API menggunakan pemanggilan asinkron: Buat tugas → Poll hasilnya.
Langkah 1: Buat tugas
Beijing
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Singapura
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Singapura
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
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.
-
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 panduan pemula, lihat Panggil API dengan Postman atau cURL.
Parameter permintaan |
Narasi multi-shotKontrol struktur shot dengan bahasa alami dalam
Sediakan file audioTentukan URL file audio kustom dalam parameter
Dubbing otomatisTanpa
Gunakan negative promptGunakan negative_prompt untuk mengecualikan elemen "flower" agar tidak muncul dalam video.
|
Header |
|
|
Content-Type Tipe konten permintaan. Harus |
|
|
Authorization Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx. |
|
|
X-DashScope-Async Mengaktifkan pemrosesan asinkron. Permintaan HTTP hanya mendukung panggilan asinkron. Harus Penting
Jika header permintaan ini tidak ada, kesalahan "current user api does not support synchronous calls" dikembalikan. |
|
Body permintaan |
|
|
model Nama model. Untuk model dan harga, lihat Harga model. Contoh: wan2.7-t2v, wan2.7-t2v-2026-06-12. |
|
|
input Data input, termasuk prompt. |
|
|
parameters Parameter pembuatan video: resolusi, penulisan ulang prompt, dan watermark. |
Parameter respons |
Respons berhasilSimpan
Respons kesalahanPembuatan tugas gagal. Lihat Kode kesalahan.
|
|
output Output tugas. |
|
|
request_id Identifier permintaan unik untuk pelacakan dan troubleshooting. |
|
|
code Kode kesalahan. Dikembalikan hanya untuk permintaan yang gagal. Lihat Kode kesalahan. |
|
|
message Pesan kesalahan detail. Dikembalikan hanya untuk permintaan yang gagal. Lihat Kode kesalahan. |
Langkah 2: Tanyakan hasilnya
Beijing
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
Singapura
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
Singapura
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
Beijing
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
-
Rekomendasi polling: Pembuatan video memerlukan beberapa menit. Gunakan mekanisme polling dengan interval yang masuk akal, seperti 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 permintaan |
Hasil tugas kueriGanti |
Header |
|
|
Authorization Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx. |
|
Parameter Jalur |
|
|
task_id ID tugas. |
Parameter respons |
Tugas berhasil dieksekusiURL video hanya berlaku selama 24 jam, lalu secara otomatis dihapus. Segera simpan video yang dihasilkan.
Eksekusi tugas gagalSaat tugas gagal,
Kueri tugas kedaluwarsa
|
|
output Output tugas. |
|
|
usage Statistik output. Dikembalikan hanya untuk tugas yang berhasil. |
|
|
request_id Identifier permintaan unik untuk pelacakan dan troubleshooting. |
HTTP (wan2.6 dan versi sebelumnya)
Antarmuka ini menggunakan protokol lama dan mendukung wan2.6 dan versi sebelumnya (wan2.5/wan2.2/wan2.1).
Tugas text-to-video memerlukan waktu 1–5 menit, sehingga API menggunakan pemanggilan asinkron: Buat tugas → Poll hasilnya.
Langkah 1: Buat tugas
Singapura
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Virginia
POST https://dashscope-us.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Beijing
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Frankfurt
POST https://<u>{WorkspaceId}.eu-central-1.maas.aliyuncs.com/</u>api/v1/services/aigc/video-generation/video-synthesis
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
-
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 panduan pemula, lihat Panggil API dengan Postman atau cURL.
Parameter permintaan |
Narasi multi-shot
Teruskan file audioModel yang didukung: seri wan2.6 dan wan2.5. Atur parameter
Dubbing otomatisModel yang didukung: seri wan2.6 dan wan2.5. Tanpa parameter
Hasilkan video tanpa suaraHanya model seri wan2.2 dan wan2.1 yang mendukung pembuatan video tanpa suara. Model-model ini menghasilkan video tanpa suara secara default tanpa konfigurasi tambahan. Model seri wan2.6 dan wan2.5 menghasilkan video dengan audio secara default.
Gunakan negative promptModel yang didukung: Semua model. Gunakan negative_prompt untuk mengecualikan elemen tertentu (seperti "flowers") dari video yang dihasilkan.
|
Header permintaan |
|
|
Content-Type Tipe konten permintaan. Harus |
|
|
Authorization Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx. |
|
|
X-DashScope-Async Mengaktifkan pemrosesan asinkron. Permintaan HTTP hanya mendukung panggilan asinkron. Harus Penting
Jika header permintaan ini tidak ada, kesalahan "current user api does not support synchronous calls" dikembalikan. |
|
Body permintaan |
|
|
model Nama model. Untuk model dan harga, lihat Harga model. Contoh: wan2.6-t2v. |
|
|
input Data input, termasuk prompt. |
|
|
parameters Parameter pembuatan video: resolusi, penulisan ulang prompt, dan watermark. |
Parameter respons |
Respons berhasilSimpan
Respons kesalahanPembuatan tugas gagal. Lihat Kode kesalahan.
|
|
output Output tugas. |
|
|
request_id Identifier permintaan unik untuk pelacakan dan troubleshooting. |
|
|
code Kode kesalahan. Dikembalikan hanya untuk permintaan yang gagal. Lihat Kode kesalahan. |
|
|
message Pesan kesalahan detail. Dikembalikan hanya untuk permintaan yang gagal. Lihat Kode kesalahan. |
Langkah 2: Tanyakan hasilnya
Singapura
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
Virginia
GET https://dashscope-us.aliyuncs.com/api/v1/tasks/{task_id}
Beijing
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
Frankfurt
GET https://<u>{WorkspaceId}.eu-central-1.maas.aliyuncs.com</u>/api/v1/tasks/{task_id}
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
-
Rekomendasi polling: Pembuatan video memerlukan beberapa menit. Gunakan mekanisme polling dengan interval yang masuk akal, seperti 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 permintaan |
Hasil Tugas KueriGanti |
Header |
|
|
Authorization Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx. |
|
Parameter path |
|
|
task_id ID tugas. |
Parameter respons |
Tugas berhasil dieksekusiURL video hanya berlaku selama 24 jam, lalu secara otomatis dihapus. Segera simpan video yang dihasilkan.
Eksekusi tugas gagalSaat tugas gagal,
Kueri tugas kedaluwarsa
|
|
output Output tugas. |
|
|
usage Statistik penggunaan. Dikembalikan hanya untuk tugas yang berhasil. |
|
|
request_id Identifier permintaan unik untuk pelacakan dan troubleshooting. |
DashScope SDK
Nama parameter SDK sebagian besar sesuai dengan API HTTP, dengan struktur mengikuti konvensi khusus bahasa.
Tugas text-to-video memerlukan waktu 1–5 menit. SDK membungkus alur panggilan HTTP asinkron dan mendukung pemanggilan sinkron maupun asinkron.
Waktu pemrosesan aktual tergantung pada kedalaman antrian dan beban layanan.
Python SDK
-
SDK mendukung wan2.6 dan versi sebelumnya. wan2.7 tidak didukung.
-
Diperlukan versi DashScope Python SDK 1.25.8 atau lebih baru.
Versi lama mungkin mengembalikan "url error, please check url!". Untuk memperbarui, lihat 安装SDK.
Atur dashscope.base_http_api_url ke endpoint wilayah:
Beijing
dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1'
Singapura
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
Virginia
dashscope.base_http_api_url = 'https://dashscope-us.aliyuncs.com/api/v1'
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
Pemanggilan sinkron
Contoh permintaan
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os
# URL wilayah Singapura. URL ini bervariasi tergantung wilayah. Untuk informasi selengkapnya, lihat https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference.
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# Jika variabel lingkungan belum dikonfigurasi, ganti dengan Kunci API Model Studio Anda: api_key="sk-xxx".
# Kunci API bervariasi berdasarkan wilayah. Untuk informasi selengkapnya, lihat https://www.alibabacloud.com/help/en/model-studio/get-api-key.
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_sync_call_t2v():
# Panggil API secara sinkron dan kembalikan hasilnya.
print('Please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
model='wan2.6-t2v',
prompt="Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them.'",
audio_url='https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3',
size='1280*720',
duration=10,
negative_prompt="",
prompt_extend=True,
watermark=False,
seed=12345)
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_t2v()
Contoh respons
video_url kedaluwarsa setelah 24 jam. Unduh segera.
{
"status_code": 200,
"request_id": "167f3beb-3dd0-47fe-a83c-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "5b65411f-d946-4e29-859e-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-bj.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
"submit_time": "2025-10-23 11:47:23.879",
"scheduled_time": "2025-10-23 11:47:34.351",
"end_time": "2025-10-23 11:52:35.323",
"orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective's office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '."
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"size": "1280*720",
"input_video_duration": 0,
"output_video_duration": 10,
"SR": 720
}
}
Pemanggilan asinkron
Contoh permintaan
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os
# Ini adalah URL wilayah Singapura. URL bervariasi berdasarkan wilayah. Untuk informasi lebih lanjut, lihat: https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# Jika variabel lingkungan tidak dikonfigurasi, ganti ini dengan Kunci API Model Studio Anda: api_key="sk-xxx"
# Kunci API bervariasi berdasarkan wilayah. Untuk informasi lebih lanjut, lihat: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_async_call_t2v():
# Panggil API asinkron dan kembalikan informasi tugas.
# Gunakan ID tugas untuk memeriksa statusnya.
rsp = VideoSynthesis.async_call(api_key=api_key,
model='wan2.6-t2v',
prompt="Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.",
audio_url='https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3',
size='1280*720',
duration=10,
negative_prompt="",
prompt_extend=True,
watermark=False,
seed=12345)
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 informasi tugas, termasuk status tugas.
status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
if status.status_code == HTTPStatus.OK:
print(status.output.task_status) # Periksa status tugas.
else:
print('Failed. Status code: %s, code: %s, message: %s' %
(status.status_code, status.code, status.message))
# Tunggu hingga tugas selesai. Metode ini memanggil fetch secara berkala dan memeriksa apakah tugas berada dalam status 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_t2v()
Contoh respons
-
Contoh respons pembuatan tugas
{ "status_code": 200, "request_id": "c86ff7ba-8377-917a-90ed-xxxxxx", "code": "", "message": "", "output": { "task_id": "721164c6-8619-4a35-a6d9-xxxxxx", "task_status": "PENDING", "video_url": "" }, "usage": null } -
Contoh respons kueri tugas
video_url kedaluwarsa setelah 24 jam. Unduh segera.
{ "status_code": 200, "request_id": "167f3beb-3dd0-47fe-a83c-xxxxxx", "code": null, "message": "", "output": { "task_id": "5b65411f-d946-4e29-859e-xxxxxx", "task_status": "SUCCEEDED", "video_url": "https://dashscope-result-bj.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx", "submit_time": "2025-10-23 11:47:23.879", "scheduled_time": "2025-10-23 11:47:34.351", "end_time": "2025-10-23 11:52:35.323", "orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective's office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '." }, "usage": { "video_count": 1, "video_duration": 0, "video_ratio": "", "duration": 10, "size": "1280*720", "input_video_duration": 0, "output_video_duration": 10, "SR": 720 } }
Java SDK
-
SDK mendukung wan2.6 dan versi sebelumnya. wan2.7 tidak didukung.
-
Diperlukan versi DashScope Java SDK 2.22.6 atau lebih baru.
Versi lama mungkin mengembalikan "url error, please check url!". Untuk memperbarui, lihat 安装SDK.
Atur Constants.baseHttpApiUrl ke endpoint wilayah:
Singapura
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
Virginia
Constants.baseHttpApiUrl = "https://dashscope-us.aliyuncs.com/api/v1";
Beijing
Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
Ganti {WorkspaceId} dengan ID ruang kerja aktual Anda.
Pemanggilan sinkron
Contoh permintaan
// Copyright (c) Alibaba, Inc. and its affiliates.
// dashscope SDK versi 2.18.2 atau lebih baru
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.HashMap;
import java.util.Map;
public class Text2Video {
static {
// URL wilayah Singapura. URL bervariasi tergantung wilayah. Untuk informasi selengkapnya, lihat https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference.
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// Jika tidak ada variabel lingkungan yang dikonfigurasi, ganti nilai berikut dengan Kunci API Model Studio Anda: apiKey = "sk-xxx".
// Kunci API bervariasi tergantung wilayah. Untuk informasi selengkapnya, lihat https://www.alibabacloud.com/help/en/model-studio/get-api-key.
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", false);
parameters.put("seed", 12345);
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-t2v")
.prompt("Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them'.")
.audioUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3")
.negativePrompt("")
.size("1280*720")
.duration(10)
.parameters(parameters)
.build();
System.out.println("Please wait...");
VideoSynthesisResult result = vs.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
text2Video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
Contoh respons
video_url kedaluwarsa setelah 24 jam. Unduh segera.
{
"request_id": "c1209113-8437-424f-a386-xxxxxx",
"output": {
"task_id": "966cebcd-dedc-4962-af88-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
"orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '",
"submit_time": "2026-01-22 23:13:40.553",
"scheduled_time": "2026-01-22 23:13:49.415",
"end_time": "2026-01-22 23:17:56.380"
},
"usage": {
"video_count": 1,
"duration": 10.0,
"size": "1280*720",
"input_video_duration": 0.0,
"output_video_duration": 10.0,
"SR": "720"
},
"status_code": 200,
"code": "",
"message": ""
}Pemanggilan asinkron
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.HashMap;
import java.util.Map;
public class Text2Video {
static {
// URL untuk wilayah Singapura. URL bervariasi berdasarkan wilayah. Untuk informasi lebih lanjut, lihat https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// Jika variabel lingkungan tidak diatur, ganti placeholder dengan Kunci API Model Studio Anda, misalnya: apiKey = "sk-xxx"
// Kunci API bervariasi berdasarkan wilayah. Untuk informasi lebih lanjut, lihat https://www.alibabacloud.com/help/en/model-studio/get-api-key
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", false);
parameters.put("seed", 12345);
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.6-t2v")
.prompt("Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.")
.audioUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3")
.negativePrompt("")
.size("1280*720")
.duration(10)
.parameters(parameters)
.build();
// Lakukan panggilan asinkron.
VideoSynthesisResult task = vs.asyncCall(param);
System.out.println(JsonUtils.toJson(task));
System.out.println("please wait...");
// Ambil hasilnya.
VideoSynthesisResult result = vs.wait(task, apiKey);
System.out.println(JsonUtils.toJson(result));
}
// Ambil daftar tugas.
public static void listTask() throws ApiException, NoApiKeyException {
VideoSynthesis is = new VideoSynthesis();
AsyncTaskListParam param = AsyncTaskListParam.builder().build();
param.setApiKey(apiKey);
VideoSynthesisListResult result = is.list(param);
System.out.println(result);
}
// Ambil hasil tugas tunggal.
public static void fetchTask(String taskId) throws ApiException, NoApiKeyException {
VideoSynthesis is = new VideoSynthesis();
// Jika Anda mengatur variabel lingkungan DASHSCOPE_API_KEY, Anda dapat mengatur apiKey ke null.
VideoSynthesisResult result = is.fetch(taskId, apiKey);
System.out.println(result.getOutput());
System.out.println(result.getUsage());
}
public static void main(String[] args) {
try {
text2Video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
Contoh respons
-
Contoh respons pembuatan tugas.
{ "request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx", "output": { "task_id": "7277e20e-aa01-4709-xxxxxxxx", "task_status": "PENDING" } } -
Contoh respons kueri tugas
video_url kedaluwarsa setelah 24 jam. Unduh segera.
{ "request_id": "c1209113-8437-424f-a386-xxxxxx", "output": { "task_id": "966cebcd-dedc-4962-af88-xxxxxx", "task_status": "SUCCEEDED", "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx", "orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '", "submit_time": "2026-01-22 23:13:40.553", "scheduled_time": "2026-01-22 23:13:49.415", "end_time": "2026-01-22 23:17:56.380" }, "usage": { "video_count": 1, "duration": 10.0, "size": "1280*720", "input_video_duration": 0.0, "output_video_duration": 10.0, "SR": "720" }, "status_code": 200, "code": "", "message": "" }
Batasan
-
Retensi data: ID tugas (
task_id) dan URL video (video_url) kedaluwarsa setelah 24 jam. Setelah kedaluwarsa, tidak dapat dikueri atau diunduh. -
Moderasi konten: Input dan output menjalani moderasi konten. Konten terlarang memicu kesalahan "IPInfringementSuspect" atau "DataInspectionFailed". Lihat Kode kesalahan.
Kode kesalahan
Jika pemanggilan model gagal dan mengembalikan pesan kesalahan, lihat Kode kesalahan untuk penyelesaian.
FAQ
P: Perubahan kode apa saja yang diperlukan untuk meningkatkan dari wan2.6 ke wan2.7?
J: Diperlukan dua perubahan:
-
Kontrol resolusi: wan2.7 menggantikan field
size. Sebagai gantinya, menggunakan kombinasiresolution(tingkat resolusi) danratio(rasio aspek) untuk menentukan resolusi output. Model sebelumnya menggunakan fieldsize. -
Penghapusan jenis shot: wan2.7 menghapus field
shot_type. Jelaskan struktur shot langsung dalam prompt sebagai gantinya.
P: Bagaimana cara mengonversi tautan video sementara menjadi tautan permanen?
J: Konversi langsung tidak dimungkinkan. Unduh video dari URL tersebut, lalu unggah ke penyimpanan persisten (seperti OSS Alibaba Cloud) untuk menghasilkan tautan permanen.
P: Apakah tautan video yang dikembalikan dapat diputar langsung di browser?
J: Tidak. Tautan kedaluwarsa setelah 24 jam. Unduh video, simpan secara persisten, dan gunakan tautan permanen untuk pemutaran.