视频生成 API
本页介绍通过 /videos 端点创建与下载视频的流程,覆盖纯文本生成、图生视频、视频续写、音频驱动、状态轮询与内容下载的完整示例。示例基于 requests/curl,可按需替换为其他 HTTP 客户端。
支持的模型
可用型号、价格与区域以模型列表为准:
鉴权与基础信息
- Base URL:
https://live-turing.cn.llm.tcljd.com/api/v1 - 认证:
Authorization: Bearer <YOUR_API_KEY> - 资源路径:
- 创建任务:
POST /videos - 查询状态:
GET /videos/{video_id} - 下载内容:
GET /videos/{video_id}/content
- 创建任务:
- 返回的
status常见值:queued→processing→completed,失败时为failed。
参数限制说明
Veo 模型
- seconds (string): 仅支持
"4","6","8"。 - size (string): 仅支持
"1280x720"和"720x1280"。 - input_reference: 图生视频时上传的参考图,文件大小限制为 10MB。
- personGeneration (string): 仅 Gemini Veo 模型支持。图生视频上传人物图片时,可传入
allow_all允许生成人物相关内容;但包含儿童的人物图片会被安全策略禁止。
Seedance 模型
完整的 Seedance API 参数规范请参考 火山引擎官方文档。
Seedance 参数:通过 JSON body 直接传递 Seedance 原生参数,支持更丰富的控制:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | - | 模型 ID |
prompt | string | 是 | - | 文本描述(自动填入 content 数组) |
content | array | 否 | [] | 多模态内容数组,支持混合 text/image/video/audio(见下方说明) |
resolution | string | 否 | - | 分辨率:"480p", "720p" |
ratio | string | 否 | - | 画面比例:"16:9", "9:16", "1:1", "4:3", "3:4" |
duration | int | 否 | - | 视频时长(秒):4, 5, 6, 8 |
seed | int | 否 | - | 随机种子,用于复现结果 |
watermark | bool | 否 | false | 是否添加水印 |
generate_audio | bool | 否 | true | 是否生成音频 |
return_last_frame | bool | 否 | false | 是否返回最后一帧图片(用于视频续写衔接) |
content 数组支持的类型:
| type | 结构 | 说明 |
|---|---|---|
text | {"type": "text", "text": "描述文本"} | 文本描述 |
image_url | {"type": "image_url", "image_url": {"url": "..."}} | 参考图片(支持 HTTPS URL 或 base64 data URI) |
video_url | {"type": "video_url", "video_url": {"url": "..."}} | 参考视频(HTTPS URL) |
audio_url | {"type": "audio_url", "audio_url": {"url": "..."}} | 参考音频(HTTPS URL) |
Seedance 支持的尺寸(size 参数自动映射)
下表列出 seedance 2.0 / 2.0 fast 在不同 resolution + ratio 组合下输出的像素值:
| 分辨率 | 宽高比 | 宽高像素值 |
|---|---|---|
| 480p | 16:9 | 864×496 |
| 480p | 4:3 | 752×560 |
| 480p | 1:1 | 640×640 |
| 480p | 3:4 | 560×752 |
| 480p | 9:16 | 496×864 |
| 480p | 21:9 | 992×432 |
| 720p | 16:9 | 1280×720 |
| 720p | 4:3 | 1112×834 |
| 720p | 1:1 | 960×960 |
| 720p | 3:4 | 834×1112 |
| 720p | 9:16 | 720×1280 |
| 720p | 21:9 | 1470×630 |
纯文本生成示例(JSON 请求)
curl $TURING_BASE_URL/videos \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "please generate a video of a cat playing piano",
"model": "turing/veo-3.1-generate",
"size": "1280x720",
"seconds": "6"
}'
响应示例(HTTP 200):
{
"id": "video-xxx",
"status": "in_progress",
"model": "turing/veo-3.1-generate"
}
图生视频示例(multipart/form-data)
当需要参考图像时,使用表单上传文件字段 input_reference,其中文件名与 MIME 类型必填。
注意:上传的图片文件大小不能超过 10MB。Gemini Veo 模型如需基于人物图片生成视频,可额外传入
personGeneration=allow_all;包含儿童的人物图片会被禁止上传 / 生成。
curl $TURING_BASE_URL/videos \
-H "Authorization: Bearer $TURING_API_KEY" \
-F "prompt=Generate a video that from the facade of the picture showing in the file to the real Pompidou Center" \
-F "model=turing/veo-3.1-generate" \
-F "size=1280x720" \
-F "seconds=6" \
-F "personGeneration=allow_all" \
-F "input_reference=@tests/e2e/video_image.jpg;type=image/jpeg"
Python 示例
import requests
BASE_URL = "https://live-turing.cn.llm.tcljd.com/api/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
payload = {
"prompt": "Generate a video that from the facade of the picture showing in the file to the real Pompidou Center",
"model": "turing/veo-3.1-generate",
"size": "1280x720",
"seconds": "6",
"personGeneration": "allow_all",
}
with open("tests/e2e/video_image.jpg", "rb") as f:
# 确保文件大小不超过 10MB
files = {"input_reference": ("pompidou.jpg", f.read(), "image/jpeg")}
res = requests.post(f"{BASE_URL}/videos", data=payload, files=files, headers=HEADERS)
res.raise_for_status()
video_id = res.json()["id"]
print(f"Created video task: {video_id}")
Seedance 请求示例(JSON 请求)
使用 content 数组 + resolution/ratio/duration 等原生参数,可以实现更精细的控制。
curl $TURING_BASE_URL/videos \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "一只猫在弹钢琴",
"model": "doubao-seedance-2-0-260128",
"content": [
{"type": "text", "text": "一只猫在弹钢琴,背景是温暖的客厅,阳光洒进来"},
{"type": "image_url", "image_url": {"url": "https://example.com/cat_reference.jpg"}}
],
"resolution": "1080p",
"ratio": "16:9",
"duration": 6,
"seed": 42,
"generate_audio": true,
"return_last_frame": false
}'
轮询任务状态
GET /videos/{video_id} 返回实时状态。
推荐轮询间隔为 20s - 30s,避免过于频繁的请求。
curl -X GET $TURING_BASE_URL/videos/$VIDEO_ID \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json"
import asyncio
import requests
async def wait_until_done(video_id: str):
# 建议每 20-30 秒检查一次
poll_interval = 30
for _ in range(20): # 根据生成时长适当调整重试次数
res = requests.get(f"{BASE_URL}/videos/{video_id}", headers=HEADERS)
res.raise_for_status()
data = res.json()
if data["status"] == "completed":
return data
if data["status"] == "failed":
raise RuntimeError(f"Video {video_id} failed")
await asyncio.sleep(poll_interval)
raise TimeoutError(f"Video {video_id} not finished in time")
下载视频内容
生成完成后,通过 GET /videos/{video_id}/content 获取二进制视频流(Content-Type: video/mp4)。
curl -X GET $TURING_BASE_URL/videos/$VIDEO_ID/content \
-H "Authorization: Bearer $TURING_API_KEY" \
-o output.mp4
错误与常见限制
通用限制
- 文件大小: 上传图片文件超过 10MB 会返回 HTTP 400。
- 状态管理: 视频生成耗时较长,请确保客户端有足够的超时等待或使用异步轮询机制。
Veo 模型限制
seconds: 必须是"4","6","8"。size: 必须是"1280x720"或"720x1280"。input_reference: 仅支持图片。personGeneration=allow_all: 仅 Gemini Veo 模型支持,用于允许基于人物图片生成视频;包含儿童的人物图片会被安全策略禁止。