爱诗-文生视频模型基于 文本提示词 ,生成一段流畅的视频。
重要本文档仅适用于华北2(北京)地域,且必须使用该地域的API Key。
服务开通
- 前往阿里云百炼控制台,搜索 PixVerse,找到 PixVerse 模型卡片,单击立即开通;
- 在弹窗内确认开通及授权。
适用范围
为确保调用成功,请务必保证模型、Endpoint URL 和 API Key 均属于同一地域。跨地域调用将会失败。
- 选择模型:确认模型所属的地域。
- 选择 URL:选择对应的地域 Endpoint URL,支持HTTP URL或 DashScope SDK URL。
- 配置 API Key:选择地域并获取与配置 API Key,再配置API Key到环境变量。
- 安装 SDK:如需通过SDK进行调用,请安装DashScope SDK。
说明本文的示例代码适用于华北2(北京)地域。
HTTP调用
由于文生视频任务耗时较长(通常为1-5分钟),API采用异步调用。整个流程包含 "创建任务 -> 轮询获取" 两个核心步骤,具体如下:
步骤1:创建任务获取任务ID
北京地域:POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
调用时请将{WorkspaceId}替换为真实的业务空间ID。
说明
- 创建成功后,使用接口返回的
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 模型名称。 可选值:
input 输入的基本信息,如提示词等。 parameters 视频生成参数。如设置视频分辨率、时长、是否生成音频等。 | 文生视频支持模型:pixverse/pixverse-c1-t2v、pixverse/pixverse-v6-t2v、pixverse/pixverse-v5.6-t2v。 文生视频(多镜头)pixverse-c1支持模型:pixverse/pixverse-c1-t2v。 在 pixverse-v6支持模型:pixverse/pixverse-v6-t2v。 在 |
响应参数output 任务输出信息。 request_id 请求唯一标识。可用于请求明细溯源和问题排查。 code 请求失败的错误码。请求成功时不会返回此参数,详情请参见错误码。 message 请求失败的详细信息。请求成功时不会返回此参数,详情请参见错误码。 | 成功响应请保存 task_id,用于查询任务状态与结果。 异常响应创建任务失败,请参见错误码进行解决。 |
步骤2:根据任务ID查询结果
北京地域:GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
请求参数请求头(Headers)Authorization 请求身份认证。接口使用阿里云百炼API Key进行身份认证。示例值:Bearer sk-xxxx。 URL路径参数(Path parameters)task_id 任务ID。 | 查询任务结果将 |
响应参数output 任务输出信息。 usage 输出信息统计。只对成功的结果计数。 request_id 请求唯一标识。可用于请求明细溯源和问题排查。 | 任务执行成功任务执行失败若任务执行失败,task_status将置为 FAILED,并提供错误码和信息。请参见错误码进行解决。 任务查询过期task_id查询有效期为 24 小时,超时后将无法查询,返回以下报错信息。 |
DashScope SDK调用
SDK 的参数命名与HTTP接口基本一致,参数结构根据语言特性进行封装。
由于文生视频任务耗时较长(通常为1-5分钟),SDK 在底层封装了 HTTP 异步调用流程,支持同步、异步两种调用方式。
具体耗时受限于排队任务数和服务执行情况,请在获取结果时耐心等待。
Python SDK调用
重要请确保 DashScope Python SDK 版本不低于2.0.1,再运行以下代码。
北京地域:region="cn-beijing"
调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的region取值不同。
同步调用
请求示例
import os
import dashscope
from dashscope.v2 import DashScopeError
# 以下为华北2(北京)地域的配置。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的region取值不同。
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="cn-beijing",
)
def sample_sync_call_t2v():
# call sync api, will return the result
print('please wait...')
# generate 为一步式调用(提交任务并等待完成),返回已完成的 Job
# audio 为 parameters 段字段,不在具名签名内,经 parameters 透传
try:
job = client.videos.generate(model='pixverse/pixverse-c1-t2v',
prompt='下着雨,赛博城市里,一只浣熊在栏杆上行走。突然他眼睛发出蓝光,变身成一架高科技无人机,快速飞离画面。',
size='1280*720',
duration=5,
watermark=False,
parameters={'audio': False})
print(job)
print(job.video_url)
except DashScopeError as e:
print(f"HTTP返回码:{e.status_code}")
print(f"错误码:{e.code}")
print(f"错误信息:{e.message}")
print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
if __name__ == '__main__':
sample_sync_call_t2v()
响应示例
video_url暂无过期时间,但不建议将其作为长期存储,请及时下载。
{
"request_id": "2b68d32e-86c8-4383-8a18-xxxxxx",
"task_id": "ec40bb42-02d4-44d8-bf35-xxxxxx",
"status": "SUCCEEDED",
"results": [
{
"video_url": "https://media.pixverseai.cn/xxx.mp4"
}
],
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
},
"usage": {
"video_count": 1,
"video_duration": 0,
"video_ratio": "",
"duration": 10,
"size": "1280*720",
"fps": 24,
"audio": false,
"SR": "720"
}
}
异步调用
请求示例
import os
import dashscope
from dashscope.v2 import DashScopeError
# 以下为华北2(北京)地域的配置。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的region取值不同。
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="cn-beijing",
)
def sample_async_call_t2v():
# call async api, will return the task information
# you can get task status with the returned task id.
# audio 为 parameters 段字段,不在具名签名内,经 parameters 透传
try:
job = client.videos.jobs.create(model='pixverse/pixverse-c1-t2v',
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返回码:{e.status_code}")
print(f"错误码:{e.code}")
print(f"错误信息:{e.message}")
print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
return
# get the task information include the task status.
try:
snapshot = client.videos.jobs.fetch(job.task_id)
print(snapshot.status) # check the task status
except DashScopeError as e:
print(f"HTTP返回码:{e.status_code}")
print(f"错误码:{e.code}")
print(f"错误信息:{e.message}")
print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
# wait the task complete, will call fetch interval, and check it's in finished status.
try:
done = client.videos.jobs.wait(job)
print(done)
print(done.video_url)
except DashScopeError as e:
print(f"HTTP返回码:{e.status_code}")
print(f"错误码:{e.code}")
print(f"错误信息:{e.message}")
print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
if __name__ == '__main__':
sample_async_call_t2v()
响应示例
1、创建任务的响应示例
{
"request_id": "c86ff7ba-8377-917a-90ed-xxxxxx",
"task_id": "721164c6-8619-4a35-a6d9-xxxxxx",
"status": "PENDING"
}
2、查询任务结果的响应示例
video_url暂无过期时间,但不建议将其作为长期存储,请及时下载。
{
"request_id": "2b68d32e-86c8-4383-8a18-xxxxxx",
"task_id": "ec40bb42-02d4-44d8-bf35-xxxxxx",
"status": "SUCCEEDED",
"results": [
{
"video_url": "https://media.pixverseai.cn/xxx.mp4"
}
],
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
},
"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,再运行以下代码。
北京地域:Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
调用时请将{WorkspaceId}替换为真实的业务空间ID。
同步调用
请求示例
// 调用时请将 {WorkspaceId} 替换为真实的业务空间ID。
// 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://{WorkspaceId}.cn-beijing.maas.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-c1-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": ""
}
异步调用
请求示例
// 调用时请将 {WorkspaceId} 替换为真实的业务空间ID。
// 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://{WorkspaceId}.cn-beijing.maas.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-c1-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: pixverse-v5.6-t2v 在 1080P 下不支持 10 秒。建议降低分辨率至 720P/540P/360P,或切换至 pixverse-c1-t2v或pixverse-v6-t2v 模型。