All Products
Search
Document Center

Alibaba Cloud Model Studio:Wan2.7 - Referensi API text-to-video

Last Updated:Jul 02, 2026

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.

Catatan

Kode contoh dalam topik ini menggunakan wilayah Singapura.

Penting

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.com ke https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com

  • Singapura: dari https://dashscope-intl.aliyuncs.com ke https://{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)

Penting

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.

Catatan
  • Setelah tugas dibuat, gunakan task_id yang dikembalikan untuk menanyakan hasilnya. task_id berlaku 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

Kontrol struktur shot dengan bahasa alami dalam prompt. Parameter shot_type tidak berpengaruh.

  • Single shot: Masukkan "Generate a single-shot video".

  • Multi-shot: Masukkan "Generate a multi-shot video" atau jelaskan shot dengan timestamp (misalnya, "Shot 1 [0–3 detik] wide shot: Jalan New York yang hujan di malam hari").

  • Default: Jika tidak ditentukan, model menginterpretasikan konten prompt.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-t2v-2026-06-12",
        "input": {
            "prompt": "A tense detective story with cinematic storytelling. Shot 1 [0–3 seconds] wide shot: Rainy New York street at night, neon lights flicker, a detective in a black trench coat walks briskly. Shot 2 [3–6 seconds] medium shot: The detective enters an old building, rain wets his coat, the door closes slowly behind him. Shot 3 [6–9 seconds] close-up: The detective's focused eyes, distant sirens sound, he frowns slightly. Shot 4 [9–12 seconds] medium shot: The detective moves carefully down a dim hallway, his flashlight illuminating the way. Shot 5 [12–15 seconds] close-up: The detective discovers a key clue, his face shows sudden realization."
        },
        "parameters": {
            "resolution": "720P",
            "ratio": "16:9",
            "prompt_extend": true,
            "watermark": true,
            "duration": 15
        }
    }'

Sediakan file audio

Tentukan URL file audio kustom dalam parameter input.audio_url.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-t2v-2026-06-12",
        "input": {
            "prompt": "An epic and cute scene. A small, adorable cartoon kitten general, wearing exquisitely detailed golden armor and a slightly oversized helmet, stands bravely on a cliff. He rides a small but heroic warhorse and says: 'The long clouds of Qinghai darken the snowy mountains, a lone city gazes at Yumen Pass from afar. Through a hundred battles in the yellow sand, the golden armor is worn, but we will not return until we have broken Loulan'. Below the cliff, a vast and endless army of mice with makeshift weapons is charging forward. This is a dramatic, large-scale battle scene inspired by ancient Chinese war epics. In the distance, dark clouds gather in the sky over the snowy mountains. The overall atmosphere is a comical and epic fusion of 'cute' and 'domineering'.",
            "audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250923/hbiayh/%E4%BB%8E%E5%86%9B%E8%A1%8C.mp3"
        },
        "parameters": {
            "resolution": "1080P",
            "ratio": "16:9",
            "prompt_extend": true,
            "duration": 10
        }
    }'

Dubbing otomatis

Tanpa input.audio_url, model menghasilkan musik latar atau efek suara yang sesuai dengan konten video.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-t2v-2026-06-12",
        "input": {
            "prompt": "An epic and cute scene. A small, adorable cartoon kitten general, wearing exquisitely detailed golden armor and a slightly oversized helmet, stands bravely on a cliff. He rides a small but heroic warhorse and says: 'The long clouds of Qinghai darken the snowy mountains, a lone city gazes at Yumen Pass from afar. Through a hundred battles in the yellow sand, the golden armor is worn, but we will not return until we have broken Loulan'. Below the cliff, a vast and endless army of mice with makeshift weapons is charging forward. This is a dramatic, large-scale battle scene inspired by ancient Chinese war epics. In the distance, dark clouds gather in the sky over the snowy mountains. The overall atmosphere is a comical and epic fusion of 'cute' and 'domineering'."
        },
        "parameters": {
            "resolution": "720P",
            "ratio": "16:9",
            "prompt_extend": true,
            "duration": 10
        }
    }'

Gunakan negative prompt

Gunakan negative_prompt untuk mengecualikan elemen "flower" agar tidak muncul dalam video.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-t2v-2026-06-12",
        "input": {
            "prompt": "A kitten running in the moonlight",
            "negative_prompt": "flower"
        },
        "parameters": {
            "resolution": "720P",
            "ratio": "16:9"
        }
    }'
