APIMODELSAPIMODELS
API 文档

apimodels.app

可灵多元素视频编辑 API 参数文档

可灵多元素视频编辑(Kling Multi-Elements)用来改一段现成的短视频:把参考图里的东西加进画面(addition)、把画面里标出的元素换成参考图里的(swap),或者把标出的元素删掉(removal)。在 APIMODELS 上它是统一视频端点里的一个模型名 kling-multi-elements(kling-video-edit 也能用),而且只要一次请求:可灵那套「上传视频、逐帧标选区、提交编辑」的流程由我们在服务端跑完。输入只收 2-5 秒或 7-10 秒的视频。按成片每 5 秒计费,std(720p)$0.42、pro(1080p)$0.70,只在生成成功时扣费。

价格

成片时长std(720p)pro(1080p)
5 秒成片(输入 2-5 秒)$0.42$0.70
10 秒成片(输入 7-10 秒)$0.84$1.40

按成片每 5 秒计费:std $0.42、pro $0.70。成片只有 5 秒和 10 秒两种,不传 duration 时按输入视频的长度定(2-5 秒 → 5 秒,7-10 秒 → 10 秒)。编辑方式、参考图张数、标了几帧都不影响价格。参数不合规的请求在创建时返回 400,不扣费;生成失败不扣费。

认证

所有请求在 Header 携带 API Key:

Authorization: Bearer YOUR_API_KEY

创建任务与查询结果

POSThttps://api.apimodels.app/v1/video/generations·GET/v1/video/generations?task_id=

三个示例各对应一种编辑方式:cURL 是添加(addition),Python 是替换(swap),Node 是删除(removal)。

# Kling multi-element video editing — one call edits an existing 2-5 s or 7-10 s clip.
# edit_mode: addition (1-2 images) | swap (exactly 1 image) | removal (no image).
# Billed per 5 s of output on success: std (720p) $0.42, pro (1080p) $0.70.

# Addition: put an element from a reference image into the video (selections are optional here)
curl -X POST https://api.apimodels.app/v1/video/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-multi-elements",
    "video_url": "https://example.com/street-4s.mp4",
    "edit_mode": "addition",
    "image_urls": ["https://example.com/red-umbrella-cropped.png"],
    "prompt": "Using the context of <<<video_1>>>, seamlessly add the red umbrella from <<<image_1>>> into the hand of the woman walking on the left",
    "mode": "std"
  }'

# Response (async — a task is created):
# { "code": 200, "msg": "success", "data": { "taskId": "clxxx", "state": "pending", "model": "kling-multi-elements" } }

# Poll every 10-15 s until completed (result files are kept 30 days)
curl "https://api.apimodels.app/v1/video/generations?task_id=TASK_ID" \
  -H "Authorization: Bearer YOUR_API_KEY"
# { "code": 200, "data": { "state": "completed",
#     "resultUrls": ["https://r2.apimodels.app/videos/clxxx.mp4"] } }

任务状态依次是 pending → processing → completed 或 failed。completed 时 data.resultUrls[0] 是编辑后的 MP4;failed 时原因在 data.failMsg,费用自动退回。每 10-15 秒轮询一次即可。

三种编辑方式与提示词模板

提示词里用 <<<video_1>>> 指代输入视频,用 <<<image_1>>>、<<<image_2>>> 指代 image_urls 里的第 1、2 张图。[x] 换成你要描述的东西,比如「the red umbrella」。

edit_mode提示词模板参考图selections
additionUsing the context of <<<video_1>>>, seamlessly add [x] from <<<image_1>>>image_urls: 1-2可选
swapswap [x] from <<<image_1>>> for [x] from <<<video_1>>>image_urls: 1必填
removalDelete [x] from <<<video_1>>>image_urls: —必填

参考图要事先裁好,只留下要加进去或换上去的那个主体:接口不会帮你裁图。

选区(selections):标出要改的元素

