爱诗-文生视频API参考
爱诗-文生视频模型基于文本提示词,生成一段流畅的视频。
本文档仅适用于“中国内地(北京)”地域,且必须使用该地域的API Key。
适用范围
为确保调用成功,请务必保证模型、Endpoint URL 和 API Key 均属于同一地域。跨地域调用将会失败。
选择模型:确认模型所属的地域。
选择 URL:选择对应的地域 Endpoint URL,支持HTTP URL或 DashScope SDK URL。
配置 API Key:选择地域并获取API Key,再配置API Key到环境变量。
安装 SDK:如需通过SDK进行调用,请安装DashScope SDK。
HTTP调用
由于文生视频任务耗时较长(通常为1-5分钟),API采用异步调用。整个流程包含 "创建任务 -> 轮询获取" 两个核心步骤,具体如下:
步骤1:创建任务获取任务ID
北京地域:POST https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
创建成功后,使用接口返回的
task_id查询结果,task_id 有效期为 24 小时。请勿重复创建任务,轮询获取即可。新手指引请参见Postman。
请求参数 | 文生视频通过 生成带音频视频通过设置 |
请求头(Headers) | |
Content-Type 请求内容类型。此参数必须设置为 | |
Authorization 请求身份认证。接口使用阿里云百炼API-Key进行身份认证。示例值:Bearer sk-xxxx。 | |
X-DashScope-Async 异步处理配置参数。HTTP请求只支持异步,必须设置为 重要 缺少此请求头将报错:“current user api does not support synchronous calls”。 | |
请求体(Request Body) | |
model 模型名称。 固定值:pixverse/pixverse-v5.6-t2v。 | |
input 输入的基本信息,如提示词等。 | |
parameters 视频生成参数。如设置视频分辨率、时长、是否生成音频等。 |
响应参数 | 成功响应请保存 task_id,用于查询任务状态与结果。 异常响应创建任务失败,请参见错误信息进行解决。 |
output 任务输出信息。 | |
request_id 请求唯一标识。可用于请求明细溯源和问题排查。 | |
code 请求失败的错误码。请求成功时不会返回此参数,详情请参见错误信息。 | |
message 请求失败的详细信息。请求成功时不会返回此参数,详情请参见错误信息。 |
步骤2:根据任务ID查询结果
北京地域:GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
请求参数 | 查询任务结果将 |
请求头(Headers) | |
Authorization 请求身份认证。接口使用阿里云百炼API-Key进行身份认证。示例值:Bearer sk-xxxx。 | |
URL路径参数(Path parameters) | |
task_id 任务ID。 |
响应参数 | 任务执行成功任务执行失败若任务执行失败,task_status将置为 FAILED,并提供错误码和信息。请参见错误信息进行解决。 任务查询过期task_id查询有效期为 24 小时,超时后将无法查询,返回以下报错信息。 |
output 任务输出信息。 | |
usage 输出信息统计。只对成功的结果计数。 | |
request_id 请求唯一标识。可用于请求明细溯源和问题排查。 |
DashScope SDK调用
SDK 的参数命名与HTTP接口基本一致,参数结构根据语言特性进行封装。
由于文生视频任务耗时较长(通常为1-5分钟),SDK 在底层封装了 HTTP 异步调用流程,支持同步、异步两种调用方式。
具体耗时受限于排队任务数和服务执行情况,请在获取结果时耐心等待。
Python SDK调用
请确保 DashScope Python SDK 版本不低于 1.25.8,再运行以下代码。
若版本过低,可能会触发 "url error, please check url!" 等错误。请参考安装SDK进行更新。
北京地域:dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
同步调用
请求示例
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os
# 以下为北京地域URL
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 获取API Key:https://help.aliyun.com/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='pixverse/pixverse-v5.6-t2v',
prompt='一只小猫在月光下奔跑',
size='1280*720',
duration=10,
audio=False,
watermark=False)
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暂无过期时间,但不建议将其作为长期存储,请及时下载。{
"status_code": 200,
"request_id": "2b68d32e-86c8-4383-8a18-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "ec40bb42-02d4-44d8-bf35-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://media.pixverseai.cn/xxx.mp4",
"submit_time": "2026-03-20 10:59:01.993",
"scheduled_time": "2026-03-20 10:59:02.028",
"end_time": "2026-03-20 11:00:06.322",
"orig_prompt": "一只小猫在月光下奔跑"
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"size": "1280*720",
"fps": 24,
"audio": false,
"SR": "720"
}
}异步调用
请求示例
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os
# 以下为北京地域URL
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 获取API Key:https://help.aliyun.com/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='pixverse/pixverse-v5.6-t2v',
prompt='一只小猫在月光下奔跑',
size='1280*720',
duration=10,
audio=False,
watermark=True)
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 暂无过期时间,但不建议将其作为长期存储,请及时下载。{
"status_code": 200,
"request_id": "2b68d32e-86c8-4383-8a18-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "ec40bb42-02d4-44d8-bf35-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://media.pixverseai.cn/xxx.mp4",
"submit_time": "2026-03-20 10:59:01.993",
"scheduled_time": "2026-03-20 10:59:02.028",
"end_time": "2026-03-20 11:00:06.322",
"orig_prompt": "一只小猫在月光下奔跑"
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"size": "1280*720",
"fps": 24,
"audio": false,
"SR": "720"
}
}Java SDK调用
请确保 DashScope Java SDK 版本不低于 2.22.6,再运行以下代码。
若版本过低,可能会触发 “url error, please check url!” 等错误。请参考安装SDK进行更新。
北京地域:Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
同步调用
请求示例
// Copyright (c) Alibaba, Inc. and its affiliates.
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;
public class Text2Video {
static {
// 以下为北京地域url
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
// 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* Create a video compositing task and wait for the task to complete.
*/
public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("pixverse/pixverse-v5.6-t2v")
.prompt("一只小猫在月光下奔跑")
.size("1280*720")
.duration(5)
.audio(true)
.watermark(true)
.seed(12345)
.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 暂无过期时间,但不建议将其作为长期存储,请及时下载。{
"request_id": "bd1109bd-6c63-4e62-8bb8-xxxxxx",
"output": {
"task_id": "72af7c13-dad5-4aaa-b85d-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://media.pixverseai.cn/xxx.mp4",
"orig_prompt": "一只小猫在月光下奔跑",
"submit_time": "2026-03-20 11:21:13.227",
"scheduled_time": "2026-03-20 11:21:13.252",
"end_time": "2026-03-20 11:21:43.924"
},
"usage": {
"video_count": 1,
"duration": 5.0,
"size": "1280*720",
"input_video_duration": 0.0,
"output_video_duration": 0.0,
"SR": "720"
},
"status_code": 200,
"code": "",
"message": ""
}异步调用
请求示例
// 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;
public class Text2Video {
static {
// 以下为北京地域url
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
// 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* Create a video compositing task and wait for the task to complete.
*/
public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
VideoSynthesis vs = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("pixverse/pixverse-v5.6-t2v")
.prompt("一只小猫在月光下奔跑")
.size("1280*720")
.duration(5)
.audio(true)
.watermark(true)
.seed(12345)
.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": "9b583f1b-2423-4fac-bb3f-xxxxxx",
"output": {
"task_id": "3944b819-1bbb-4da0-a230-xxxxxx",
"task_status": "PENDING"
},
"status_code": 200,
"code": "",
"message": ""
}2、查询任务结果的响应示例
video_url 暂无过期时间,但不建议将其作为长期存储,请及时下载。{
"request_id": "bd1109bd-6c63-4e62-8bb8-xxxxxx",
"output": {
"task_id": "72af7c13-dad5-4aaa-b85d-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://media.pixverseai.cn/xxx.mp4",
"orig_prompt": "一只小猫在月光下奔跑",
"submit_time": "2026-03-20 11:21:13.227",
"scheduled_time": "2026-03-20 11:21:13.252",
"end_time": "2026-03-20 11:21:43.924"
},
"usage": {
"video_count": 1,
"duration": 5.0,
"size": "1280*720",
"input_video_duration": 0.0,
"output_video_duration": 0.0,
"SR": "720"
},
"status_code": 200,
"code": "",
"message": ""
}错误码
如果模型调用失败并返回报错信息,请参见错误信息进行解决。
常见问题
Q: 为什么1080P分辨率下不能使用10秒时长?
A: 1080P分辨率下仅支持5秒和8秒时长。这是模型本身的限制。如果需要生成10秒视频,请选择720P或更低的分辨率档位。