全部產品
Search
文件中心

Alibaba Cloud Model Studio:通義萬相-文生視頻API參考

更新時間:Dec 17, 2025

通義萬相文生視頻模型基於文本提示詞,產生一段流暢的視頻。支援的能力包括:

  • 基礎能力:支援選擇視頻時間長度(5/10/15秒)、指定視頻解析度(480P/720P/1080P)、智能改寫prompt、添加浮水印。

  • 音頻能力:支援自動配音,或傳入自訂音頻檔案,實現聲畫同步。(wan2.5、wan2.6支援)

  • 多鏡頭敘事:支援產生包含多個鏡頭的視頻,在鏡頭切換的同時保持主體一致。(僅wan2.6支援)

快速入口:通義萬相官網線上體驗

說明

通義萬相官網的功能與API支援的能力可能存在差異。本文檔以API的實際能力為準,並會隨功能更新及時同步。

模型概覽

輸入樣本

輸出視頻(wan2.5)

輸入提示詞: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 '.

輸入音頻

前提條件

在調用前,先擷取與配置 API Key,再配置API Key到環境變數(準備下線,併入配置 API Key)。如需通過SDK進行調用,請安裝DashScope SDK

重要

北京和新加坡地區擁有獨立的 API Key 請求地址,不可混用,跨地區調用將導致鑒權失敗或服務報錯。

HTTP調用

由於文生視頻任務耗時較長(通常為1-5分鐘),API採用非同步呼叫。整個流程包含 “建立任務 -> 輪詢擷取” 兩個核心步驟,具體如下:

具體耗時受限於排隊任務數和服務執行情況,請在擷取結果時耐心等待。

步驟1:建立任務擷取任務ID

新加坡地區POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

北京地區POST https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

說明
  • 建立成功後,使用介面返回的 task_id 查詢結果,task_id 有效期間為 24 小時。請勿重複建立任務,輪詢擷取即可。

請求參數

多鏡頭敘事

僅 wan2.6-t2v模型支援此功能。

# 注意:如果使用中國大陸(北京)地區的模型,需要將url替換為:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.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 \""
    },
    "parameters": {
        "size": "1280*720",
        "prompt_extend": true,
        "duration": 10,
        "audio": true,
        "shot_type":"multi"
    }
}'

自動配音

僅 wan2.5 及以上版本模型支援此功能。

模型已預設開啟自動配音功能,無需配置;如需顯式聲明,可將 parameters.audio 參數設定為 true 。

# 注意:如果使用中國大陸(北京)地區的模型,需要將url替換為:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.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,
        "audio": true
    }
}'

傳入音頻檔案

僅 wan2.5 及以上版本模型支援此功能。

可通過 input.audio_url 參數傳入自訂音訊 URL。

# 注意:如果使用中國大陸(北京)地區的模型,需要將url替換為:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.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
    }
}'

產生無聲視頻

參數設定因模型版本而異:

  • wan2.5 及以上版本模型:必須顯式設定 parameters.audio 參數為 false

  • wan2.2 及以下版本模型:預設產生無聲視頻,無需設定任何參數,參考下述代碼。

# 注意:如果使用華北2(北京)地區的模型,需要將url替換為:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.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": "低對比,在一個複古的70年代風格地鐵站裡,街頭音樂家在昏暗的色彩和粗糙的質感中演奏。他穿著舊式夾克,手持吉他,專註地彈奏。通勤者匆匆走過,一小群人漸漸聚攏聆聽。鏡頭慢慢向右移動,捕捉到樂器聲與城市喧囂交織的情境,背景中有老式的地鐵標誌和斑駁的牆面。"
    },
    "parameters": {
        "size": "832*480",
        "prompt_extend": true
    }
}'

使用反向提示詞

通過 negative_prompt 排除“花朵”元素,避免其出現在視頻畫面中。

# 注意:如果使用華北2(北京)地區的模型,需要將url替換為:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.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": "一隻小貓在月光下奔跑",
        "negative_prompt": "花朵"
    },
    "parameters": {
        "size": "832*480"
    }
}'
要求標頭(Headers)

Content-Type string (必選)

請求內容類型。此參數必須設定為application/json