替换和删除必须告诉可灵改的是画面里哪个东西。做法是挑几个时间点,在那一帧里在这个元素身上点几个点:time 是输入视频里的秒数(也可以改用 frame_index 直接写帧号),x、y 是点在画面里的位置,按画面宽和高的比例写成 0-1 的小数,从左上角算起。最多标 10 帧,每帧最多 10 个点;元素会移动时,在它位置不同的几帧各标一次。添加模式可以不标,也可以标出要放的位置。

"selections": [
  { "time": 1.0, "points": [ { "x": 0.52, "y": 0.40 }, { "x": 0.55, "y": 0.47 } ] },
  { "time": 3.2, "points": [ { "x": 0.60, "y": 0.43 } ] }
]

// time        = seconds into the input video (or frame_index = the frame number instead)
// x, y        = fractions 0-1 of the frame width and height, measured from the top-left corner
//               (x 0.5, y 0.5 is the centre of the frame)
// limits      = up to 10 marked frames, up to 10 points per frame

结果好不好很大程度取决于标得准不准:点要落在元素本身上,不要落在背景上。网站上的试用区可以暂停视频、直接在画面上点,坐标会按这个格式自动生成。

回调(callback_url)

不想轮询就在创建请求里传 callback_url。任务到达 completed 或 failed 时,我们向这个地址发一个 HTTP POST(JSON)。投递失败会按指数退避重试,30 分钟内持续重试,直到你的接口返回 2xx。回调地址必须公网可达,localhost 和内网地址在创建时就返回 400。轮询接口照常可用。

POST {your callback_url}
Content-Type: application/json

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "clxxx...",
    "model": "kling-multi-elements",
    "state": "completed",                 // or "failed"
    "param": "<JSON string>",             // your request, JSON.parse once
    "resultJson": "<JSON string> | null", // {"resultUrls": ["https://...mp4"]}, JSON.parse once
    "failCode": null,
    "failMsg": null
  }
}

参数

字段必填类型说明
model是stringkling-multi-elements(kling-video-edit 也可)
video_url是string要编辑的视频,公网 URL。MP4 或 MOV,2-5 秒或 7-10 秒,宽和高都在 720-2160 像素之间,24 / 30 / 60 fps。
edit_mode是stringaddition(添加)、swap(替换)或 removal(删除)。
image_urls看模式string[]参考图,URL 或 base64。addition 1-2 张,swap 正好 1 张,removal 不传。要事先裁到主体。
prompt是string最多 2500 个字符,必须包含 <<<video_1>>>;addition 和 swap 还要包含 <<<image_1>>>。模板见上文。
negative_prompt否string不想在结果里出现的东西。
selectionsswap / removal 必填object[][{ time 或 frame_index, points: [{ x, y }] }],x、y 为 0-1 比例,从左上角算。最多 10 帧,每帧最多 10 个点。addition 可选。
mode否stringstd(默认,720p,每 5 秒 $0.42)或 pro(1080p,每 5 秒 $0.70)。
duration否integer成片时长 5 或 10。不传时按输入定:2-5 秒的视频出 5 秒,7-10 秒的出 10 秒。5 要配 2-5 秒的输入,10 要配 7-10 秒的输入。
callback_url否string任务完成时我们向该地址 POST 结果;不传就轮询 GET 查询。

限制

  • 输入时长 — 只收 2-5 秒或 7-10 秒的视频。6 秒、11 秒这类长度会在创建时返回 400,需要先剪。
  • 输入画面 — MP4 或 MOV,宽和高都在 720-2160 像素之间,24 / 30 / 60 fps。
  • 标记质量 — 结果好坏取决于元素标得好不好;点落在背景上,可能改错东西。
  • 成功率 — 不是 100% 成功:编辑可能失败,也可能没改到目标元素。失败的任务不扣费;没改到位时,调整选区或提示词后重试。
  • 结果保留 — 结果文件保留 30 天后自动删除,请及时下载或转存。

常见报错

参数问题在创建时同步返回 400({"code": 400, "msg": "..."}),不会建任务、不扣费。输入视频的时长由我们在建任务前测量。下表 msg 是当前原文(N 为实际数值)。

