跳到主要内容

提交视频生成请求

POST 

https://api.knox.chat/v1/videos

提交一个异步视频生成任务。视频生成不是流式对话补全 —— API 会立即接受请求(202 Accepted)并返回任务 ID。请轮询 GET /v1/videos/{jobId} 直到 statuscompleted,再通过 GET /v1/videos/{jobId}/content 下载视频字节。

使用 GET /v1/videos/models 发现可用模型,以及每个模型支持的分辨率、宽高比、时长和帧图像类型。

请求

此端点需要一个 JSON 对象。

请求头

名称类型必填描述
AuthorizationStringBearer 认证,格式为 Bearer <token>,其中 token 是您的 Knox Chat API key。
Content-TypeString必须为 application/json

请求体

名称类型必填描述
modelString视频模型 ID,来自 GET /v1/videos/models,例如 google/veo-3.1
promptString条件必填视频的文本描述。除非通过 frame_imagesinput_references 提供了图片输入,否则必填。
aspect_ratioString输出宽高比。可选值:16:99:161:14:33:43:22:321:99:21。同时必须出现在该模型的 supported_aspect_ratios 中。
durationInteger视频时长(秒)。必须至少为 1;当模型提供 supported_durations 时,取值必须在该列表中。
resolutionString输出分辨率。可选值:480p720p768p1080p1K2K4K。同时必须出现在该模型的 supported_resolutions 中。
sizeString精确像素尺寸,格式为 宽x高,例如 1280x720。当模型提供 supported_sizes 时,用此字段代替 resolution
generate_audioBooleantrue 时同时生成音轨。仅当模型报告 generate_audio: true 时有效。
seedInteger确定性随机种子。当模型报告 seed: false 时会被拒绝。
callback_urlString任务到达终态时回调的 HTTPS webhook。HTTP URL 会被拒绝。
frame_images对象列表用于图生视频的首/尾帧图片。每个对象必须包含 frame_typefirst_framelast_frame)以及图片数据。frame_type 必须出现在模型的 supported_frame_images 中。
input_references对象列表额外媒体参考。图生视频使用 { "type": "image_url", "image_url": { "url": "..." } };参考视频使用 { "type": "video_url", "video_url": { "url": "..." } }

仅当通过 frame_imagestype: "image_url"input_references 提供了至少一张图片时,才可以省略 prompt

cURL 示例

文生视频

curl -X POST https://api.knox.chat/v1/videos \
-H "Authorization: Bearer $KNOXCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/veo-3.1",
"prompt": "日落时分宁静的山地风景,电影感镜头缓缓推移",
"aspect_ratio": "16:9",
"duration": 8,
"resolution": "720p",
"generate_audio": true
}'

图生视频

curl -X POST https://api.knox.chat/v1/videos \
-H "Authorization: Bearer $KNOXCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/veo-3.1",
"prompt": "将这张静帧动画化为缓慢的电影感推进镜头",
"aspect_ratio": "16:9",
"duration": 8,
"resolution": "720p",
"frame_images": [
{
"frame_type": "first_frame",
"image_url": {
"url": "https://example.com/first-frame.png"
}
}
]
}'

参考视频

curl -X POST https://api.knox.chat/v1/videos \
-H "Authorization: Bearer $KNOXCHAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/veo-3.1",
"prompt": "保持相同的镜头运动和角色,但将场景改为夜晚",
"input_references": [
{
"type": "video_url",
"video_url": {
"url": "https://example.com/reference.mp4"
}
}
]
}'

响应

成功响应 (202 Accepted)

{
"generation_id": "gen-8f2c1a9b4d6e7f01",
"id": "job-3c91a0e8b7d24f11",
"polling_url": "/v1/videos/job-3c91a0e8b7d24f11",
"status": "pending"
}

请保存 id,并对 polling_url(相对于 https://api.knox.chat)进行轮询,直到任务结束。不要把 202 当作视频已经生成完成 —— unsigned_urlsusage 仅在任务完成后才会出现。

响应 Schema

名称类型描述
generation_idstring唯一的生成标识符(gen-...)。任务被接受后即会返回。
idstring任务 ID(job-...)。轮询和下载请求都使用该路径参数。
polling_urlstring状态轮询的相对 URL,例如 /v1/videos/job-3c91a0e8b7d24f11
statusstring当前任务状态。参见 任务状态
errorstringstatusfailed 时的错误信息。其他情况下省略。
unsigned_urls字符串数组任务为 completed 时可下载的视频 URL。由 Knox Chat 托管(绝不会返回上游供应商 URL)。
usageobject任务完成后的计费信息。
usage.costnumber本次生成的费用(美元)。

任务状态

状态含义
pending任务已被接受,正在等待开始。
in_progress模型正在生成视频。
completed视频已就绪。可下载或使用 unsigned_urls
failed生成失败。查看 error。失败任务不会扣费。
cancelled任务已取消。
expired任务在完成前已过期。

错误响应

视频端点的错误格式如下:

{
"error": {
"code": 400,
"message": "Invalid request parameters"
}
}
状态码消息触发条件
400Invalid request parameters缺少 model、JSON 无效,或字段不被该模型支持。
400Prompt is required unless image input is provided既没有 prompt 也没有图片输入。
400Unsupported aspect_ratio / resolution / size取值不在全局允许列表中。
400aspect_ratio … is not supported by {model}取值全局合法,但该模型不支持。
400callback_url must be HTTPSWebhook URL 不是 HTTPS。
401Missing Authentication header缺少或无效的 API key。
402Insufficient credits. Add more using https://knox.chat/credits账户余额不足以覆盖预估费用。
403This token is not authorized to use model: {model}该 API key 的模型白名单不包含此视频模型。
404Resource not found未知或已禁用的模型 ID。
429Rate limit exceeded请求过于频繁。
500Internal Server Error未预期的服务器错误。