概述
| 项目 | 值 |
|---|---|
| Base URL | https://new.tangzhi.org |
| 控制台 | https://new.tangzhi.org |
| TZ生成工作台 | https://vip.tangzhi.org(在线生成视频、图片,无需写代码) |
| 模型定价 | https://docs.tangzhi.org/pricing |
快速开始
创建 API 密钥,提交生成请求,然后使用任务 ID 查询结果并下载视频。
鉴权与请求头
所有 API 请求使用 Bearer Token。API Key 仅应保存在服务端,不要写入浏览器代码、公开仓库或日志。
| 请求头 | 值 | 说明 |
|---|---|---|
Authorization | Bearer 你的_API_KEY | 必填,用于识别账户和调用权限 |
Content-Type | application/json | JSON 请求必填 |
Authorization: Bearer 你的_API_KEY Content-Type: application/json
接口端点
所有视频模型共用以下三个端点,点击展开查看示例。
{
"model": "ch0101-sd-2.0-720p",
"prompt": "人物向前走,背景流动变换",
"client_task_id": "order_20260926_000001",
"mode": "references",
"aspect_ratio": "16:9",
"duration": 5,
"resolution": "720p"
}{ "id": "task_abc123def456", "object": "video", "status": "queued", "progress": 0 }curl https://new.tangzhi.org/v1/videos/task_abc123def456 \ -H "Authorization: Bearer 你的_API_KEY"
{ "id": "task_abc123def456", "object": "video", "status": "in_progress", "progress": 30 }curl -o output.mp4 https://new.tangzhi.org/v1/videos/task_abc123def456/content \ -H "Authorization: Bearer 你的_API_KEY"
二进制视频流,Content-Type: video/mp4。任务未完成时返回错误。
通用请求参数
创建任务时使用以下参数,具体约束(如 prompt 长度、可选值)因模型而异,详见 模型定价。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,以 模型定价 中开放调用的模型为准 |
prompt | string | 是 | 视频内容描述,长度限制因模型而异 |
mode | string | 是 | references / frames(默认 references) |
aspect_ratio | string | 否 | 画面比例,如 16:9、9:16,范围因模型而异 |
duration | number | 否 | 视频时长(秒),范围因模型而异;按秒计费模型按此时长计费 |
resolution | string | 否 | 分辨率,如 480p、720p、1080p,需与模型匹配 |
references | object | 否 | 参考素材块,留空即为纯文生视频 |
frames | object | 条件 | mode=frames 时必填 |
client_task_id | string | 是 | 幂等任务 ID,最长 128 字符,仅支持字母、数字、下划线、连字符和点号 |
mode 互斥:references 模式不能带 frames,frames 模式不能带 references。301010 全能参考:上传素材并生成视频
适用于 seedance2.5-480p-301010 和 seedance2.5-720p-301010。用自己的中转站 API Key 完成上传、生成、查询和下载。两款模型均按全能参考使用图片、视频、音频,可按需组合。图片是内容参考,即使只传一张也不指定首帧;多张图片也不指定首尾帧。
1. 逐个上传,取得文件 ID
POST https://new.tangzhi.org/v1/videos/files,使用 Authorization: Bearer <API_KEY>。请求格式为 multipart/form-data;每次上传一个 file,并提供生成时使用的 model。可用 purpose 显式声明素材类型。
| 素材 | purpose → 生成字段 | 单文件上限 | 每条视频上限 |
|---|---|---|---|
| 图片 | image → images | 20 MiB | 30 张 |
| 视频 | video → videos | 100 MiB | 10 段 |
| 音频 | audio → audios | 15 MiB | 10 段 |
下面是 Bash 示例,依赖 curl、jq。先设置 TZ_API_KEY,并准备示例中的三个本地文件;只用某类素材时,只执行对应上传,再从生成请求中删掉不用的数组。
BASE=https://new.tangzhi.org/v1
MODEL=seedance2.5-720p-301010
upload() {
curl --fail-with-body -sS "$BASE/videos/files" \
-H "Authorization: Bearer $TZ_API_KEY" \
-F "model=$MODEL" -F "purpose=$1" -F "file=@$2" | jq -er '.id'
}
IMAGE_ID=$(upload image reference.png) || exit 1
VIDEO_ID=$(upload video motion.mp4) || exit 1
AUDIO_ID=$(upload audio rhythm.wav) || exit 1
成功返回 {"object":"file","id":"file_…","purpose":"image","bytes":12345}。生成时传返回的 ID,不传本地路径、网址或 base64。
2. 提交全能参考任务
PAYLOAD=$(jq -n --arg m "$MODEL" --arg i "$IMAGE_ID" --arg v "$VIDEO_ID" --arg a "$AUDIO_ID" \
'{model:$m, prompt:"参考图片的色调、视频的运动和音频的节奏,生成一段新视频。",
mode:"references", seconds:5, aspect_ratio:"16:9", images:[$i], videos:[$v], audios:[$a]}')
TASK_ID=$(curl --fail-with-body -sS "$BASE/videos" -H "Authorization: Bearer $TZ_API_KEY" \
-H 'Content-Type: application/json' -d "$PAYLOAD" | jq -er '.id') || exit 1
echo "$TASK_ID"
分辨率由模型名决定。时长 seconds 为 4–30 的整数。只有参考图片时,只保留 images;纯文字生成时不需要上传,省略三个数组和 mode。不要传 frames 或 input_reference。
3. 查询并下载 MP4
curl --fail-with-body -sS "$BASE/videos/$TASK_ID" -H "Authorization: Bearer $TZ_API_KEY"
# 等到 status 为 completed,再执行下载
curl --fail --show-error --location "$BASE/videos/$TASK_ID/content" \
-H "Authorization: Bearer $TZ_API_KEY" -o result.mp4
用同一把 Key 每 10–15 秒查询一次。排队、生成中或查询暂时超时时请继续查原任务;不要重复创建。若任务为 failed,保留任务 ID 以便排查。上传报 400 时检查文件类型和字段,403 检查模型权限,413 检查大小,429 稍后重试。
references 结构
参考素材放在 references 对象内,当前仅支持公网可访问的 URL,不支持 multipart/form-data 文件上传,也不接收 base64 / data URL。
{
"references": {
"image": "https://example.com/ref.jpg",
"images": ["https://example.com/ref1.jpg", "https://example.com/ref2.jpg"],
"video": "https://example.com/ref.mp4",
"videos": ["https://example.com/ref1.mp4", "https://example.com/ref2.mp4"],
"audio": "https://example.com/ref.mp3",
"audios": ["https://example.com/ref1.mp3", "https://example.com/ref2.mp3"]
}
}| 字段 | 类型 | 说明 |
|---|---|---|
image | string | 单张参考图(1 张时用此字段) |
images | string[] | 多张参考图(≥2 张时用此字段) |
video | string | 单个参考视频(1 条时用此字段) |
videos | string[] | 多个参考视频(≥2 条时用此字段) |
audio | string | 单个参考音频(1 条时用此字段) |
audios | string[] | 多个参考音频(≥2 条时用此字段) |
image/images、video/videos、audio/audios 两两互斥。只有 1 个元素时必须用单数字段,≥2 个才能用复数字段;空数组、单元素数组均返回 400。各模型的素材数量上限见 模型定价。frames 结构
首尾帧驱动模式,需将 mode 设为 frames。
{
"frames": {
"first_frame": "https://example.com/start.jpg",
"last_frame": "https://example.com/end.jpg"
}
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
first_frame | string | 是 | 首帧图片 URL |
last_frame | string | 是 | 尾帧图片 URL |
响应格式
创建与查询接口返回同一种任务对象,字段随状态变化。在 任务状态 中点击各状态可查看对应响应。
| 字段 | 类型 | 出现时机 | 说明 |
|---|---|---|---|
id | string | 始终 | 任务唯一标识,用于查询与下载 |
object | string | 始终 | 固定值 "video" |
model | string | 始终 | 使用的模型名 |
status | string | 始终 | 任务状态,见 任务状态 |
progress | number | 始终 | 进度百分比 0-100 |
created_at | number | 始终 | 创建时间戳(Unix 秒) |
completed_at | number | completed / failed | 完成或失败时间戳 |
error | object | failed | 失败信息,含 code 与 message |
任务完成后,使用 GET /v1/videos/:taskId/content 下载视频文件(video/mp4)。
任务状态
点击状态查看含义和对应的查询响应。
建议每 5-15 秒查询一次,生成通常需要 1-6 分钟,视模型、时长与排队情况而定。
client_task_id 幂等说明
每次创建任务都必须传入 client_task_id,建议使用你业务系统里的唯一订单号。
| 场景 | 建议 |
|---|---|
| 首次创建任务 | 使用新的 client_task_id |
| 请求超时 | 使用同一个 client_task_id 重试,避免同一业务订单生成新任务 |
| 视频取回失败 | 使用同一个 client_task_id 重新提交,系统会继续尝试取回同一任务结果 |
| 新业务订单 | 使用新的 client_task_id |
client_task_id。任务进行中或已完成时重复提交,请求会被拒绝,请使用原任务 ID 查询。错误处理
请求失败时返回非 2xx 状态码。鉴权、格式等网关错误返回 {"error": {...}};参数校验等任务错误返回 {"code": "fail_to_fetch_task", "message": "..."},message 可能嵌套多层 JSON,最里层的 error.code 才是真正的错误码。
{
"code": "fail_to_fetch_task",
"message": "{\"error\":{\"code\":\"invalid_params\",\"message\":\"mode 为必填项(references/frames)\"}}",
"data": null
}完整错误码、校验错误与 错误解析器 见 错误码参考。下方点击状态码查看常见原因。
按秒计费的模型在提交时按 duration 预扣费用,任务失败会退回。
代码示例
完整流程:创建任务 → 轮询 → 下载。语言选择会在整页同步。
你的_API_KEY 换成控制台创建的令牌
# 1. 创建任务
curl -X POST https://new.tangzhi.org/v1/videos \
-H "Authorization: Bearer 你的_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "ch0101-sd-2.0-720p",
"prompt": "人物向前走,背景流动变换",
"client_task_id": "order_20260926_000001",
"mode": "references",
"aspect_ratio": "16:9",
"duration": 5,
"resolution": "720p"
}'
# 2. 查询任务状态
curl https://new.tangzhi.org/v1/videos/task_abc123def456 \
-H "Authorization: Bearer 你的_API_KEY"
# 3. 下载视频
curl -o output.mp4 https://new.tangzhi.org/v1/videos/task_abc123def456/content \
-H "Authorization: Bearer 你的_API_KEY"import time
import requests
BASE = "https://new.tangzhi.org"
HEADERS = {"Authorization": "Bearer 你的_API_KEY", "Content-Type": "application/json"}
# 1. 创建任务
resp = requests.post(f"{BASE}/v1/videos", headers=HEADERS, json={
"model": "ch0101-sd-2.0-720p",
"prompt": "人物向前走,背景流动变换",
"client_task_id": "order_20260926_000001",
"mode": "references",
"aspect_ratio": "16:9",
"duration": 5,
"resolution": "720p",
}, timeout=120)
resp.raise_for_status()
task_id = resp.json()["id"]
print(f"任务已创建:{task_id}")
# 2. 轮询任务状态
while True:
task = requests.get(f"{BASE}/v1/videos/{task_id}", headers=HEADERS, timeout=30).json()
print(f"状态: {task['status']} ({task.get('progress', 0)}%)")
if task["status"] in ("completed", "failed"):
break
time.sleep(10)
# 3. 下载视频
if task["status"] == "completed":
video = requests.get(f"{BASE}/v1/videos/{task_id}/content", headers=HEADERS, timeout=300).content
with open("output.mp4", "wb") as f:
f.write(video)
else:
print(f"失败: {task.get('error', {}).get('message', '未知原因')}")import { writeFile } from "node:fs/promises";
const BASE = "https://new.tangzhi.org";
const headers = { Authorization: "Bearer 你的_API_KEY", "Content-Type": "application/json" };
// 1. 创建任务
const created = await fetch(`${BASE}/v1/videos`, {
method: "POST",
headers,
body: JSON.stringify({
model: "ch0101-sd-2.0-720p",
prompt: "人物向前走,背景流动变换",
client_task_id: "order_20260926_000001",
mode: "references",
aspect_ratio: "16:9",
duration: 5,
resolution: "720p",
}),
}).then((r) => r.json());
// 2. 轮询任务状态
let task;
do {
await new Promise((r) => setTimeout(r, 10000));
task = await fetch(`${BASE}/v1/videos/${created.id}`, { headers }).then((r) => r.json());
console.log(task.status, task.progress);
} while (!["completed", "failed"].includes(task.status));
// 3. 下载视频
if (task.status === "completed") {
const video = await fetch(`${BASE}/v1/videos/${created.id}/content`, { headers });
await writeFile("output.mp4", Buffer.from(await video.arrayBuffer()));
}DOLA 渠道模型
doubao-seedance-2-0-260128 与 doubao-seedance-2-5-260628 走 DOLA 渠道,同样调用 POST /v1/videos,但请求体格式与上文不同。上方 请求构造器 选中这两个模型时会自动生成正确格式。
| 模型 | 分辨率 | 时长 | 参考素材 | 计费 |
|---|---|---|---|---|
doubao-seedance-2-0-260128 | 720p | 5 / 10 / 15 秒 | 图片最多 10 张,不支持音频、视频 | 按次 |
doubao-seedance-2-5-260628 | 720p | 5 / 10 / 30 秒 | 图片最多 10 张,不支持音频、视频 | 按次 |
{
"model": "doubao-seedance-2-5-260628",
"prompt": "一只橘色小猫在草地上追逐蝴蝶,阳光明媚",
"seconds": 10,
"images": ["https://example.com/ref1.jpg", "https://example.com/ref2.jpg"],
"metadata": { "ratio": "16:9", "resolution": "720p" }
}| 字段 | 必填 | 说明 |
|---|---|---|
model | 是 | 上表中的模型 ID |
prompt | 是 | 视频内容描述 |
seconds | 否 | 视频时长(秒),只能取上表中的档位;不传时默认 5 秒 |
images | 否 | 参考图公网 URL 数组,最多 10 张;不传即为文生视频 |
metadata.ratio | 否 | 16:9 / 9:16 / 1:1 / 4:3 / 3:4 |
metadata.resolution | 否 | 固定 720p |
seconds,不要用 duration:顶层的 duration 不会传到上游,任务会按默认 5 秒生成,但仍按次全额计费。不支持 mode、references、frames(首尾帧)和 client_task_id。查询任务与下载视频和其他模型一致:GET /v1/videos/:taskId、GET /v1/videos/:taskId/content。生成失败时 error.message 可能为空,任务会自动退款。
模型与定价
素材数量上限、时长范围、分辨率、人脸限制与价格,与控制台实时同步。