跳到正文

可灵:视频生成 API

用可灵生成视频:文生与图生视频、主体参考、动作控制、数字人与对口型的型号、参数、返回结果与报错。

可灵从文本、图片、视频和主体生成视频,也支持动作控制、数字人与对口型:提交任务后用 HopBase 任务 ID 轮询结果。

项目值
Base URLhttps://api.hop-base.com/v1
提交视频任务POST /v1/video/generate
查询任务GET /v1/video/tasks/{task_id}
任务列表GET /v1/video/tasks
自定义主体POST / GET /v1/kling/subjects
对口型人脸识别POST /v1/kling/faces(按次计费)
密钥分组「可灵模型分组(官方)」

可灵生图与扩图也是异步任务:用 POST /v1/images/generations 提交,用 GET /v1/video/tasks/{task_id} 查询。型号、参数、返回与报错见可灵生图。

可用型号

正式产生付费任务前,先用 GET /v1/models 确认当前密钥实际返回的完整模型 ID。

模型 ID时长分辨率声音官方价
kling-v3-turbo3–15 秒720p / 1080p / 2k / 4k单一价格档$0.1176起/ 秒
kling-v3-omni3–15 秒720p / 1080p / 2k / 4k有声 / 无声$0.0882起/ 秒
kling-v33–15 秒720p / 1080p / 2k / 4k有声 / 无声$0.0882起/ 秒
kling-o13–10 秒720p / 1080p / 2k / 4k只能无声$0.0882起/ 秒
kling-v2-65 / 10 秒720p / 1080p / 2k / 4k有声 / 无声$0.0441起/ 秒
kling-v2-5-turbo5–10 秒720p / 1080p只能无声$0.0441起/ 秒
kling-v2-1、kling-v2-05–10 秒720p / 1080p / 2k / 4k只能无声$0.0588起/ 秒
kling-v1-65–10 秒720p / 1080p / 2k / 4k只能无声$0.0588起/ 秒
kling-v3-motion-control输入素材时长720p / 1080p / 2k / 4k不生成声音$0.1324起/ 秒
kling-v2-6-motion-control输入素材时长720p / 1080p不生成声音$0.0735起/ 秒
kling-avatar输入音频时长720p / 1080p来自输入音频$0.0588起/ 秒
kling-lip-sync输入素材时长不影响计价来自输入音频$0.0147/ 秒

表外的分辨率 / 声音组合在提交时返回 400。每个型号的分档价与完整规格见模型卡,例如 kling-v3、kling-v3-omni、kling-lip-sync。

  • kling-v3-turbo 是官方固定 Voice 价格档,audio 不影响计价,调用方不能指定音色。
  • kling-v3-omni 带 feature 参考视频时只能无声,分辨率为 720p / 1080p / 2k。
  • kling-o1 没有参考生输入时只支持 5 或 10 秒。
  • kling-v2-6 有声时 1080p 起,有声 720P 未定价。
  • kling-v1-6 的 base 视频编辑不看 audio。

模型矩阵

各视频模型支持的素材:

模型 ID参考图参考视频主体分镜
kling-v3-turbo不支持不支持支持不支持
kling-v3-omni最多 7 张feature支持支持
kling-v3最多 6 张不支持支持支持
kling-o1最多 4 张feature不支持不支持
kling-v2-6最多 4 张不支持不支持不支持
kling-v2-5-turbo最多 3 张不支持不支持不支持
kling-v2-1、kling-v2-0不支持不支持不支持不支持
kling-v1-6不支持base不支持不支持
kling-v3-motion-control、kling-v2-6-motion-control1 图 + 1 视频场景确定不支持不支持
kling-avatar1-5 张不支持不支持不支持
kling-lip-sync不支持不支持不支持不支持
  • “参考图”只统计 usage: reference,不包含首尾帧,不是所有 images[] 的总数。
  • kling-v3-omni 的 base 未定价,4K 无声 feature 未定价。
  • kling-v1-6 的待编辑视频使用 multi_elements 桶。

请求参数

所有请求都带 Authorization: Bearer sk-你的密钥 和 Content-Type: application/json。请求体只接受本页列出的字段:表外字段、嵌套对象里的未知字段、请求体后面跟着的第二个 JSON 值,都会在任务创建前返回 400,不计费。