Header

Content-Type string (Wajib)

Tipe konten permintaan. Harus application/json.

Authorization string (Wajib)

Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx.

X-DashScope-Async string (Wajib)

Mengaktifkan pemrosesan asinkron. Permintaan HTTP hanya mendukung panggilan asinkron. Harus enable.

Penting

Jika header permintaan ini tidak ada, kesalahan "current user api does not support synchronous calls" dikembalikan.

Body permintaan

model string (Wajib)

Nama model. Untuk model dan harga, lihat Harga model.

Contoh: wan2.7-t2v, wan2.7-t2v-2026-06-12.

input object (Wajib)

Data input, termasuk prompt.

Properti

prompt string (Wajib)

Text prompt yang menjelaskan konten dan gaya visual video.

Mendukung bahasa Tionghoa dan Inggris. Setiap karakter atau huruf dihitung sebagai satu. Teks yang melebihi batas dipotong secara otomatis. Panjang maksimum berdasarkan model:

  • wan2.7-t2v, wan2.7-t2v-2026-06-12: Hingga 5.000 karakter.

Contoh: Seekor anak kucing berlari di bawah sinar bulan.

Untuk tips, lihat Panduan prompt text-to-video/image-to-video.

negative_prompt string (Opsional)

Elemen yang ingin dikecualikan dari video yang dihasilkan.

Mendukung bahasa Tionghoa dan Inggris. Maksimal 500 karakter; teks yang lebih panjang dipotong secara otomatis.

Contoh: low resolution, error, worst quality, low quality, deformed, extra fingers, bad proportions.

audio_url string (Opsional)

URL file audio untuk pembuatan video.

Format yang didukung:

  1. URL publik:

    • Protokol HTTP dan HTTPS.

    • Contoh: https://help-static-aliyun-doc.aliyuncs.com/xxx.mp3.

Batasan audio:

  • Format: WAV, MP3.

  • Durasi: 2–30 detik.

  • Ukuran file: Hingga 15 MB.

  • Penanganan durasi: Jika audio melebihi nilai duration (misalnya, 5 detik), hanya 5 detik pertama yang digunakan. Jika audio lebih pendek dari video, sisa video akan senyap. Misalnya, audio 3 detik dengan video 5 detik menghasilkan 3 detik audio diikuti 2 detik senyap.

parameters object (Opsional)

Parameter pembuatan video: resolusi, penulisan ulang prompt, dan watermark.

Properti

resolution string (Opsional)

Penting

Resolusi memengaruhi biaya. Periksa Harga model sebelum memanggil.

Tingkat resolusi video yang dihasilkan. Mengontrol kejernihan output (jumlah total piksel).

  • wan2.7-t2v, wan2.7-t2v-2026-06-12: Nilai valid: 720P, 1080P. Default: 1080P.

ratio string (Opsional)

Rasio aspek video output.

  • 16:9 (default)

  • 9:16

  • 1:1

  • 4:3

  • 3:4

Resolusi output (lebar*tinggi) berdasarkan rasio aspek:

Tingkat resolusi

Rasio aspek

Resolusi video output (lebar*tinggi)

720P

16:9

1280*720

9:16

720*1280

1:1

960*960

4:3

1104*832

3:4

832*1104

1080P

16:9

1920*1080

9:16

1080*1920

1:1

1440*1440

4:3

1648*1248

3:4

1248*1648

duration integer (Opsional)

Penting

Durasi memengaruhi biaya. Penagihan per detik. Periksa Harga model sebelum memanggil.

Durasi video output, dalam detik.

  • wan2.7-t2v, wan2.7-t2v-2026-06-12: Bilangan bulat dari 2 hingga 15. Default: 5.

prompt_extend boolean (Opsional)

Mengaktifkan penulisan ulang prompt. Saat diaktifkan, LLM menulis ulang prompt input untuk meningkatkan kualitas generasi. Terbaik untuk prompt pendek tetapi menambah latensi.

  • true (default)

  • false

watermark boolean (Opsional)

Menambahkan watermark di pojok kanan bawah dengan teks "AI Generated".

  • false (default)

  • true

seed integer (Opsional)

Bilangan acak seed harus berupa bilangan bulat dalam rentang [0, 2147483647].

Jika tidak ditentukan, seed acak dihasilkan. Seed tetap meningkatkan reproduktibilitas.