Authorization string(必選)

請求身份認證。介面使用阿里雲百鍊API-Key進行身份認證。樣本值:Bearer sk-xxxx。

X-DashScope-Async string (必選)

非同步處理配置參數。HTTP請求只支援非同步,必須設定為enable

重要

缺少此要求標頭將報錯:“current user api does not support synchronous calls”。

請求體(Request Body)

model string (必選)

模型名稱。模型列表與價格詳見模型價格

樣本值:wan2.5-t2v-preview。

input object (必選)

輸入的基本資料,如提示詞等。

屬性

prompt string (必選)

文本提示詞。用來描述產生視頻中期望包含的元素和視覺特點。

支援中英文,每個漢字/字母佔一個字元,超過部分會自動截斷。長度限制因模型版本而異:

  • wan2.6-t2v:長度不超過1500個字元。

  • wan2.5-t2v-preview:長度不超過1500個字元。

  • wan2.2及以下版本模型:長度不超過800個字元。

樣本值:一隻小貓在月光下奔跑。

提示詞的提示請參見文生視頻/圖生視頻Prompt指南

negative_prompt string (可選)

反向提示詞,用來描述不希望在視頻畫面中看到的內容,可以對視頻畫面進行限制。

支援中英文,長度不超過500個字元,超過部分會自動截斷。

樣本值:低解析度、錯誤、最差品質、低品質、殘缺、多餘的手指、比例不良等。

audio_url string (可選)

支援模型:wan2.6-t2v、 wan2.5-t2v-preview。

音頻檔案URL,模型將使用該音頻產生視頻。使用方法參見設定音頻參數

支援 HTTP 或 HTTPS 協議。

音頻限制:

  • 格式:wav、mp3。

  • 時間長度:3~30s。

  • 檔案大小:不超過15MB。

  • 超限處理:若音頻長度超過 duration 值(5秒或10秒),自動截取前5秒或10秒,其餘部分丟棄。若音頻長度不足視頻時間長度,超出音頻長度部分為無聲視頻。例如,音頻為3秒,視頻時間長度為5秒,輸出視頻前3秒有聲,後2秒無聲。

樣本值:https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/xxx.mp3。

parameters object (可選)

影像處理參數。如設定視頻解析度、開啟prompt智能改寫、添加浮水印等。

屬性

size string (可選)

重要
  • size直接影響費用,費用 = 單價(基於解析度)× 時間長度(秒)。同一模型:1080P > 720P > 480P,請在調用前確認模型價格

  • size必須設定為具體數值(如 1280*720),而不是 1:1或480P。

指定產生的視頻解析度,格式為寬*高。該參數的預設值和可用枚舉值依賴於 model 參數,規則如下:

  • wan2.6-t2v:預設值為 1920*1080(1080P)。可選解析度:720P、1080P對應的所有解析度。

  • wan2.5-t2v-preview:預設值為 1920*1080(1080P)。可選解析度:480P、720P、1080P對應的所有解析度。

  • wan2.2-t2v-plus:預設值為 1920*1080(1080P)。可選解析度:480P、1080P對應的所有解析度。

  • wan2.1-t2v-turbo :預設值為 1280*720(720P)。可選解析度:480P、720P 對應的所有解析度。

  • wan2.1-t2v-plus:預設值為1280*720(720P)。可選解析度:720P 對應的所有解析度。

480P檔位:可選的視頻解析度及其對應的視頻寬高比為:

  • 832*480:16:9。

  • 480*832:9:16。

  • 624*624:1:1。

720P檔位:可選的視頻解析度及其對應的視頻寬高比為:

  • 1280*720:16:9。

  • 720*1280:9:16。

  • 960*960:1:1。

  • 1088*832:4:3。

  • 832*1088:3:4。

1080P檔位:可選的視頻解析度及其對應的視頻寬高比為:

  • 1920*1080: 16:9。

  • 1080*1920: 9:16。

  • 1440*1440: 1:1。

  • 1632*1248: 4:3。

  • 1248*1632: 3:4。

duration integer (可選)

重要

duration直接影響費用。費用 = 單價(基於解析度)× 時間長度(秒),請在調用前確認模型價格