参数必填类型与限制默认值说明
model必填上方型号表中的 ID—决定时长、分辨率与素材限制
prompt无素材时必填≤ 2,500 字符—仅在有 images / videos 时可为空
duration可选整数秒,范围见型号表5动作控制、数字人、对口型必须省略
resolution可选720p / 1080p / 2k / 4k720p不区分大小写,须为该模型支持的值
aspect_ratio可选16:9 / 9:16 / 1:1—省略时网关不代填
audio可选布尔值false随视频生成音轨,仅型号表标注支持声音的模型可用
images可选数组,每项 url / file_id 二选一—首尾帧、参考图、人物图
videos可选数组,最多一项—参考视频、待编辑视频、动作视频
subjects可选数组,每项非空 id—仅 kling-v3-turbo、kling-v3、kling-v3-omni
shots可选对象—分镜,仅 kling-v3 和 kling-v3-omni
extra可选对象—仅动作控制、数字人、对口型使用
voice_ids—暂不可用—非空即返回 400
  • prompt 的长度由可灵在任务执行中校验。
  • 普通视频模型传任何 extra 键都返回 400。
  • 视频画面请用 resolution 与 aspect_ratio 指定,不要带 OpenAI 习惯的 size、response_format、user,视频请求里的 n,或顶层的 image_url / video_url。

视频请求的全部字段见 API 参考提交视频任务(选「可灵」)。

素材定位

每个 images[] 或 videos[] 项必须且只能提供 url 或 file_id 其中之一:

{ "url": "https://cdn.example.com/file.png" }
{ "file_id": "your-file-id" }

url 必须是公网可访问的绝对 http:// 或 https:// 地址。图片接口、人脸识别与数字人的 extra.sound_file 也遵循同一规则。下列写法会在提交时同步拒绝:

  • 空字符串或相对路径。
  • file://、ftp:// 等非 HTTP(S) 协议。
  • 指向内网、回环或链路本地的地址。
  • 带认证信息的 URL。
  • 同时提供 url 和 file_id。

文生与图生视频

普通视频模型支持文生视频、首尾帧、参考图、参考视频和视频编辑。图片放进 images[],视频放进 videos[];只传 prompt 就是文生视频。

每张图用 usage 标明角色:first_frame、last_frame 或 reference。

{
  "model": "kling-v3-omni",
  "prompt": "<<<element_1>>> 和 <<<element_2>>> 在干净的摄影棚桌面上缓慢旋转",
  "duration": 5,
  "resolution": "1080p",
  "images": [
    { "url": "https://cdn.example.com/first.png", "usage": "first_frame" },
    { "file_id": "last-frame-file-id", "usage": "last_frame" },
    { "url": "https://cdn.example.com/reference-a.png", "usage": "reference" }
  ]
}
  • 首帧和尾帧各最多一张。
  • 指定尾帧必须同时提供首帧。
  • 参考图超过两张时不能再指定尾帧。
  • kling-v2-1 同时提供首尾帧时,resolution 只能为 1080p。
  • 参考图上限见型号表,只统计 usage: reference。

videos[] 最多一项,且必须带 reference_type:

{
  "videos": [
    {
      "url": "https://cdn.example.com/character-motion.mp4",
      "reference_type": "feature",
      "keep_original_sound": false
    }
  ]
}
  • feature 是参考视频,仅 kling-v3-omni 和 kling-o1 开放。
  • base 是视频编辑,仅已实测且有价的 kling-v1-6 开放。
  • base 必须是唯一素材,不能和图片或主体混用。
  • keep_original_sound 是布尔值,保留源视频的原声。

主体与分镜

subjects[] 使用官方固定主体 ID,只有 kling-v3-turbo、kling-v3、kling-v3-omni 支持主体。

{
  "subjects": [
    { "id": "subject-92951593344", "name": "猫" },
    { "id": "subject-92951593345", "name": "狗" }
  ]
}
  • 每项必须有非空 id,name 可选。
  • 主体按数组位置绑定:subjects[0] 对应 <<<element_1>>>,依此类推。
  • 每个已提供的主体都必须在 Prompt 中被引用。
  • Prompt 不能引用不存在的 <<<element_N>>>。
  • 对 kling-v3,提供主体时 images[] 至少要有一项 usage: "reference"。

