参考图生视频
Kling 4.0 Flash 的 reference_to_video:让参考图里的人物、物体或场景出现在新生成的视频里,也可以附上参考视频。
Kling 4.0 Flash 让参考图里的人物、物体或场景出现在新生成的视频里。也可以附上参考视频,例如让主体模仿参考视频中的动作。
创建任务
POST
https://api.nanoapi.ai/v1/tasks用所有模型共用的创建任务接口,model 传 "kling-4.0-flash",mode 传 "reference_to_video"。
请求头
| 请求头 | 必填 | 说明 |
|---|---|---|
Authorization | 是 | Bearer <API Key>,见鉴权 |
Content-Type | 是 | application/json |
Idempotency-Key | 否 | 每个新任务一个唯一字符串,建议用 UUID(1–255 个字符),见防止重复创建 |
请求体
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | kling-4.0-flash |
mode | string | 是 | reference_to_video |
image_urls | string[] | 条件必填 | 与 video_urls 至少传一项。最多 10 张参考图,见素材 |
video_urls | string[] | 条件必填 | 与 image_urls 至少传一项(可以只传参考视频)。最多 5 段参考视频,每段 3–30 秒,总时长不超过 30 秒,720p 及以上,画面比例不超过 2.5:1,见素材。带参考视频时按 video_edit 的单价计费,见价格 |
prompt | string | 否 | 描述视频内容,例如参考图里的主体在做什么,最长 8000 字符。可以用 @Image1、@Video1 等指代素材,见引用素材 |
aspect_ratio | string | 是 | 画面比例:auto、21:9、16:9、9:16 或 1:1。auto 不会跟随参考图的比例,需要特定比例(例如竖屏)时请明确指定 |
resolution | string | 是 | 720p |
duration | integer | 是 | 输出时长(秒),3–20,按此计费,见价格 |
webhook_url | string | 否 | 任务成功或失败时通知该地址:https,最长 2048 字符,不能指向内网、回环或保留地址。见回调 |
两张参考图,竖屏,5 秒:
curl https://api.nanoapi.ai/v1/tasks \
-H "Authorization: Bearer $NANOAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-4.0-flash",
"mode": "reference_to_video",
"image_urls": [
"https://example.com/cat.jpg",
"https://example.com/car.jpg"
],
"prompt": "The cat sits on the hood of the car",
"aspect_ratio": "9:16",
"resolution": "720p",
"duration": 5
}'一张参考图加一段参考视频(让猫模仿视频中人物的走路方式),16:9,5 秒:
curl https://api.nanoapi.ai/v1/tasks \
-H "Authorization: Bearer $NANOAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-4.0-flash",
"mode": "reference_to_video",
"image_urls": ["https://example.com/cat.jpg"],
"video_urls": ["https://example.com/walk.mp4"],
"prompt": "The cat from @Image1 walks down the street like the woman in @Video1",
"aspect_ratio": "16:9",
"resolution": "720p",
"duration": 5
}'响应:200 OK,返回新建的任务(字段说明)。保存 data.id,用它获取结果;任务创建后仍可能失败,见错误。
{
"code": 200,
"message": "success",
"data": {
"object": "task",
"id": "tk_01jbm3r8x5c2v9b6n4q7w1e3t5",
"model": "kling-4.0-flash",
"status": "queued",
"error": null,
"created_at": "2026-11-18T08:30:00Z"
}
}价格
费用 = 输出时长 duration × 每秒单价正在读取当前价格…
带参考视频(video_urls)时改按 video_edit 的每秒单价计费。上面第二个请求(5 秒)的费用为 5 × video_edit 的每秒单价:
正在读取当前价格…
计费秒数即请求的 duration,与参考图和参考视频的数量以及视频时长均无关。Kling 4.0 Flash 所有模式的价格见 Kling 4.0 Flash → 价格。当前单价见 GET /v1/products(产品 kling_flash,prices 中 mode 为 reference_to_video 的行;带参考视频时为 video_edit 的行),以任务的 billing.frozen 为准;冻结和扣费规则见计费。
错误
见 Kling 4.0 Flash → 错误。本模式的参数规则见上面的参数表。