Model text-to-video Wanxiang menghasilkan video yang mulus berdasarkan text prompts.
Referensi: Panduan pengguna
Cakupan
Untuk memastikan pemanggilan berhasil, pastikan model, URL Endpoint, dan Kunci API berada di wilayah yang sama. Pemanggilan lintas-wilayah akan gagal.
Pilih model: Konfirmasi wilayah model tersebut.
Pilih URL: Gunakan URL Endpoint regional yang sesuai. Baik URL HTTP maupun URL SDK DashScope didukung.
Konfigurasikan Kunci API: Pilih wilayah dan dapatkan Kunci API dan Host API. Kemudian, konfigurasikan Kunci API sebagai Variabel lingkungan (untuk disembunyikan dan digabung ke dalam Konfigurasi Kunci API).
Instal SDK: Jika Anda ingin memanggil API menggunakan SDK, instal SDK DashScope.
Kode contoh dalam topik ini berlaku untuk wilayah Singapura.
Pemanggilan HTTP
Karena tugas text-to-video memerlukan waktu lama—biasanya 1 hingga 5 menit—API menggunakan pemanggilan asinkron. Prosesnya terdiri dari dua langkah utama: Buat tugas → Polling hasil.
Langkah 1: Buat tugas untuk mendapatkan ID tugas
Singapura
POST https://dashscope-intl.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://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-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 | Narasi multi-shotFitur ini hanya didukung oleh model seri wan2.6. Aktifkan fitur ini dengan mengatur Dubbing otomatisFitur ini hanya didukung oleh model seri wan2.6 dan wan2.5. Jika Anda tidak menyediakan Sediakan file audioFitur ini hanya didukung oleh model seri wan2.6 dan wan2.5. Anda dapat menyediakan URL file audio kustom menggunakan parameter Hasilkan video tanpa suaraHanya model seri wan2.2 dan wan2.1 yang mendukung pembuatan video tanpa suara. Video tanpa suara dihasilkan secara default, sehingga tidak diperlukan pengaturan tambahan. Model seri wan2.6 dan wan2.5 menghasilkan video dengan audio secara default. Gunakan negative promptGunakan `negative_prompt` untuk mengecualikan elemen "flower" dan mencegahnya muncul dalam video. |
Header | |
Content-Type Tipe konten permintaan. Harus berupa | |
Authorization Kredensial autentikasi 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 daftar model dan harga, lihat Harga model. Contoh: wan2.6-t2v. | |
input Informasi input dasar, seperti prompt. | |
parameters Parameter pengeditan gambar. Gunakan ini untuk mengatur resolusi video, mengaktifkan penulisan ulang prompt, menambahkan Watermark, dan lainnya. |
Parameter respons | Respons berhasilSimpan Respons kesalahanPembuatan tugas gagal. Lihat kode kesalahan untuk menyelesaikan masalah. |
output Informasi output tugas. | |
request_id Pengidentifikasi unik untuk permintaan, digunakan dalam pelacakan dan pemecahan masalah. | |
code Kode kesalahan. Hanya dikembalikan saat permintaan gagal. Lihat kode kesalahan untuk detailnya. | |
message Pesan kesalahan detail. Hanya dikembalikan saat permintaan gagal. Lihat kode kesalahan untuk detailnya. |
Langkah 2: Tanyakan hasil berdasarkan ID tugas
Singapura
GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}
Virginia
GET https://dashscope-us.aliyuncs.com/api/v1/tasks/{task_id}
Beijing
GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
Saran polling: Pembuatan video dapat memakan waktu beberapa menit. Kami menyarankan Anda menggunakan mekanisme polling dengan interval permintaan yang wajar, misalnya 15 detik, untuk mengambil hasilnya.
Transisi status tugas: PENDING → RUNNING → SUCCEEDED atau FAILED.
URL hasil: Setelah tugas berhasil, URL video dikembalikan. URL tersebut berlaku selama 24 jam. Setelah Anda mendapatkan URL tersebut, segera unduh dan simpan video ke layanan penyimpanan permanen, seperti Object Storage Service (OSS).
Validitas task_id: 24 jam. Setelah periode ini, Anda tidak dapat lagi menanyakan hasilnya, dan API akan mengembalikan status tugas
UNKNOWN.
Parameter permintaan | Hasil Kueri TugasGanti |
Header | |
Authorization Kredensial autentikasi menggunakan Kunci API Model Studio. Contoh: | |
Parameter path | |
task_id ID tugas yang akan ditanyakan. |
Parameter respons | Tugas berhasil dieksekusiURL video hanya disimpan selama 24 jam, lalu secara otomatis dihapus. Segera simpan video yang dihasilkan. Eksekusi tugas gagalSaat tugas gagal, Kueri tugas kedaluwarsa
|
output Informasi output tugas. | |
usage Statistik untuk output. Hanya hasil yang berhasil yang dihitung. | |
request_id Pengidentifikasi unik untuk permintaan. Digunakan untuk pelacakan dan troubleshooting masalah. |
Pemanggilan SDK DashScope
Pemberian nama parameter di SDK sebagian besar konsisten dengan API HTTP. Struktur parameter disesuaikan untuk setiap bahasa pemrograman.
Karena tugas text-to-video memerlukan waktu lama—biasanya 1 hingga 5 menit—SDK merangkum proses pemanggilan asinkron HTTP dan mendukung metode pemanggilan sinkron maupun asinkron.
Waktu aktual yang dibutuhkan bergantung pada jumlah tugas dalam antrian dan status eksekusi layanan.
Memanggil SDK Python
Pastikan versi SDK Python DashScope Anda minimal 1.25.8 sebelum menjalankan kode berikut.
Jika Anda menggunakan versi yang lebih lama, Anda mungkin mengalami kesalahan seperti "url error, please check url!". Untuk memperbarui SDK, lihat Instal SDK.
Atur base_http_api_url berdasarkan wilayah tempat model berada:
Pemanggilan sinkron
Contoh permintaan
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os
# Berikut adalah URL untuk wilayah Singapura. URL untuk wilayah berbeda bervariasi. Untuk mendapatkan URL: https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
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 berbeda bervariasi. Untuk mendapatkan Kunci API: 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 sinkron. Hasil dikembalikan.
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/fox.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 berlaku selama 24 jam. Pastikan mengunduh video dalam periode ini.
{
"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
# Berikut adalah URL untuk wilayah Singapura. URL untuk wilayah berbeda bervariasi. Untuk mendapatkan URL: https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
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 berbeda bervariasi. Untuk mendapatkan Kunci API: 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. Informasi tugas dikembalikan.
# Anda dapat mendapatkan status tugas dengan ID tugas yang dikembalikan.
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/fox.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))
# Dapatkan 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. 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
1. Contoh respons terhadap permintaan 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
}2. Contoh respons terhadap permintaan kueri tugas
video_url berlaku selama 24 jam. Pastikan mengunduh video dalam periode ini.
{
"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 SDK Java
Pastikan versi SDK Java DashScope Anda 2.22.6 atau lebih baru, lalu jalankan kode berikut.
Jika Anda menggunakan versi yang lebih lama, Anda mungkin mengalami kesalahan seperti "url error, please check url!". Untuk memperbarui SDK, lihat Instal SDK.
Atur baseHttpApiUrl berdasarkan wilayah tempat model berada:
Singapura
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
Virginia
Constants.baseHttpApiUrl = "https://dashscope-us.aliyuncs.com/api/v1";
Beijing
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
Panggilan sinkron
Contoh permintaan
// Copyright (c) Alibaba, Inc. and its affiliates.
// dashscope sdk >= 2.18.2
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 {
// Berikut adalah URL untuk wilayah Singapura. URL untuk wilayah berbeda bervariasi. Untuk mendapatkan URL: https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
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 berbeda bervariasi. Untuk mendapatkan Kunci API: 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/fox.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 berlaku selama 24 jam. Pastikan mengunduh video dalam periode ini.
{
"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 {
// Berikut adalah URL untuk wilayah Singapura. URL untuk wilayah berbeda bervariasi. Untuk mendapatkan URL: https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference
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 berbeda bervariasi. Untuk mendapatkan Kunci API: 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/fox.mp3")
.negativePrompt("")
.size("1280*720")
.duration(10)
.parameters(parameters)
.build();
// Panggilan asinkron
VideoSynthesisResult task = vs.asyncCall(param);
System.out.println(JsonUtils.toJson(task));
System.out.println("please wait...");
// Dapatkan hasilnya
VideoSynthesisResult result = vs.wait(task, apiKey);
System.out.println(JsonUtils.toJson(result));
}
// Dapatkan 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);
}
// Dapatkan hasil satu tugas
public static void fetchTask(String taskId) throws ApiException, NoApiKeyException {
VideoSynthesis is = new VideoSynthesis();
// Jika DASHSCOPE_API_KEY diatur sebagai variabel lingkungan, apiKey bisa 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
1. Contoh respons terhadap permintaan pembuatan tugas.
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}2. Contoh respons terhadap permintaan kueri tugas
video_url berlaku selama 24 jam. Pastikan mengunduh video dalam periode ini.
{
"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
Validitas data:
task_iddanvideo_urlhanya disimpan selama 24 jam. Setelah kedaluwarsa, Anda tidak dapat lagi menanyakan atau mengunduhnya.Moderasi konten: Baik konten input maupun video output dikenai moderasi konten. Permintaan yang mengandung konten terlarang akan menghasilkan kesalahan "IPInfringementSuspect" atau "DataInspectionFailed". Untuk informasi lebih lanjut, lihat Pesan kesalahan.
Konfigurasi akses jaringan: Tautan video disimpan di Object Storage Service (OSS). Jika sistem bisnis Anda tidak dapat mengakses tautan OSS eksternal karena kebijakan keamanan, tambahkan nama domain OSS berikut ke daftar putih akses jaringan 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 pemanggilan model gagal dan mengembalikan pesan kesalahan, lihat Pesan kesalahan untuk penyelesaian.
FAQ
T: Bagaimana cara mengonversi tautan video sementara menjadi permanen?
J: Anda tidak dapat mengonversi tautan secara langsung. Metode yang benar adalah layanan backend Anda mengambil URL tersebut, mengunduh file video secara terprogram, lalu mengunggahnya ke layanan penyimpanan objek permanen, seperti OSS Alibaba Cloud, untuk menghasilkan tautan akses permanen baru.
T: Apakah tautan video yang dikembalikan dapat diputar langsung di browser?
J: Hal ini tidak disarankan karena tautan kedaluwarsa setelah 24 jam. Praktik terbaik adalah backend Anda mengunduh dan menyimpan video, lalu menggunakan tautan permanen baru untuk pemutaran.