Karena generasi model bersifat probabilistik, seed yang sama tidak menjamin hasil identik.

Parameter respons

Respons berhasil

Simpan task_id untuk menanyakan status dan hasil tugas.

{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

Respons kesalahan

Pembuatan tugas gagal. Lihat Kode kesalahan.

{
    "code": "InvalidApiKey",
    "message": "No API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}

output object

Output tugas.

Properti

task_id string

ID tugas. Berlaku untuk kueri selama 24 jam.

task_status string

Status tugas.

Nilai enumerasi

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN: Tugas tidak ada atau statusnya tidak diketahui.

request_id string

Identifier permintaan unik untuk pelacakan dan troubleshooting.

code string

Kode kesalahan. Dikembalikan hanya untuk permintaan yang gagal. Lihat Kode kesalahan.

message string

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.

Catatan
  • 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_id masa berlaku: 24 jam. Setelah periode ini, kueri mengembalikan status tugas sebagai UNKNOWN.

Parameter permintaan

Hasil tugas kueri

Ganti {task_id} dengan nilai task_id yang dikembalikan oleh panggilan API sebelumnya. task_id berlaku untuk kueri selama 24 jam.

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

Header

Authorization string (Wajib)

Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx.

Parameter Jalur

task_id string (Wajib)

ID tugas.

Parameter respons

Tugas berhasil dieksekusi

URL video hanya berlaku selama 24 jam, lalu secara otomatis dihapus. Segera simpan video yang dihasilkan.

{
    "request_id": "caa62a12-8841-41a6-8af2-xxxxxx",
    "output": {
        "task_id": "eff1443c-ccab-4676-aad3-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-09-29 14:18:52.331",
        "scheduled_time": "2025-09-29 14:18:59.290",
        "end_time": "2025-09-29 14:23:39.407",
        "orig_prompt": "An epic and cute scene. A small, adorable cartoon kitten general, wearing exquisitely detailed golden armor and a slightly oversized helmet, stands bravely on a cliff. He rides a small but heroic warhorse and says: 'The long clouds of Qinghai darken the snowy mountains, a lone city gazes at Yumen Pass from afar. Through a hundred battles in the yellow sand, the golden armor is worn, but we will not return until we have broken Loulan'. Below the cliff, a vast and endless army of mice with makeshift weapons is charging forward. This is a dramatic, large-scale battle scene inspired by ancient Chinese war epics. In the distance, dark clouds gather in the sky over the snowy mountains. The overall atmosphere is a comical and epic fusion of 'cute' and 'domineering'.",
        "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx"
    },
    "usage": {
        "duration": 10,
        "input_video_duration": 0,
        "output_video_duration": 10,
        "video_count": 1,
        "ratio": "16:9",
        "SR": 720
    }
}

Eksekusi tugas gagal

Saat tugas gagal, task_status bernilai FAILED dan disertai kode serta pesan kesalahan. Lihat Kode Kesalahan.

{
    "request_id": "e5d70b02-ebd3-98ce-9fe8-759d7d7b107d",
    "output": {
        "task_id": "86ecf553-d340-4e21-af6e-a0c6a421c010",
        "task_status": "FAILED",
        "code": "InvalidParameter",
        "message": "The size does not match xxxxxx"
    }
}

Kueri tugas kedaluwarsa

task_id berlaku selama 24 jam. Setelah periode ini, kueri mengembalikan kesalahan berikut.

{
    "request_id": "a4de7c32-7057-9f82-8581-xxxxxx",
    "output": {
        "task_id": "502a00b1-19d9-4839-a82f-xxxxxx",
        "task_status": "UNKNOWN"
    }
}

output object

Output tugas.

Properti

task_id string

ID tugas. Berlaku untuk kueri selama 24 jam.

task_status string

Status tugas.

Nilai enumerasi

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN: Tugas tidak ada atau statusnya tidak diketahui.

Transisi status selama polling:

  • PENDING → RUNNING → SUCCEEDED atau FAILED.

  • Status kueri awal biasanya PENDING atau RUNNING.

  • Saat status berubah menjadi SUCCEEDED, respons berisi URL video yang dihasilkan.

  • Jika status FAILED, periksa pesan kesalahan dan coba ulang tugas.

submit_time string

Waktu saat tugas dikirim. Waktu dalam UTC+8 dan formatnya YYYY-MM-DD HH:mm:ss.SSS.

scheduled_time string

Waktu saat tugas dieksekusi. Waktu dalam UTC+8 dan formatnya YYYY-MM-DD HH:mm:ss.SSS.

end_time string

Waktu saat tugas selesai. Waktu dalam UTC+8 dan formatnya YYYY-MM-DD HH:mm:ss.SSS.

video_url string

URL video yang dihasilkan. Dikembalikan hanya saat task_status bernilai SUCCEEDED.

Berlaku selama 24 jam. Video dalam format MP4 dengan encoding H.264.

orig_prompt string

Prompt input asli, sesuai dengan parameter permintaan prompt.

code string

Kode kesalahan. Dikembalikan hanya untuk permintaan yang gagal. Lihat Kode Kesalahan.

message string

Pesan kesalahan detail. Dikembalikan hanya untuk permintaan yang gagal. Lihat Kode Kesalahan.

usage object

Statistik output. Dikembalikan hanya untuk tugas yang berhasil.

Properti

duration float

Total durasi video, digunakan untuk penagihan.

Sama dengan output_video_duration.

input_video_duration integer

Nilai tetap: 0.

output_video_duration integer

Durasi video output dalam detik. Sesuai dengan nilai input.duration.

SR integer

Tingkat resolusi video output. Contoh: 720.

ratio string

Rasio aspek video output. Contoh: 16:9.

video_count integer

Jumlah video yang dihasilkan. Selalu 1.

request_id string

Identifier permintaan unik untuk pelacakan dan troubleshooting.

HTTP (wan2.6 dan versi sebelumnya)

Penting

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.

Catatan
  • Setelah tugas dibuat, gunakan task_id yang dikembalikan untuk menanyakan hasilnya. task_id berlaku 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

  • Untuk membuat narasi multi-shot, atur shot_type ke "multi".

  • Atur prompt_extend ke true untuk mengaktifkan penulisan ulang prompt demi optimasi storyboard.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.6-t2v",
        "input": {
            "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"
        },
        "parameters": {
            "size": "1280*720",
            "prompt_extend": true,
            "duration": 10,
            "shot_type":"multi"
        }
    }'

Teruskan file audio

Model yang didukung: seri wan2.6 dan wan2.5.

Atur parameter input.audio_url ke URL file audio kustom.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.5-t2v-preview",
        "input": {
            "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"
        },
        "parameters": {
            "size": "832*480",
            "prompt_extend": true,
            "duration": 10
        }
    }'