產生視頻的時間長度,單位為秒。該參數的取值依賴於 model參數:

  • wan2.6-t2v:可選值為5、10、15。預設值為5。

  • wan2.5-t2v-preview:可選值為5、10。預設值為5。

  • wan2.2-t2v-plus:固定為5秒,且不支援修改。

  • wan2.1-t2v-plus:固定為5秒,且不支援修改。

  • wan2.1-t2v-turbo:固定為5秒,且不支援修改。

樣本值:5。

prompt_extend boolean (可選)

是否開啟prompt智能改寫。開啟後使用大模型對輸入prompt進行智能改寫。對於較短的prompt產生效果提升明顯,但會增加耗時。

  • true:預設值,開啟智能改寫。

  • false:不開啟智能改寫。

樣本值:true。

shot_type string (可選)

支援模型:wan2.6-t2v。

指定產生視頻的鏡頭類型,即視頻是由一個連續鏡頭還是多個切換鏡頭組成。

生效條件:僅當"prompt_extend": true 時生效。

參數優先順序:shot_type > prompt。例如,若 shot_type設定為"single",即使 prompt 中包含“產生多鏡頭視頻”,模型仍會輸出單鏡頭視頻。

可選值:

  • single:預設值,輸出單鏡頭視頻。

  • multi:輸出多鏡頭視頻。

樣本值:single。

說明

當希望嚴格控制視頻的敘事結構(如產品展示用單鏡頭、故事短片用多鏡頭),可通過此參數指定。

audio boolean (可選)

支援模型:wan2.6-t2v、 wan2.5-t2v-preview。

是否為產生的視頻自動添加音頻。

生效條件:僅在不傳入 audio_url時生效。

參數優先順序:audio_url > audio。使用方式參見設定音頻參數

可選值:

  • true:預設值,表示自動添加音頻,輸出有聲視頻。

  • false:表示不添加音頻,輸出無聲視頻。

樣本值:true。

說明

若希望產生純視覺內容(如特效示範、無聲動畫),請顯式設定 "audio": false。若需自訂配音,請使用 audio_url 而非此參數。

watermark boolean (可選)

是否添加浮水印標識,浮水印位於視頻右下角,文案固定為“AI產生”。

  • false:預設值,不添加浮水印。

  • true:添加浮水印。

樣本值:false。

seed integer (可選)

隨機數種子,取值範圍為[0, 2147483647]

未指定時,系統自動產生隨機種子。若需提升產生結果的可複現性,建議固定seed值。

請注意,由於模型產生具有機率性,即使使用相同 seed,也不能保證每次產生結果完全一致。

樣本值:12345。

響應參數

成功響應

請儲存 task_id,用於查詢任務狀態與結果。

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

異常響應

建立任務失敗,請參見錯誤資訊進行解決。

{
    "code":"InvalidApiKey",
    "message":"Invalid API-key provided.",
    "request_id":"fb53c4ec-1c12-4fc4-a580-xxxxxx"
}

output object

任務輸出資訊。

屬性

task_id string

任務ID。查詢有效期間24小時。

task_status string

任務狀態。

枚舉值

  • PENDING:任務排隊中

  • RUNNING:任務處理中

  • SUCCEEDED:任務執行成功

  • FAILED:任務執行失敗

  • CANCELED:任務已取消

  • UNKNOWN:任務不存在或狀態未知

request_id string

請求唯一標識。可用於請求明細溯源和問題排查。

code string

請求失敗的錯誤碼。請求成功時不會返回此參數,詳情請參見錯誤資訊

message string

請求失敗的詳細資料。請求成功時不會返回此參數,詳情請參見錯誤資訊

步驟2:根據任務ID查詢結果

新加坡地區GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}

北京地區GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}

說明
  • 輪詢建議:視頻產生過程約需數分鐘,建議採用輪詢機制,並設定合理的查詢間隔(如 15 秒)來擷取結果。

  • 任務狀態流轉:PENDING(排隊中)→ RUNNING(處理中)→ SUCCEEDED(成功)/ FAILED(失敗)。

  • 結果連結:任務成功後返回視頻連結,有效期間為 24 小時。建議在擷取連結後立即下載並轉存至永久儲存(如阿里雲 OSS)。

  • task_id 有效期間24小時,逾時後將無法查詢結果,介面將返回任務狀態為UNKNOWN

