請求參數 請求頭(Headers) Content-Typestring(必選) 請求內容類型。此參數必須設定為application/json。 Authorizationstring(必選) 請求身份認證。介面使用阿里雲百鍊API Key進行身份認證。示例值:Bearer sk-xxxx。 X-DashScope-Asyncstring(必選) 非同步處理設定參數。HTTP請求只支援非同步,必須設定為enable。 重要缺少此請求頭將報錯:“current user api does not support synchronous calls”。 請求體(Request Body) model string (必選) 模型名稱。模型輸出規格請參見模型列表。 可選值: input object (必選) 輸入的基本資訊,包括參考圖片和提示詞。 屬性 prompt string (必選) 文本提示詞。用來描述生成視頻中期望包含的元素和視覺特點。 支援中英文,每個漢字/字母佔一個字符,字符編碼為UTF-8,超過部分會自動截斷。
- pixverse/pixverse-v6-r2v:不超過2048個字符。
圖片引用說明:當在 media 參數中傳入參考圖時,可以通過 @ref_name在prompt中直接引用該圖片。
- media 中設定的 ref_name 在同一請求內必須全局唯一,且須與 prompt 中的引用一一對應。
- 書寫規範:必須在
@ref_name 後保留一個空格作為分隔。
示例值:
- 普通提示詞:男人坐在靠窗的椅子上,手持吉他,在咖啡廳旁演奏一首舒緩的美國鄉村民謠。
- 含引用的提示詞:@男人 坐在靠窗的椅子上,手持@吉他 ,在@咖啡廳 旁演奏一首舒緩的美國鄉村民謠。
media array (必選) 媒體素材列表,用於指定視頻生成所需的參考圖像。 數組的每個元素為一個媒體對象,包含 type和 url字段。 元素屬性 type string (必選) 媒體素材類型。固定值為: 素材數量限制:圖像數量最多7張。 url string (必選) 參考圖像URL,必須為公網可訪問的 URL。 圖像限制:
- 格式:JPG、PNG、WEBP。
- 解析度:圖像的寬度和高度均不超過10000像素。
- 檔案大小:不超過20MB。
ref_name string (可選) 參考圖片中主體的名稱標識,用於在prompt中通過@ref_name引用。長度不超過30個字符。 parameters object (必選) 視頻生成參數。如設定視頻解析度、時長、是否生成音訊等。 屬性 size string (必選) 生成視頻的解析度,格式為寬*高的像素值。 不同解析度檔位對應的可選值見下方表格。 pixverse/pixverse-v6-r2v模型 解析度檔位 | 寬高比 | size取值(寬*高) | 360P | 16:9 | 640*360 | 4:3 | 640*480 | 1:1 | 640*640 | 3:4 | 480*640 | 9:16 | 360*640 | 3:2 | 640*432 | 2:3 | 432*640 | 21:9 | 640*288 | 540P | 16:9 | 1024*576 | 4:3 | 1024*768 | 1:1 | 1024*1024 | 3:4 | 768*1024 | 9:16 | 576*1024 | 3:2 | 1024*688 | 2:3 | 688*1024 | 21:9 | 1024*448 | 720P | 16:9 | 1280*720 | 4:3 | 1108*832 | 1:1 | 960*960 | 3:4 | 832*1108 | 9:16 | 720*1280 | 3:2 | 1200*800 | 2:3 | 800*1200 | 21:9 | 1280*560 | 1080P | 16:9 | 1920*1080 | 4:3 | 1664*1248 | 1:1 | 1440*1440 | 3:4 | 1248*1664 | 9:16 | 1080*1920 | 3:2 | 1776*1184 | 2:3 | 1184*1776 | 21:9 | 1920*832 |
示例值:1280*720。 duration integer (必選) 生成視頻的時長,單位為秒。
- pixverse/pixverse-v6-r2v:取值範圍為[1, 15]之間的整數。
示例值:5。 audio boolean (可選) 是否生成有聲視頻。開啟後模型將根據視頻內容自動生成匹配的背景音樂或音效。
false:預設值,輸出無聲視頻。
true:輸出有聲視頻。
示例值:false。 watermark boolean (可選) 是否添加水印標識,水印位於視頻右下角,文案固定為“AI生成”。
false:預設值,不添加水印。
true:添加水印。
示例值:false。 seedinteger(可選) 隨機數種子,取值範圍為[0, 2147483647]。 未指定時,系統自動生成隨機種子。若需提升生成結果的可復現性,建議固定seed值。 請注意,由於模型生成具有概率性,即使使用相同 seed,也不能保證每次生成結果完全一致。 | 參考生視頻通過 media 傳入參考圖像,設定 size 和 duration 控制視頻解析度和時長。 # 调用时请将 {WorkspaceId} 替换为真实的业务空间ID。
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": "pixverse/pixverse-v6-r2v",
"input": {
"media": [
{
"type": "image_url",
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260320/knsple/wan-r2v-role-frame.jpg"
},
{
"type": "image_url",
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png"
},
{
"type": "image_url",
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png"
}
],
"prompt": "男人坐在靠窗的椅子上,手持吉他,在咖啡厅旁演奏一首舒缓的美国乡村民谣"
},
"parameters": {
"size": "1280*720",
"duration": 5,
"audio": false,
"watermark": true
}
}'
Python SDKimport dashscope
import os
from dashscope.v2 import DashScopeError
# 以下為新加坡地區的配置,調用時請將{WorkspaceId}替換為真實的業務空間ID,各地區的region取值不同。
client = dashscope.Client(
# 若未配置環境變數,請將下一行替換為您的 Model Studio API Key:api_key="sk-xxx"
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
media = [{'type': 'image_url', 'url': 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260320/knsple/wan-r2v-role-frame.jpg'}, {'type': 'image_url', 'url': 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png'}, {'type': 'image_url', 'url': 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png'}]
def sample_async_call():
# 非同步提交視頻生成任務
# audio 不在具名簽名內,通過parameters透傳
try:
job = client.videos.jobs.create(model='pixverse/pixverse-v6-r2v',
media=media,
prompt='男人坐在靠窗的椅子上,手持吉他,在咖啡厅旁演奏一首舒缓的美国乡村民谣',
size='1280*720',
duration=5,
watermark=True,
parameters={'audio': False})
print(job)
print("task_id: %s" % job.task_id)
except DashScopeError as e:
print(f"HTTP status code: {e.status_code}")
print(f"Error code: {e.code}")
print(f"Error message: {e.message}")
print("See the documentation: https://www.alibabacloud.com/help/model-studio/developer-reference/error-code")
return
# 查詢任務狀態
try:
snapshot = client.videos.jobs.fetch(job.task_id)
print(snapshot.status)
except DashScopeError as e:
print(f"HTTP status code: {e.status_code}")
print(f"Error code: {e.code}")
print(f"Error message: {e.message}")
print("See the documentation: https://www.alibabacloud.com/help/model-studio/developer-reference/error-code")
# 等待任務完成
try:
done = client.videos.jobs.wait(job)
print(done)
print(done.video_url)
except DashScopeError as e:
print(f"HTTP status code: {e.status_code}")
print(f"Error code: {e.code}")
print(f"Error message: {e.message}")
print("See the documentation: https://www.alibabacloud.com/help/model-studio/developer-reference/error-code")
if __name__ == '__main__':
sample_async_call()
參考生視頻(使用ref_name)在 media 傳入參考圖像,並傳入ref_name用於設定參考圖像的主體名稱。 # 调用时请将 {WorkspaceId} 替换为真实的业务空间ID。
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": "pixverse/pixverse-v6-r2v",
"input": {
"media": [
{
"type": "image_url",
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260320/knsple/wan-r2v-role-frame.jpg",
"ref_name": "男人"
},
{
"type": "image_url",
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png",
"ref_name": "吉他"
},
{
"type": "image_url",
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png",
"ref_name": "咖啡厅"
}
],
"prompt": "@男人 坐在靠窗的椅子上,手持@吉他 ,在@咖啡厅 旁演奏一首舒缓的美国乡村民谣"
},
"parameters": {
"size": "1280*720",
"duration": 5,
"audio": false,
"watermark": true
}
}'
|