Dubbing otomatis

Model yang didukung: seri wan2.6 dan wan2.5.

Tanpa parameter input.audio_url, model menghasilkan musik latar atau efek suara yang sesuai dengan konten video.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.5-t2v-preview",
        "input": {
            "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 \""
        },
        "parameters": {
            "size": "832*480",
            "prompt_extend": true,
            "duration": 10
        }
    }'

Hasilkan video tanpa suara

Hanya 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.
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.2-t2v-plus",
        "input": {
            "prompt": "Low contrast. In a retro 1970s-style subway station, a street musician plays amidst dim colors and rough textures. He wears an old-fashioned jacket and holds a guitar, playing with concentration. Commuters hurry past, and a small crowd gradually gathers to listen. The camera slowly pans to the right, capturing a scene where the sound of the instrument mixes with the city's noise, with old-fashioned subway signs and mottled walls in the background."
        },
        "parameters": {
            "size": "832*480",
            "prompt_extend": true
        }
    }'

Gunakan negative prompt

Model yang didukung: Semua model.

Gunakan negative_prompt untuk mengecualikan elemen tertentu (seperti "flowers") dari video yang dihasilkan.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.2-t2v-plus",
        "input": {
            "prompt": "A kitten running in the moonlight",
            "negative_prompt": "flowers"
        },
        "parameters": {
            "size": "832*480"
        }
    }'
Header permintaan

Content-Type string (Wajib)

Tipe konten permintaan. Harus application/json.

Authorization string (Wajib)

Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx.

X-DashScope-Async string (Wajib)

Mengaktifkan pemrosesan asinkron. Permintaan HTTP hanya mendukung panggilan asinkron. Harus enable.

Penting

Jika header permintaan ini tidak ada, kesalahan "current user api does not support synchronous calls" dikembalikan.

Body permintaan

model string (Wajib)

Nama model. Untuk model dan harga, lihat Harga model.

Contoh: wan2.6-t2v.

