sglang /v1/videos 视频生成接口 完整文档解析

12次阅读
没有评论

一、接口基础信息

  • 请求方式POST
  • 接口路径/v1/videos
  • 接口用途:提交任务创建 AI 生成视频任务
  • 请求编码格式multipart/form-data(表单文件上传格式)
  • 无 URL Query 参数,所有入参全部放在请求体表单

二、请求体全部入参说明

表格

参数名 类型 允许为空 参数含义
prompt string | null 正向提示词,画面、镜头、内容描述核心文案
input_reference string | null 参考图 / 参考素材本地文件标识(本地上传资源用)
reference_url string | null 在线参考素材网络地址,用于图生视频、视频续画
model string | null 指定生成模型,示例返回默认 sora-2
n integer | null 本次批量生成几组任务
num_outputs_per_prompt integer | null 单条提示词输出视频数量
seconds integer | null 视频总时长(秒)
size string | null 分辨率尺寸,格式示例:1280x720 / 720x1280
fps integer | null 视频帧率
num_frames integer | null 总帧数,优先级高于 seconds
seed integer | null 随机种子,固定种子可复现相同生成结果
generator_device string | null 指定推理硬件设备,如 cuda:0
negative_prompt string | null 反向提示词,规避画面瑕疵、畸变、水印、模糊等
guidance_scale number | null 提示词引导强度,数值越大越贴合 prompt
num_inference_steps integer | null 扩散推理步数,步数越高画质越好、速度越慢
max_sequence_length integer | null 文本编码最大序列长度,控制提示词字数上限
flow_shift number | null 流偏移参数,优化视频动态流畅度
enable_teacache boolean | null 开启 TeaCache 加速推理,降低显存占用、提速
enable_frame_interpolation boolean | null 开启插帧补帧,提升视频顺滑度
frame_interpolation_exp integer | null 插帧指数,控制插帧倍率
frame_interpolation_scale number | null 插帧缩放系数
frame_interpolation_model_path string | null 插帧模型本地路径
enable_upscaling boolean | null 开启超分辨率高清放大
upscaling_model_path string | null 放大模型路径
upscaling_scale integer | null 画面放大倍数(2/4 倍等)
output_quality string | null 输出画质档位:standard/high/low
output_compression integer | null 视频压缩率,数值越大压缩越强、体积越小
output_path string | null 服务器本地视频存储路径
extra_params string | null 额外自定义参数 JSON 字符串
extra_body string | null 扩展业务字段 JSON 字符串

三、返回状态码与响应结构

1. 200 成功提交任务(入参校验通过,任务进入队列)

json

{
  "id": "string",                  // 任务唯一ID,后续查进度/查结果必备
  "object": "video",               // 对象固定标识
  "model": "sora-2",               // 使用的模型名称
  "status": "queued",              // 任务状态:queued排队 / running生成中 / completed完成 / failed失败
  "progress": 0,                   // 生成进度 0~100
  "created_at": 0,                 // 任务创建时间戳
  "size": "",                      // 输出分辨率
  "seconds": "4",                  // 设定视频时长
  "quality": "standard",           // 输出画质等级
  "url": "string",                 // 生成后视频可访问下载链接
  "remixed_from_video_id": "string",// 溯源上一条衍生视频ID
  "completed_at": 0,               // 任务完成时间戳
  "expires_at": 0,                 // 链接过期时间戳
  "error": {},                     // 错误详情,失败时填充
  "file_path": "string",           // 单文件服务器路径
  "file_paths": ["string"],        // 多视频输出文件路径数组
  "num_outputs": 0,                // 实际输出视频条数
  "peak_memory_mb": 0,             // 推理峰值显存占用MB
  "inference_time_s": 0            // 推理耗时秒数
}

2. 422 参数校验错误

入参类型非法、必填项缺失、数值越界、格式错误时返回:

json

{
  "detail": [
    {
      "loc": ["参数层级", 索引],
      "msg": "具体错误说明",
      "type": "错误类型",
      "input": "传入的错误值",
      "ctx": {}
    }
  ]
}

四、curl 请求示例(可直接复制调试)

bash

运行

curl --location --request POST 'http://接口域名/v1/videos' \
--form 'prompt="A cat walking on grass, cinematic lighting"' \
--form 'model="sora-2"' \
--form 'seconds="4"' \
--form 'size="1080x1920"' \
--form 'fps="24"' \
--form 'negative_prompt="blurry, deformed, watermark"' \
--form 'guidance_scale=7.5' \
--form 'num_inference_steps=30'

五、常规业务调用流程

  1. 调用本接口提交生成任务,拿到返回的 id
  2. 轮询任务查询接口(一般为 /v1/videos/{task_id})获取 statusprogress
  3. 状态变为 completed 后,读取 url / file_paths 获取成品视频
  4. status=failed,读取 error 字段排查失败原因
正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)
验证码