請求參數

查詢任務結果

請將86ecf553-d340-4e21-xxxxxxxxx替換為真實的task_id。

新加坡和北京地區的API Key不同。擷取與配置 API Key
以下為新加坡地區base_url,若使用北京地區的模型,需將base_url替換為https://dashscope.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

要求標頭(Headers)

Authorization string(必選)

請求身份認證。介面使用阿里雲百鍊API-Key進行身份認證。樣本值:Bearer sk-xxxx。

URL路徑參數(Path parameters)

task_id string(必選)

任務ID。

響應參數

任務執行成功

視頻URL僅保留24小時,逾時後會被自動清除,請及時儲存產生的視頻。

{
    "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
    }
}

任務執行失敗

若任務執行失敗,task_status將置為 FAILED,並提供錯誤碼和資訊。請參見錯誤資訊進行解決。

{
    "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"
    }
}

任務查詢到期

task_id查詢有效期間為 24 小時,逾時後將無法查詢,返回以下報錯資訊。

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

output object

任務輸出資訊。

屬性

task_id string(必選)

任務ID。

task_status string

任務狀態。

枚舉值

  • PENDING:任務排隊中

  • RUNNING:任務處理中

  • SUCCEEDED:任務執行成功

  • FAILED:任務執行失敗

  • CANCELED:任務已取消

  • UNKNOWN:任務不存在或狀態未知

submit_time string

任務提交時間。時區為UTC+8,格式為 YYYY-MM-DD HH:mm:ss.SSS。

scheduled_time string

任務執行時間。時區為UTC+8,格式為 YYYY-MM-DD HH:mm:ss.SSS。

end_time string

任務完成時間。時區為UTC+8,格式為 YYYY-MM-DD HH:mm:ss.SSS。

video_url string

視頻URL。僅在 task_status 為 SUCCEEDED 時返回。

連結有效期間24小時,可通過此URL下載視頻。視頻格式為MP4(H.264 編碼)。

orig_prompt string

原始輸入的prompt,對應請求參數prompt

actual_prompt string

prompt_extend=true 時,系統會對輸入 prompt 進行智能改寫,此欄位返回實際用於產生的最佳化後 prompt。

  • prompt_extend=false,該欄位不會返回。

  • 注意:wan2.6 模型無論 prompt_extend 取值如何,均不返回此欄位。

code string

請求失敗的錯誤碼。請求成功時不會返回此參數,詳情請參見錯誤資訊

message string

請求失敗的詳細資料。請求成功時不會返回此參數,詳情請參見錯誤資訊

usage object

輸出資訊統計。只對成功的結果計數。

屬性

video_duration integer

僅在使用 wan2.5 及以下版本模型時返回,用於計費。

產生視頻的時間長度,單位秒。枚舉值為5、10。

input_video_duration integer

僅在使用 wan2.6 模型時返回。固定為0。

output_video_duration integer

僅在使用 wan2.6 模型時返回。

輸出視頻的時間長度,單位秒。其值等同於input.duration的值。

duration float

僅在使用 wan2.6 模型時返回,用於計費。

表示總的視頻時間長度,且duration=input_video_duration+output_video_duration

SR integer

僅在使用 wan2.6 模型時返回。產生視頻的解析度檔位。樣本值:720。

video_ratio string

產生視頻的解析度。其值等同於parameters.size的值。

格式為“寬*高,樣本值:1920*1080。

video_count integer

產生視頻的數量。固定為1。

request_id string

請求唯一標識。可用於請求明細溯源和問題排查。

DashScope SDK調用

SDK 的參數命名與HTTP介面基本一致,參數結構根據語言特性進行封裝。

由於文生視頻任務耗時較長(通常為1-5分鐘),SDK 在底層封裝了 HTTP 非同步呼叫流程,支援同步、非同步兩種調用方式。

具體耗時受限於排隊任務數和服務執行情況,請在擷取結果時耐心等待。

Python SDK調用