分镜仅 kling-v3 和 kling-v3-omni 支持:

{
  "model": "kling-v3-omni",
  "prompt": "两段式产品展示短片",
  "duration": 5,
  "shots": {
    "mode": "customize",
    "segments": [
      { "index": 1, "prompt": "盒子打开", "duration": 2 },
      { "index": 2, "prompt": "产品出现", "duration": 3 }
    ]
  }
}
  • mode 可取 intelligence 或 customize。
  • 智能模式不能带 segments,自定义模式必须带分镜。
  • 自定义分镜最多 6 段,从 1 开始连续编号。
  • 每段提示词不能为空,且不超过 512 字。
  • 每段至少 1 秒,各段时长之和必须严格等于总时长。
  • 请使用结构化 shots,extra.multi_shot、extra.shot_type、extra.multi_prompt 会被拒绝。

创建自定义主体

POST /v1/kling/subjects 创建自定义主体,得到的主体 ID 可填入 subjects[].id。GET 同一路径查询已有主体。

字段必填取值
name必填≤ 20 个字符
description可选≤ 100 个字符
reference_type必填image_refer / video_refer
frontal_image_urlimage_refer 必填正面图地址
reference_image_urlsimage_refer 必填1–3 个地址
video_urlvideo_refer 必填视频地址
voice_id可选,仅 video_refer绑定到主体的音色
tag_ids可选字符串数组
  • image_refer 用图片创建主体,video_refer 用一段视频创建。
  • 所有地址都必须是公网 HTTP(S) 地址,规则与「素材定位」相同。
  • reference_image_urls 不能与正面图重复,彼此也不能重复。
  • video_refer 不能带任何图片字段,image_refer 不能带 video_url。
  • tag_ids 用于归类主体,每项非空且不重复。

创建是异步任务:提交返回 202 与 id(object 为 kling.subject.task),用 GET /v1/video/tasks/{task_id} 轮询。完成后结果里带 element_ids 与 elements。

动作控制

动作控制让人物图跟随一段视频的动作,需要恰好一个视频和一张人物图。这类任务的时长由输入素材决定,必须省略 duration。

{
  "model": "kling-v3-motion-control",
  "prompt": "跟随舞者的动作",
  "resolution": "1080p",
  "images": [{ "file_id": "person-image-file-id" }],
  "videos": [{ "url": "https://cdn.example.com/dance.mp4", "keep_original_sound": true }],
  "extra": { "character_orientation": "video" }
}
  • 场景决定两者含义,所以图片不能带 usage,视频不能带 reference_type。
  • videos[].keep_original_sound 是布尔值,对应官方的 keep_original_sound 标记。
  • 目前唯一验证过的额外参数是 extra.character_orientation(image 或 video)。
  • 产物使用临时存储。

数字人

数字人(kling-avatar)让人物图按一段音频说话,时长由输入音频决定,必须省略 duration。

  • 需要 1-5 张人物图,不接受视频。
  • 必须在 extra.sound_file(HTTP(S) 音频地址)和 extra.audio_id 中二选一。

对口型

对口型(kling-lip-sync)替视频里的人脸换上新的口型,不接受图片或视频。分两步:先识别人脸,再提交任务。

第一步,用一个或多个素材调用人脸识别。请求体只接受 videos 数组,每项 url / file_id 二选一,规则与「素材定位」相同。

curl https://api.hop-base.com/v1/kling/faces \
  -H "Authorization: Bearer sk-你的密钥" \
  -H "Content-Type: application/json" \
  -d '{"videos":[{"file_id":"source-video-file-id"}]}'

第二步,提交返回的 session 和一个 face_choose 项:

{
  "model": "kling-lip-sync",
  "extra": {
    "session_id": "face-session-id",
    "face_choose": [
      { "face_id": "face-1", "sound_file": "https://cdn.example.com/voice.mp3" }
    ]
  }
}
  • face_choose 必须恰好一项,且包含非空 face_id 与 sound_file。
  • 时长由输入音频 / 视频决定,必须省略 duration。
  • 官方确认对应 SKU 前,voice_ids 和 extra.voice_list 均不可用。

返回结果

可灵的任务字段在响应顶层,不像 Seedance 那样包在 task 里。

提交响应

