视频生成与编辑

视频任务采用异步模式:提交请求后立即返回 task_id,再通过 任务查询Webhook 回调 获取最终 mp4 结果。

视频能力分三类:

能力接口输入模型
文生视频/v1/video/generate文本omni_flash
图生视频/v1/video/generate图片 URL + 文本omni_flash_components
视频编辑/v1/video/edits视频 upload_id + 文本omni_flash_edit

视频生成和编辑请求使用模型族名加参数。生成类用 secondsresolution 表达时长和分辨率;编辑类用 resolution 表达输出分辨率。

创建 Auto Key 时只需要选择视频模型 omni_flash。文生视频、图生视频和视频编辑由具体接口、输入素材和请求参数区分;Token8 会在内部匹配对应的计费规格。

POST /v1/video/generate

提交文生视频或图生视频任务。

请求参数

参数类型必填说明
modelstring视频模型族。文生视频用 omni_flash,图生视频用 omni_flash_components
messagesarrayOpenAI chat 格式。文生视频可直接写字符串;图生视频使用 content[].image_url.url 传参考图
aspect_ratiostring16:99:16
secondsstring46810;默认 10
resolutionstring720p1080p4K;默认 720p
callback_urlstring任务完成后回调地址

文生视频示例

curl https://api.token8.pro/v1/video/generate \
  -H "Authorization: Bearer sk-你的AutoKey" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "omni_flash",
    "messages": [
      { "role": "user", "content": "A red cube rotating slowly on a clean white background" }
    ],
    "aspect_ratio": "16:9",
    "seconds": "8",
    "resolution": "1080p"
  }'

图生视频示例

图生视频需要先通过 图片上传接口 上传参考图,再把返回的 Token8 URL 放到 image_url.url

curl https://api.token8.pro/v1/video/generate \
  -H "Authorization: Bearer sk-你的AutoKey" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "omni_flash_components",
    "messages": [{
      "role": "user",
      "content": [
        { "type": "image_url", "image_url": { "url": "https://r2.token8.pro/uploads/.../reference.png" } },
        { "type": "text", "text": "Turn this product photo into a clean rotating studio video" }
      ]
    }],
    "aspect_ratio": "16:9",
    "seconds": "6",
    "resolution": "1080p"
  }'

参考图限制:

  • 最多 3 张。
  • 只使用 Token8 图片上传接口返回的 URL。

POST /v1/uploads/videos

上传视频供 /v1/video/edits 引用。上传本身不计费。

  • 返回的 upload_id 有效期 24 小时
  • 视频编辑时把 upload_id 放进 input_video

请求参数

参数类型必填说明
filefile视频文件,支持 MP4、WebM、MOV,最大 50MB

请求示例

curl https://api.token8.pro/v1/uploads/videos \
  -H "Authorization: Bearer sk-你的AutoKey" \
  -F "file=@./source.mp4"

响应

{
  "upload_id": "upload_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "url": "https://r2.token8.pro/uploads/.../source.mp4",
  "filename": "source.mp4",
  "content_type": "video/mp4",
  "bytes": 504237,
  "created_at": 1714450000,
  "expires_at": 1714536400
}

POST /v1/video/edits

提交视频编辑任务。请先通过 视频上传接口 上传源视频,再把返回的 upload_id 传给 input_video

请求参数

参数类型必填说明
modelstring视频编辑模型族,如 omni_flash_edit
messagesarray编辑指令,OpenAI chat 格式
input_videoobject视频上传接口返回的 { "upload_id": "..." }
aspect_ratiostring16:99:16
resolutionstring720p1080p4K;默认 720p
callback_urlstring任务完成后回调地址

编辑示例

curl https://api.token8.pro/v1/video/edits \
  -H "Authorization: Bearer sk-你的AutoKey" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "omni_flash_edit",
    "input_video": { "upload_id": "upload_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" },
    "messages": [
      { "role": "user", "content": "Change the cube color to blue while keeping the same clean rotating scene" }
    ],
    "aspect_ratio": "16:9",
    "resolution": "1080p"
  }'

响应 202

{
  "task_id": "task_abc123def456",
  "status": "pending",
  "model": "omni_flash",
  "normalized_model": "omni_flash_8s_1080p",
  "operation": "video_generation",
  "media_type": "video",
  "created_at": 1714450000
}

normalized_model 表示本次请求实际匹配到的规格,便于对账和排查。

获取结果

使用 任务查询 轮询,或传 callback_url 接收 Webhook 回调。完成后 data[0].url 指向可访问的 mp4 文件。