重要
  • wan2.6-t2v模型暫不支援SDK調用。

  • 請確保 DashScope Python SDK 版本不低於 1.25.2,再運行以下代碼。

    若版本過低,可能會觸發 “url error, please check url!” 等錯誤。請參考安裝SDK進行更新。

同步調用

請求樣本
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# 如果使用華北2(北京)地區的模型,需要將url替換為:https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 新加坡和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

def sample_sync_call_t2v():
    # call sync api, will return the result
    print('please wait...')
    rsp = VideoSynthesis.call(api_key=api_key,
                              model='wan2.5-t2v-preview',
                              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='832*480',
                              duration=10,
                              negative_prompt="",
                              # audio=True,
                              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()
響應樣本
video_url 有效期間24小時,請及時下載視頻。
{
    "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 '。",
        "actual_prompt": "Low-angle shot, medium close-up, warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, 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 crimson fur contrasting with the dimly lit room. Its tail rests lightly on the edge of the chair, and its fingers slowly turn yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. The fox slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera. Its mouth clearly moves 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": 10,
        "video_ratio": "832*480"
    }
}

非同步呼叫

請求樣本
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# 如果使用華北2(北京)地區的模型,需要將url替換為:https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 新加坡和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

def sample_async_call_t2v():
    # call async api, will return the task information
    # you can get task status with the returned task id.
    rsp = VideoSynthesis.async_call(api_key=api_key,
                                    model='wan2.5-t2v-preview',
                                    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='832*480',
                                    duration=10,
                                    negative_prompt="",
                                    # audio=True,
                                    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))
                           
    # get the task information include the task status.
    status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
    if status.status_code == HTTPStatus.OK:
        print(status.output.task_status)  # check the task status
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (status.status_code, status.code, status.message))

    # wait the task complete, will call fetch interval, and check it's in finished status.
    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()
響應樣本

1、建立任務的響應樣本

{
	"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、查詢任務結果的響應樣本

video_url 有效期間24小時,請及時下載視頻。
{
    "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 '。",
        "actual_prompt": "Low-angle shot, medium close-up, warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, 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 crimson fur contrasting with the dimly lit room. Its tail rests lightly on the edge of the chair, and its fingers slowly turn yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. The fox slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera. Its mouth clearly moves 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": 10,
        "video_ratio": "832*480"
    }
}

Java SDK調用

重要
  • wan2.6-t2v模型暫不支援SDK調用。

  • 請確保 DashScope Java SDK 版本不低於 2.22.2,再運行以下代碼。

    若版本過低,可能會觸發 “url error, please check url!” 等錯誤。請參考安裝SDK進行更新。

同步調用

請求樣本
// 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 {
    /**
     * Create a video compositing task and wait for the task to complete.
     */
    static {
     Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
     // 如果使用華北2(北京)地區的模型,需要將url替換為:https://dashscope.aliyuncs.com/api/v1
    }
    
    // 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
    // 新加坡和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/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.5-t2v-preview")
                        .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("832*480")
                        .duration(10)
                        // .audio(true)
                        .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);
    }
}
響應樣本
video_url 有效期間24小時,請及時下載視頻。
{
    "request_id": "4e9aab26-c50b-4ea7-b2c0-xxxxxx",
    "output": {
        "task_id": "9e0fc846-ee92-42ac-af42-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx"
    },
    "usage": {
        "video_count": 1,
        "video_duration": 10,
        "video_ratio": "832*480"
    }
}

非同步呼叫

請求樣本
// 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 {
    /**
     * Create a video compositing task and wait for the task to complete.
     */
    static {
        // 如果使用華北2(北京)地區的模型,需要將url替換為:https://dashscope.aliyuncs.com/api/v1
        Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
    }

     // 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
    // 新加坡和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/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.5-t2v-preview")
                        .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("832*480")
                        .duration(10)
                        // .audio(true)
                        .parameters(parameters)
                        .build();

        // 非同步呼叫
        VideoSynthesisResult task = vs.asyncCall(param);
        System.out.println(JsonUtils.toJson(task));
        System.out.println("please wait...");

        //擷取結果
        VideoSynthesisResult result = vs.wait(task, apiKey);
        System.out.println(JsonUtils.toJson(result));
    }

     // 擷取工作清單
    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);
    }

    // 擷取單個任務結果
    public static void fetchTask(String taskId) throws ApiException, NoApiKeyException {
        VideoSynthesis is = new VideoSynthesis();
        // 如果已設定 DASHSCOPE_API_KEY 為環境變數,apiKey 可為空白
        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);
    }
}
響應樣本