提交成功返回 202,任务 ID 在 id 字段,形如 kt57x<task-id>。可灵生图同样返回 202 与同样形态的 id,两者查询方式相同。

{
  "id": "ktEXAMPLE",
  "object": "video.generation.task",
  "model": "kling-v3",
  "status": "queued",
  "created": 1790000000,
  "billing_bucket": "720p_silent_noref"
}

任务查询字段

字段说明
idHopBase 任务 ID,kt…
object视频与生图任务为 video.generation.task,自定义主体为 kling.subject.task
statusqueued → processing → completed 或 failed;只有后两者是终态
progress进度
outputs完成后的成片地址,URL 字符串数组
usage完成后的计量:bucket,加上视频的 billed_seconds 或生图的 billed_images
usage.cost / usage.cost_usd / usage.currency本任务扣费:cost_usd 为从余额实际扣除的美元金额,cost 为同一笔的人民币金额,currency 恒为 CNY
element_ids / elements自定义主体任务完成后的主体
error.code失败时的稳定错误码,见下方「任务失败」
error.message失败时措辞固定的英文说明

除 completed 与 failed 之外的任何值都按进行中处理。查询时不要传计费标头。

任务结束后,查询响应根对象的 usage 还会带 cost_usd(本任务从余额实际扣除的美元金额,未扣费的失败为 0)、cost(同一笔的人民币金额)与 currency(恒为 CNY),详见视频总览。任务列表(GET /v1/video/tasks)里每个终态任务的 usage 也带同样的 cost、cost_usd 与 currency。

进行中

{
  "id": "ktEXAMPLE",
  "object": "video.generation.task",
  "model": "kling-v3",
  "status": "processing",
  "created": 1790000000
}

成功

完成后从 outputs 取地址:

{
  "id": "ktEXAMPLE",
  "status": "completed",
  "outputs": [
    "https://api.hop-base.com/example-signed-image.png"
  ],
  "usage": { "bucket": "720p_silent_noref", "billed_seconds": 5, "cost": 2.55, "cost_usd": 0.375, "currency": "CNY" }
}

地址在 api.hop-base.com 域名下,是自任务完成起 24 小时有效的签名链接。再次查询返回同一地址、不会续期,过期访问返回 410,请在 24 小时内下载保存。

失败

任务失败时,查询接口仍返回 HTTP 200,status 为 failed。error.code 是稳定错误码,error.message 是措辞固定的英文说明。

{
  "id": "ktEXAMPLE",
  "object": "video.generation.task",
  "model": "kling-v3",
  "status": "failed",
  "created": 1790000000,
  "error": {
    "code": "timeout",
    "message": "task did not reach a billable terminal state within 2 hours; polling stopped"
  }
}

请按 status 判断成败,按 error.code 分支处理,并展示 error.message。较早失败的任务可能没有 error.code。

情况error.code
提示词或参考素材未通过审核input_sensitive
产出被审核拦下output_video_sensitive(生图为 safety_rejected)
并发已满rate_limited
模型版本已下架unsupported_model
提示词过长,或参数、素材不合规invalid_request
参考素材读取失败reference_input_invalid
生成失败或中途被终止generation_failed
创建 2 小时后仍未结束timeout
任务结束但没有产出no_output

最小示例

下面提交一个 5 秒 720p 的文生视频任务,再轮询到结束。

# 1. 提交
curl https://api.hop-base.com/v1/video/generate \
  -H "Authorization: Bearer sk-你的密钥" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-v3",
    "prompt": "红球在白桌面上滚动",
    "duration": 5,
    "resolution": "720p"
  }'

# 2. 用返回的 id 轮询
curl https://api.hop-base.com/v1/video/tasks/kt57xYOUR_TASK_ID \
  -H "Authorization: Bearer sk-你的密钥"

注意事项

不合规素材会在提交数分钟后才失败:

网关只校验请求结构与数量,素材的分辨率、格式、大小、时长由官方在任务执行时异步校验。提交前请确认素材可被公网稳定下载,并符合可灵官方的规格要求。

  • 可灵任务(含生图)创建 2 小时后仍未结束即判为失败、不计费。
  • 任务不支持取消,其余通用规则见视频总览。
  • 结果链接自任务完成起 24 小时有效,不会续期。
  • 动作控制、数字人与对口型的时长由输入素材决定,必须省略 duration。