input object (Wajib)

Data input, termasuk prompt.

Properti

prompt string (Wajib)

Text prompt yang menjelaskan konten dan gaya visual video.

Mendukung bahasa Tionghoa dan Inggris. Setiap karakter atau huruf dihitung sebagai satu. Teks yang melebihi batas dipotong secara otomatis. Panjang maksimum berdasarkan model:

  • Model seri wan2.6 dan wan2.5: Hingga 1.500 karakter.

  • Model seri wan2.2 dan wan2.1: Hingga 800 karakter.

Contoh: Seekor anak kucing berlari di bawah sinar bulan.

Untuk tips, lihat Panduan Prompt Text-to-Video/Image-to-Video.

negative_prompt string (Opsional)

Elemen yang ingin dikecualikan dari video yang dihasilkan.

Mendukung bahasa Tionghoa dan Inggris. Maksimal 500 karakter; teks yang lebih panjang dipotong secara otomatis.

Contoh: low resolution, error, worst quality, low quality, disfigured, extra fingers, bad proportions.

audio_url string (Opsional)

Model yang didukung: seri wan2.6 dan wan2.5.

URL file audio untuk pembuatan video.

Format yang didukung:

  1. URL publik:

    • Protokol HTTP dan HTTPS.

    • Contoh: https://help-static-aliyun-doc.aliyuncs.com/xxx.mp3.

Batasan audio:

  • Format: WAV, MP3.

  • Durasi: 3 detik hingga 30 detik.

  • Ukuran file: Hingga 15 MB.

  • Penanganan durasi: Jika audio melebihi nilai duration (misalnya, 5 detik), hanya 5 detik pertama yang digunakan. Jika audio lebih pendek dari video, sisa video akan senyap. Misalnya, audio 3 detik dengan video 5 detik menghasilkan 3 detik audio diikuti 2 detik senyap.

parameters object (Opsional)

Parameter pembuatan video: resolusi, penulisan ulang prompt, dan watermark.

Properti

size string (Opsional)

Penting
  • Parameter size memengaruhi biaya: Biaya = Harga satuan (berdasarkan resolusi) x Durasi (detik). Untuk model yang sama: 1080p > 720p > 480p. Periksa harga model.

  • Atur size ke resolusi spesifik (seperti 1280*720), bukan rasio aspek (1:1) atau label tingkat (480p).

Resolusi video output dalam format lebar*tinggi. Nilai default dan valid tergantung pada model:

  • wan2.6-t2v: Nilai default 1920*1080 (1080p). Resolusi valid: semua dalam tingkat 720p dan 1080p.

  • wan2.6-t2v-us: Nilai default 1920*1080 (1080p). Resolusi valid: semua dalam tingkat 720p dan 1080p.

  • wan2.5-t2v-preview: Nilai default 1920*1080 (1080p). Resolusi valid: semua dalam tingkat 480p, 720p, dan 1080p.

  • wan2.2-t2v-plus: Nilai default 1920*1080 (1080p). Resolusi valid: semua dalam tingkat 480p dan 1080p.

  • wan2.1-t2v-turbo: Nilai default 1280*720 (720p). Resolusi valid: semua dalam tingkat 480p dan 720p.

  • wan2.1-t2v-plus: Nilai default 1280*720 (720p). Resolusi valid: semua dalam tingkat 720p.

Resolusi dan rasio aspek tingkat 480p:

  • 832*480: 16:9.

  • 480*832: 9:16.

  • 624*624: 1:1.

Resolusi dan rasio aspek tingkat 720p:

  • 1280*720: 16:9.

  • 720*1280: 9:16.

  • 960*960: 1:1.

  • 1088*832: 4:3.

  • 832*1088: 3:4.

Resolusi dan rasio aspek tingkat 1080p:

  • 1920*1080: 16:9.

  • 1080*1920: 9:16.

  • 1440*1440: 1:1.

  • 1632*1248: 4:3.

  • 1248*1632: 3:4.

duration integer (Opsional)

Penting

Durasi memengaruhi biaya: Biaya = Harga satuan (berdasarkan resolusi) x Durasi (detik). Periksa harga model.