1、建立任務的響應樣本。

{
        "request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
	"output": {
		"task_id": "7277e20e-aa01-4709-xxxxxxxx",
		"task_status": "PENDING"
	}
}

2、查詢任務結果的響應樣本

video_url 有效期間24小時,請及時下載視頻。
{
    "request_id": "4e9aab26-c50b-4ea7-b2c0-xxxxxx",
    "output": {
        "task_id": "9e0fc846-ee92-42ac-af42-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx"
    },
    "usage": {
        "video_count": 1,
        "video_duration": 10,
        "video_ratio": "832*480"
    }
}

使用限制

  • 資料時效:任務task_id和 視頻url均只保留 24 小時,到期後將無法查詢或下載。

  • 音頻支援:wan2.5 支援有聲視頻(自動配音或上傳自訂音頻)。wan2.2 及早期版本僅輸出無聲視頻,如有需要,可通過語音合成產生音頻。

  • 內容審核:輸入的 prompt 和輸出的視頻均會經過Alibaba Content Security Service審核,包含違規內容的請求將報錯“IPInfringementSuspect”或“DataInspectionFailed”,具體參見錯誤資訊

  • 網路訪問配置:視頻連結儲存於阿里雲 OSS,如果業務系統因安全性原則無法訪問外部OSS連結,請將以下 OSS 網域名稱加入網路訪問白名單。

    # 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

關鍵參數說明

設定音頻參數

支援的模型:wan2.6-t2v,wan2.5-t2v-preview。

音頻設定:通過input.audio_url和 parameters.audio參數組合控制音頻行為,參數優先順序:audio_url > audio。支援三種模式:

  1. 產生無聲視頻

    1. 參數設定:不傳audio_url,且 audio 為 false。

    2. 適用情境:純視覺內容展示,後期自行添加音頻或配樂。

  2. 自動產生音頻

    1. 參數設定:不傳audio_url,且 audio 為 true。

    2. 效果說明:模型根據提示詞和畫面內容,自動產生匹配的背景音頻或音樂。

  3. 使用自訂音頻

    1. 參數設定:傳入 audio_url(此時 audio參數無效)。

    2. 效果說明:視頻畫面會嘗試與音頻內容對齊(如口型、節奏等)。

計費與限流

  • 模型免費額度和計費單價請參見模型列表與價格

  • 模型限流請參見通義萬相系列

  • 計費說明:

    • 按成功產生的 視頻秒數 計費。僅當查詢結果介面返回task_statusSUCCEEDED 並成功產生視頻後,才會計費。

    • 模型調用失敗或處理錯誤不產生任何費用,也不消耗免費額度

錯誤碼

如果模型調用失敗並返回報錯資訊,請參見錯誤資訊進行解決。

常見問題

Q: 如何查看模型調用量?

A: 模型調用完一小時後,請在模型觀測(新加坡)模型觀測(北京)頁面,查看模型的調用次數、成功率等指標。如何查看模型調用記錄?

Q: 如何將臨時的視頻連結轉為永久連結?

A: 不能直接轉換該連結。正確的做法是:後端服務擷取到url後,通過代碼下載該視頻檔案,然後將其上傳到永久Object Storage Service服務(如阿里雲 OSS),產生一個新的、永久訪問連結。

範例程式碼:下載視頻到本地

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() # 如果HTTP狀態代碼不是200,則引發異常
        with open(save_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        print(f"視頻已成功下載到: {save_path}")
        # 此處可以接上傳到永久儲存的邏輯
    except requests.exceptions.RequestException as e:
        print(f"下載視頻失敗: {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)

Q: 返回的視頻連結可以在瀏覽器中直接播放嗎?

A: 不建議這樣做,因為連結會在 24 小時後失效。最佳實務是後端下載轉存後,使用永久連結進行視頻播放。