余额预留

余额预留只作用于视频提交,生图没有:

提交可灵视频任务时按「可用余额 − 进行中任务的预估费用 − 本次预估费用」判断,不足返回 402。可灵生图不做预留,只在余额小于等于 0 时才会被拦截。

余额不足时 code 为 insufficient_balance,任务结束后预估自动释放。对口型(kling-lip-sync)无法提前估算,不做预留。

常见报错 → 改法

提交阶段出错不会创建任务,也不计费,原因写在 error.message 里。400 的 type 为 invalid_request_error,402 的 code 为 insufficient_balance。

HTTP情况处理
400字段、取值或组合不合法按报错修改后重新提交
400把生图模型发到视频接口改用生图接口
402视频余额预留不足充值,或等进行中的任务结束
404模型 ID 不在目录用 GET /v1/models 核对 ID
429 / 5xx服务繁忙或暂时不可用稍后重试

带了 size 等表外字段时的原样报错(人脸识别接口相同):

{
  "error": {
    "message": "request body does not match the JSON contract: json: unknown field \"size\"",
    "type": "invalid_request_error"
  }
}

其余几种的 error.message 原文:

# 把生图模型发到视频接口(400)
model "<模型 ID>" is an image model; use /v1/images/generations

# 视频模型 ID 不在目录(404)
model "<模型 ID>" is not in the Kling catalog

# 生图模型 ID 不在目录(404)
model "<模型 ID>" is not an image model in this catalog

素材与通用参数

# 素材 url / file_id 都没有或都有
<images 或 videos>[<序号>] must provide exactly one of url or file_id

# url 不是公网 http(s) 绝对地址
<images 或 videos>[<序号>].url must be a publicly accessible absolute http(s) URL

# 没有 prompt 也没有任何素材(对口型除外)
prompt and input media cannot both be empty

# duration 为负数
duration cannot be negative

# duration 超出型号范围
model <模型 ID> supports <下限> to <上限> seconds, got <值>

# kling-o1 没有参考生输入时 duration 不是 5 或 10
Kling O1 without reference media only supports duration 5 or 10 seconds

# kling-v2-6 的 duration 不是 5 或 10
model kling-v2-6 only supports a duration of 5 or 10 seconds, got <值>

# aspect_ratio 不在 16:9 / 9:16 / 1:1 之内
aspect_ratio="<值>" is invalid; allowed values: 16:9 / 9:16 / 1:1

# 分辨率 / 声音 / 参考视频组合没有对应价格档
model "<模型 ID>" does not support billing bucket "<档位>" for this request

# voice_ids 非空(报错以此开头)
voice_ids is not available yet

# extra 含该型号不接受的键
extra.<键> is not in the verified parameter contract of model <模型 ID>

# 时长由素材决定的型号传了 duration
duration of model <模型 ID> is determined by the input media; do not pass duration

首尾帧、参考图与参考视频

# usage 缺失或取值不合法
images[<序号>].usage is required for standard Kling video requests
images[<序号>].usage="<值>" is invalid; allowed values: first_frame / last_frame / reference

# 首尾帧规则
at most 1 first-frame image is allowed
at most 1 last-frame image is allowed
a last frame requires a first frame with usage=first_frame
Kling 2.1 first/last-frame generation only supports 1080p
a last frame is not supported with more than 2 reference images (got <张数>)

# 参考图数量
with a reference video, reference images + subjects cannot exceed 4, got <总数> (<图数> images + <主体数> subjects)
without a reference video, reference images + subjects cannot exceed 7, got <总数> (<图数> images + <主体数> subjects)
model <模型 ID> supports at most <上限> reference images, got <张数>
model <模型 ID> does not support reference-based generation

# reference_type 缺失或取值不合法,或视频多于 1 个
videos[0].reference_type is required for standard Kling video requests; allowed values: feature / base
videos[<序号>].reference_type="<值>" is invalid; allowed values: feature / base
standard Kling video requests accept at most 1 videos input

# 参考视频类型不被该型号支持,或 base 与图片 / 主体混用
model <模型 ID> has no confirmed feature reference-video capability or price tier
model <模型 ID> has no confirmed base video-edit price tier
base video edit cannot be combined with images or subjects; only a single video to edit is accepted