Durasi video output dalam detik. Nilai valid tergantung pada model:

  • wan2.6-t2v: Bilangan bulat dari 2 hingga 15. Nilai default 5.

  • wan2.6-t2v-us: Nilai valid 5 dan 10. Nilai default 5.

  • wan2.5-t2v-preview: Nilai valid 5 dan 10. Nilai default 5.

  • wan2.2-t2v-plus: Tetap 5 detik dan tidak dapat diubah.

  • wan2.1-t2v-plus: Tetap 5 detik dan tidak dapat diubah.

  • wan2.1-t2v-turbo: Tetap 5 detik dan tidak dapat diubah.

prompt_extend boolean (Opsional)

Mengaktifkan penulisan ulang prompt. Saat diaktifkan, LLM menulis ulang prompt input untuk meningkatkan kualitas. Terbaik untuk prompt pendek tetapi menambah latensi.

  • true (default)

  • false

shot_type string (Opsional)

Model yang didukung: model wan2.6.

Struktur shot untuk video output: satu shot berkelanjutan atau beberapa shot dengan transisi.

Nilai valid:

  • single (default)

  • multi

Parameter ini hanya berlaku saat "prompt_extend": true diatur.

Prioritas: shot_type menggantikan prompt. Mengatur shot_type ke single menghasilkan video single-shot meskipun prompt meminta multi-shot.

watermark boolean (Opsional)

Menambahkan watermark di pojok kanan bawah dengan teks "AI Generated".

  • false (default)

  • true

seed integer (Opsional)

Bilangan acak seed harus berupa bilangan bulat dalam rentang [0, 2147483647].

Jika tidak ditentukan, seed acak dihasilkan. Seed tetap meningkatkan reproduktibilitas.

Karena generasi model bersifat probabilistik, seed yang sama tidak menjamin hasil identik.

Parameter respons

Respons berhasil

Simpan task_id untuk menanyakan status dan hasil tugas.

