API 对接文档 · v1
Long Video 生成 API
一句话 prompt 生成最长 180 秒的成片。本接口为异步任务模型:创建任务后,通过轮询或 Webhook 获取进度与成片地址。下文覆盖全部对外接口、认证方式、回调与计费。
概览 Overview
- Base URL:所有接口以
/v1为前缀,生产环境 base 为你的部署域名(例https://your-domain.com/v1/videos)。 - Content-Type:请求与响应均为
application/json。 - 流程:
POST /v1/videos创建任务 → 轮询GET /v1/videos/{id}或等待 Webhook →result_url即成片。
认证 Authentication
所有 /v1 接口都需要 Bearer API 密钥。
在请求头携带 Authorization: Bearer sk-...。密钥以哈希存储,缺失、格式错误或未知/停用密钥统一返回 401 invalid_api_key。
Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json幂等 Idempotency
创建任务时可携带 Idempotency-Key 请求头(建议用 UUID)。同一密钥 + 相同 key 的重复请求不会重复创建,而是直接返回已存在任务的 202。强烈建议在创建时带上,以避免网络重试导致重复扣费。
创建任务 Create
任务列表 List
查询任务 Get
取消任务 Cancel
重新合成 Compose
余额 Credits
任务状态机 Status
GET /v1/videos/{id} 返回的 status 取值。
| status | 说明 |
|---|---|
queued | 已入队,等待开始 |
scripting | 生成分镜脚本(Claude) |
moderation | 内容安全审核 |
anchoring | 角色锚定(生成参考图) |
generating | 分段视频生成中 |
audio | 生成旁白 / 配乐 |
composing | 合成成片 |
delivering | 上传交付 |
completed | 成功,result_url 就绪 —— 终态 |
failed | 失败,error 就绪 —— 终态 |
canceled | 已取消 —— 终态 |
严格失败:任一分段失败会使整个任务转为 failed,未使用的 credits 自动退回。
Webhook 回调
任务进入终态(completed / failed / canceled)且设置了 webhook_url 时,服务端 POST 一个 JSON。
回调请求体
{
"task_id": "vid_abc",
"status": "completed",
"result_url": "https://.../final.mp4",
"duration": 60,
"cost_actual": 1650,
"error": null,
"metadata": { "user_ref": "..." }
}重试:尽力而为,间隔 0 / 1s / 5s,三次仍失败即放弃。请同时用轮询 GET /v1/videos/{id} 兜底。
错误码 Errors
所有错误响应体统一为 { error: { code, message } }。
| code | HTTP | 说明 |
|---|---|---|
invalid_api_key | 401 | 缺失或无效的 Bearer 密钥 |
invalid_request | 400 | 请求体校验失败 / provider 不支持该清晰度 |
insufficient_credits | 402 | 余额不足 |
task_not_found | 404 | 任务不存在或不属于该密钥 |
not_composable | 409 | 当前状态不可重新合成 |
no_segments | 409 | 任务无可合成分段 |
segments_not_ready | 409 | 部分分段尚未就绪(含 details.missing) |
internal_error | 500 | 服务端内部错误 |
{ "error": { "code": "invalid_request", "message": "duration: Number must be ..." } }计费与限制 Billing
- 计费单位为 credits。HappyHorse 费率:720p 27.5 / 秒,1080p 47.2 / 秒。
cost_estimate:把duration按 ≤8s 分段,每段按 provider 费率计价后累加。例:60s × 720p ≈ 1650 credits。- 创建任务即预扣 cost_estimate;任务失败自动退回未使用部分;取消按已完成分段结算后退回余额。
- 限制:
duration3–180 秒;单段 ≤8 秒。
快速开始 Quickstart
1 · 创建任务并轮询(bash)
BASE="https://your-domain.com"
KEY="sk-..."
TASK=$(curl -s -X POST $BASE/v1/videos \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{ "prompt": "城市清晨的延时风光", "duration": 30 }' | jq -r .task_id)
# 轮询直到 completed / failed
while true; do
curl -s $BASE/v1/videos/$TASK -H "Authorization: Bearer $KEY" | jq '{status, progress, shots_done, shots_total, result_url}'
sleep 5
done2 · Node.js(fetch)
const BASE = 'https://your-domain.com';
const KEY = process.env.LONGVIDEO_KEY;
const res = await fetch(`${BASE}/v1/videos`, {
method: 'POST',
headers: {
Authorization: `Bearer ${KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': crypto.randomUUID(),
},
body: JSON.stringify({ prompt: '城市清晨的延时风光', duration: 30 }),
});
const { task_id } = await res.json();
// 之后轮询 GET /v1/videos/${task_id},或在 webhook_url 接收完成回调