# 原声参数写进了 extra
extra.keep_original_sound cannot be passed through; use videos[].keep_original_sound

动作控制、数字人与对口型

# 动作控制
motion control requires exactly 1 motion video and 1 character image
motion control images[<序号>] does not accept usage; the character image role is fixed by the scene
motion control videos[<序号>] does not accept reference_type; the motion video role is fixed by the scene
extra.character_orientation must be image or video

# 数字人
Kling avatar requires at least 1 character image
model <模型 ID> supports at most 5 character images, got <张数>
Kling avatar does not accept videos input
Kling avatar requires exactly one of extra.sound_file or extra.audio_id
extra.sound_file must be a non-empty string
extra.audio_id must be a non-empty string
extra.sound_file must be a publicly accessible http(s) audio URL

# 人脸识别:JSON 不合法或带了其他字段
request body does not match the JSON contract: …

# 人脸识别:缺少 videos 或数组为空
videos is required and must contain at least one item

# 对口型
Kling lip-sync does not accept images or videos; use extra.session_id and extra.face_choose
Kling lip-sync requires a non-empty extra.session_id
Kling lip-sync requires an extra.face_choose array with exactly 1 item
extra.face_choose[0].<键> is not part of the lip-sync contract
extra.face_choose[0].face_id must be a non-empty string or a non-negative integer
extra.face_choose[0].sound_file must be a non-empty string
extra.face_choose[0].sound_file must be a publicly accessible http(s) audio URL
extra.voice_list is reserved; use voice_ids instead (voice selection is not available yet)

任务失败

常见原因是素材不符合官方规格(分辨率、格式、大小、时长)或内容审核未通过。文案本身已写明下一步;两种 2 小时超时请重新提交。失败的任务一律不计费。

下面是视频任务的 error.message 原文。生图任务写作 image generation、reference image,自定义主体写作 subject creation。

# input_sensitive:提示词未通过审核
the prompt was rejected by content moderation; rephrase it and submit again

# input_sensitive:参考素材未通过审核
the reference media was rejected by content moderation; replace it and submit again

# input_sensitive:审核未通过(未说明是哪一项)
the prompt or reference media was rejected by content moderation; revise it and submit again

# output_video_sensitive / safety_rejected:产出被审核拦下
the generated result was blocked by content moderation; adjust the prompt or reference media and submit again

# rate_limited:并发已满
this model is at its concurrency limit right now; please retry shortly

# unsupported_model:模型版本已下架
this model version is no longer available; switch to another model and submit again

# invalid_request:提示词过长
the prompt is too long for this model (at most 2500 characters); shorten it and submit again

# invalid_request:参数或素材不合规
the request was rejected as invalid by the model; check the parameters and media against the documented limits, then submit again

# reference_input_invalid:参考素材读取失败
a reference image or video is missing or could not be read; make sure every URL is publicly reachable and points to a supported file, then submit again

# generation_failed:生成失败(其他原因)
video generation failed; please retry, and contact support with the task ID if it keeps failing

# generation_failed:生成中途被终止
video generation was stopped before it finished; please retry, and contact support with the task ID if it keeps failing

# generation_failed:任务无法追踪(以此结尾)
… contact support with the task ID

# timeout:创建 2 小时后仍未结束
task did not reach a billable terminal state within 2 hours; polling stopped

# timeout:自定义主体 2 小时后仍未结束
subject task did not reach a terminal state within 2 hours; polling stopped

# no_output:任务结束但没有产出
video generation finished without a usable output; please retry, and contact support with the task ID if it keeps failing

# no_output:自定义主体结束但没有主体 ID
subject creation finished without returning a subject ID; check the media and create it again

计费

可灵对视频生成「按秒收费」,单价看该模型的分辨率与无声 / 有声 / 有无参考视频档位,不按 video tokens 计量。只有成功完成的任务才计费,失败的任务不计费。

  • 人脸识别(POST /v1/kling/faces)按次计费。
  • 创建自定义主体目前不计费。
  • 生图计费见可灵生图。
对口型最低按 5 秒计费:

对口型按秒计费并有 5 秒下限,4 秒成片按 5 秒收费。

官方牌价见价格页。你的实际单价以登录后的模型广场为准,每次请求的实际扣费见用量记录。

下一步