msg原因 / 怎么改
video_url is required (mp4/mov, 2–5 s or 7–10 s, 720–2160 px, 24/30/60 fps)没传要编辑的视频。
edit_mode must be "addition", "swap" or "removal"edit_mode 只有这三个值。
edit_mode "addition" needs 1–2 reference images in image_urls (got N)添加模式要 1-2 张参考图。
edit_mode "swap" needs exactly 1 reference image in image_urls (got N)替换模式只收正好 1 张参考图。
edit_mode "removal" takes no reference images; remove image_urls删除模式不收图,去掉 image_urls。
prompt is required; refer to the inputs as <<<video_1>>> and <<<image_1>>>, e.g. "Delete the cup from <<<video_1>>>"没写提示词。
prompt must be 2500 characters or fewer (got N)提示词超过 2500 个字符。
prompt must refer to the input video as <<<video_1>>>, e.g. "Delete the cup from <<<video_1>>>"提示词里要用 <<<video_1>>> 指代输入视频。
prompt must refer to the reference image as <<<image_1>>>添加和替换模式的提示词里要用 <<<image_1>>>(两张图时还有 <<<image_2>>>)指代参考图。
edit_mode "swap" needs selections: mark the element with [{ "time": 1.0, "points": [{ "x": 0.5, "y": 0.4 }] }] (x / y are 0–1 from the top-left)替换和删除模式必须带 selections,标出要改的那个元素(删除模式报的是 edit_mode "removal")。
selections[N] needs time (seconds) or frame_index每个选区要有 time(秒)或 frame_index。
selections[N].points: x and y must be fractions between 0 and 1 (from the top-left corner of the frame)坐标是 0-1 的比例,不是像素。像素坐标先除以画面宽高。
selections[N] has N points; at most 10 per frame一帧最多 10 个点。
selections marks N frames; at most 10最多标 10 帧。
mode must be "std" (720p) or "pro" (1080p)mode 只接受 std 或 pro。
duration must be 5 or 10 (got N)duration 只能是 5 或 10,或者不传。
The input video is N s; Kling multi-element editing accepts 2–5 s or 7–10 s videos输入视频不在 2-5 秒或 7-10 秒内(比如 6 秒或 12 秒)。先剪到这两个区间之一。
duration 5 needs a 2–5 s input video (this one is N s); use duration 10 or omit it5 秒成片要 2-5 秒的输入。
duration 10 needs a 7–10 s input video (this one is N s); use duration 5 or omit it10 秒成片要 7-10 秒的输入。
  • 401:API Key 缺失或无效。
  • 402:余额不足以支付这次编辑。
  • 生成阶段的失败(内容审核拒绝、上游报错、超时)状态为 failed,原因在 data.failMsg,费用自动退回。

说明

  • 这是编辑现成视频,不是从零生成:要生成新片子,用 Kling 3.0 Turbo 或 Kling 4.0。
  • 请只上传你有权使用的视频和图片。

试一试:Playground;用例和价格例子见 可灵多元素视频编辑模型页。

相关

常见问题

可灵多元素视频编辑多少钱?

按成片每 5 秒计费:std(720p)$0.42,pro(1080p)$0.70。5 秒成片 $0.42 或 $0.70,10 秒成片 $0.84 或 $1.40。只有编辑成功才扣费。

该用哪种 edit_mode?各要几张图?

addition 把 1-2 张参考图里的东西加进视频;swap 把标出的元素换成正好 1 张参考图里的;removal 删掉标出的元素,不收图。swap 和 removal 必须带 selections,addition 可选。

selections 里怎么标出元素?

传一组 { time, points }(也可以用 frame_index 代替 time):time 是输入视频里的秒数,每个点的 x、y 是相对画面宽高的 0-1 比例,从左上角算。最多 10 帧,每帧最多 10 个点。

可灵多元素视频编辑接受什么样的视频?

MP4 或 MOV,2-5 秒或 7-10 秒,宽高都在 720-2160 像素之间,24、30 或 60 fps。其他时长在扣费前返回 400。编辑仍可能失败或没改到目标,成功率不是 100%;失败的任务不扣费。