{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

Respons kesalahan

Pembuatan tugas gagal. Lihat Kode kesalahan.

{
    "code": "InvalidApiKey",
    "message": "No API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}

output object

Output tugas.

Properti

task_id string

ID tugas. Berlaku untuk kueri selama 24 jam.

task_status string

Status tugas.

Nilai enumerasi

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN: Tugas tidak ada atau statusnya tidak diketahui.

request_id string

Identifier permintaan unik untuk pelacakan dan troubleshooting.

code string

Kode kesalahan. Dikembalikan hanya untuk permintaan yang gagal. Lihat Kode kesalahan.

message string

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.

Catatan
  • 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_id masa berlaku: 24 jam. Setelah periode ini, kueri mengembalikan status tugas sebagai UNKNOWN.

Parameter permintaan

Hasil Tugas Kueri

Ganti {task_id} dengan nilai task_id yang dikembalikan oleh panggilan API sebelumnya. task_id berlaku untuk kueri selama 24 jam.

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

Header

Authorization string (Wajib)

Mengautentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx.

Parameter path

task_id string (Wajib)

ID tugas.

Parameter respons

Tugas berhasil dieksekusi

URL video hanya berlaku selama 24 jam, lalu secara otomatis dihapus. Segera simpan video yang dihasilkan.

{
        "request_id": "abbf7aa3-9652-4785-a622-xxxxxx",
        "output": {
            "task_id": "38513c71-5190-48e1-9f3b-xxxxxx",
            "task_status": "SUCCEEDED",
            "submit_time": "2025-09-29 14:05:22.119",
            "scheduled_time": "2025-09-29 14:05:28.278",
            "end_time": "2025-09-29 14:10:00.437",
            "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'.",
            "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx"
        },
        "usage": {
            "duration": 10,
            "size": "1280*720",
            "input_video_duration": 0,
            "output_video_duration": 10,
            "video_count": 1,
            "SR": 720
        }
    }

Eksekusi tugas gagal

Saat tugas gagal, task_status bernilai FAILED dan disertai kode serta pesan kesalahan. Lihat Kode kesalahan.

{
    "request_id": "e5d70b02-ebd3-98ce-9fe8-759d7d7b107d",
    "output": {
        "task_id": "86ecf553-d340-4e21-af6e-a0c6a421c010",
        "task_status": "FAILED",
        "code": "InvalidParameter",
        "message": "The size is not match xxxxxx"
    }
}

Kueri tugas kedaluwarsa

task_id berlaku selama 24 jam. Setelah periode ini, kueri mengembalikan kesalahan berikut.

{
    "request_id": "a4de7c32-7057-9f82-8581-xxxxxx",
    "output": {
        "task_id": "502a00b1-19d9-4839-a82f-xxxxxx",
        "task_status": "UNKNOWN"
    }
}

output object

Output tugas.

Properti

task_id string

ID tugas. Berlaku untuk kueri selama 24 jam.

task_status string

Status tugas.

Nilai enumerasi

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN: Tugas tidak ada atau statusnya tidak diketahui.

Transisi status selama polling:

  • PENDING → RUNNING → SUCCEEDED atau FAILED.

  • Status kueri awal biasanya PENDING atau RUNNING.

  • Saat status berubah menjadi SUCCEEDED, respons berisi URL video yang dihasilkan.

  • Jika status FAILED, periksa pesan kesalahan dan coba ulang tugas.

submit_time string

Waktu saat tugas dikirim. Waktu dalam UTC+8 dan formatnya YYYY-MM-DD HH:mm:ss.SSS.

scheduled_time string

Waktu saat tugas dieksekusi. Waktu dalam UTC+8 dan formatnya YYYY-MM-DD HH:mm:ss.SSS.

end_time string

Waktu saat tugas selesai. Waktu dalam UTC+8 dan formatnya YYYY-MM-DD HH:mm:ss.SSS.

video_url string

URL video yang dihasilkan. Dikembalikan hanya saat task_status bernilai SUCCEEDED.

Berlaku selama 24 jam. Video dalam format MP4 dengan encoding H.264.

orig_prompt string

Prompt input asli, sesuai dengan parameter permintaan prompt.

actual_prompt string

Saat prompt_extend=true, sistem menulis ulang prompt input. Bidang ini berisi prompt yang ditulis ulang yang digunakan untuk generasi.

  • Tidak dikembalikan saat prompt_extend=false.

  • Model wan2.6 tidak mengembalikan bidang ini, terlepas dari nilai prompt_extend.

code string

Kode kesalahan, yang hanya dikembalikan untuk permintaan yang gagal. Lihat Kode kesalahan.

message string

Pesan kesalahan detail, yang hanya dikembalikan untuk permintaan yang gagal. Lihat Kode kesalahan.

usage object

Statistik penggunaan. Dikembalikan hanya untuk tugas yang berhasil.

Properti

video_duration integer

Dikembalikan hanya untuk wan2.5 dan versi sebelumnya (digunakan untuk penagihan).

Durasi video output dalam detik. Nilai valid: 5, 10.

duration float

Dikembalikan hanya untuk wan2.6 (digunakan untuk penagihan).

Total durasi video. Rumus: duration=input_video_duration+output_video_duration.

input_video_duration integer

Dikembalikan hanya untuk wan2.6. Nilai tetap: 0.

output_video_duration integer

Dikembalikan hanya untuk wan2.6.

Durasi video output dalam detik. Sesuai dengan nilai input.duration.

SR integer

Dikembalikan hanya untuk wan2.6. Tingkat resolusi video output. Contoh: 720.

size string

Dikembalikan hanya untuk wan2.6. Resolusi output dalam format "lebar×tinggi". Contoh: 1920×1080.

video_ratio string

Dikembalikan hanya untuk wan2.5 dan versi sebelumnya. Resolusi output dalam format "lebar×tinggi". Contoh: 832×480.

video_count integer

Jumlah video yang dihasilkan. Selalu 1.

request_id string

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

Penting
  • 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
  1. 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
    }
  2. 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

Penting
  • 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
  1. Contoh respons pembuatan tugas.

    {
            "request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
    	"output": {
    		"task_id": "7277e20e-aa01-4709-xxxxxxxx",
    		"task_status": "PENDING"
    	}
    }
  2. 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 kombinasi resolution (tingkat resolusi) dan ratio (rasio aspek) untuk menentukan resolusi output. Model sebelumnya menggunakan field size.

  • 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.

Kode contoh: Unduh video ke perangkat lokal

import requests

def download_and_save_video(video_url, save_path):
    try:
        response = requests.get(video_url, stream=True, timeout=300)
        response.raise_for_status()
        with open(save_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        print(f"Video successfully downloaded to: {save_path}")
        # Anda dapat menambahkan logika untuk mengunggah video ke penyimpanan permanen di sini
    except requests.exceptions.RequestException as e:
        print(f"Failed to download video: {e}")

if __name__ == '__main__':
    video_url = "http://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxxx"
    save_path = "video.mp4"
    download_and_save_video(video_url, save_path)

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.