Skip to content

Kling 4.0 Flash 关键帧生成视频 ​

接口 ​

POST /jobs/createTask

完整 URL: https://modelfold.ai/v1/jobs/createTask

鉴权:所有请求都需要 Authorization: Bearer <API_KEY> 请求头。

输出分辨率固定 720p,成片时长 3–20 秒。传了首帧时画面比例跟随首帧;不传首帧时 aspect_ratio 生效,默认 16:9。

查询任务状态 ​

提交任务后,可通过统一查询接口查看进度并获取结果:

TIP

生产环境建议使用 callBackUrl 参数接收生成完成的自动通知,而非轮询状态接口。

相关资源 ​

请求参数 ​

请求体 (application/json) ​

参数类型必填说明
modelstring是生成任务使用的模型名称,必填。
- 本接口需使用 kling-4.0/flash-keyframe-to-video 默认值:"kling-4.0/flash-keyframe-to-video"。 可选值:kling-4.0/flash-keyframe-to-video。 示例:kling-4.0/flash-keyframe-to-video。
callBackUrlstring否接收生成任务完成通知的回调 URL。可选配置,生产环境建议使用。
- 任务生成完成后,系统会向该 URL 以 POST 方式推送任务状态和结果
- 回调内容包含生成内容的 URL 及任务相关信息
- 你的回调接口需支持接收 POST 请求及 JSON 格式的请求体
- 也可选择调用任务详情接口,主动轮询任务状态
- 为确保回调安全性,请参阅 Webhook 校验指南 了解签名验证实现方法 示例:https://your-domain.com/api/callback。
inputobject是生成任务的输入参数。
  input.promptstring是视频描述,必填,最多 8000 个字符。
传了 first_frame_url 时用 @first_frame 引用。Kling 4.0 Flash 不支持中间帧和尾帧,传入 keyframes 或 last_frame 会返回错误。 minLength: 1. maxLength: 8000. 示例:Animate the supplied image as one continuous 10-second shot. Keep the camera fixed to the opposite bench as the gondola ascends. Preserve the skier’s face, the goggles on her helmet, and the embroidered “ModelFold AI” patch.<br>REFERENCES: @first_frame is the exact opening frame.。
  input.durationinteger否输出视频时长(秒),3–20 的整数,默认 5。 默认值:5。 minimum: 3. maximum: 20. 示例:5。
  input.resolutionstring否输出分辨率。Kling 4.0 Flash 只支持 720p,默认 720p。 默认值:"720p"。 可选值:720p。 示例:720p。
  input.aspect_ratiostring否输出画面比例:16:9 / 9:16 / 1:1 / 21:9(没有 auto)。只在不传 first_frame_url 时生效(纯文生视频),默认 16:9;传了首帧时比例跟随首帧。 可选值:16:9 / 9:16 / 1:1 / 21:9。 示例:16:9。
  input.first_frame_urlstring否可选,首帧图片地址。提示词里用 @first_frame 引用。不传就是纯文生视频。不支持中间帧 keyframes 和尾帧 last_frame。 pattern: ^https?://.

请求示例 ​

bash
curl -X POST "https://modelfold.ai/v1/jobs/createTask" \
  -H "Authorization: Bearer $MODELFOLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "kling-4.0/flash-keyframe-to-video",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "prompt": "Animate the supplied image as one continuous 10-second shot. Keep the camera fixed to the opposite bench as the gondola ascends. Preserve the skier’s face, the goggles on her helmet, and the embroidered “ModelFold AI” patch.\nREFERENCES: @first_frame is the exact opening frame.",
    "first_frame_url": "https://static.aiquickdraw.com/tools/example/1793862976499_p1yBE2dY.png",
    "duration": 5,
    "resolution": "720p",
    "aspect_ratio": "16:9"
  }
}'
python
import os
import requests

resp = requests.post(
    "https://modelfold.ai/v1/jobs/createTask",
    headers={
        "Authorization": "Bearer " + os.environ["MODELFOLD_API_KEY"],
        "Content-Type": "application/json",
    },
    json={
        "model": "kling-4.0/flash-keyframe-to-video",
        "callBackUrl": "https://your-domain.com/api/callback",
        "input": {
            "prompt": "Animate the supplied image as one continuous 10-second shot. Keep the camera fixed to the opposite bench as the gondola ascends. Preserve the skier’s face, the goggles on her helmet, and the embroidered “ModelFold AI” patch.\nREFERENCES: @first_frame is the exact opening frame.",
            "first_frame_url": "https://static.aiquickdraw.com/tools/example/1793862976499_p1yBE2dY.png",
            "duration": 5,
            "resolution": "720p",
            "aspect_ratio": "16:9",
        },
    },
)
print(resp.json())
javascript
const resp = await fetch("https://modelfold.ai/v1/jobs/createTask", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.MODELFOLD_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "kling-4.0/flash-keyframe-to-video",
    "callBackUrl": "https://your-domain.com/api/callback",
    "input": {
      "prompt": "Animate the supplied image as one continuous 10-second shot. Keep the camera fixed to the opposite bench as the gondola ascends. Preserve the skier’s face, the goggles on her helmet, and the embroidered “ModelFold AI” patch.\nREFERENCES: @first_frame is the exact opening frame.",
      "first_frame_url": "https://static.aiquickdraw.com/tools/example/1793862976499_p1yBE2dY.png",
      "duration": 5,
      "resolution": "720p",
      "aspect_ratio": "16:9"
    }
  }),
});
console.log(await resp.json());
go
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"strings"
)

func main() {
	body := strings.NewReader(`{"model":"kling-4.0/flash-keyframe-to-video","callBackUrl":"https://your-domain.com/api/callback","input":{"prompt":"Animate the supplied image as one continuous 10-second shot. Keep the camera fixed to the opposite bench as the gondola ascends. Preserve the skier’s face, the goggles on her helmet, and the embroidered “ModelFold AI” patch.\nREFERENCES: @first_frame is the exact opening frame.","first_frame_url":"https://static.aiquickdraw.com/tools/example/1793862976499_p1yBE2dY.png","duration":5,"resolution":"720p","aspect_ratio":"16:9"}}`)
	req, _ := http.NewRequest("POST", "https://modelfold.ai/v1/jobs/createTask", body)
	req.Header.Set("Authorization", "Bearer " + os.Getenv("MODELFOLD_API_KEY"))
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	out, _ := io.ReadAll(resp.Body)
	fmt.Println(string(out))
}
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String body = "{\"model\":\"kling-4.0/flash-keyframe-to-video\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"input\":{\"prompt\":\"Animate the supplied image as one continuous 10-second shot. Keep the camera fixed to the opposite bench as the gondola ascends. Preserve the skier’s face, the goggles on her helmet, and the embroidered “ModelFold AI” patch.\\nREFERENCES: @first_frame is the exact opening frame.\",\"first_frame_url\":\"https://static.aiquickdraw.com/tools/example/1793862976499_p1yBE2dY.png\",\"duration\":5,\"resolution\":\"720p\",\"aspect_ratio\":\"16:9\"}}";
        HttpRequest req = HttpRequest.newBuilder()
            .uri(URI.create("https://modelfold.ai/v1/jobs/createTask"))
            .header("Authorization", "Bearer " + System.getenv("MODELFOLD_API_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .build();
        HttpResponse<String> resp = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
        System.out.println(resp.body());
    }
}
php
<?php
$ch = curl_init('https://modelfold.ai/v1/jobs/createTask');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv("MODELFOLD_API_KEY"),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => '{"model":"kling-4.0/flash-keyframe-to-video","callBackUrl":"https://your-domain.com/api/callback","input":{"prompt":"Animate the supplied image as one continuous 10-second shot. Keep the camera fixed to the opposite bench as the gondola ascends. Preserve the skier’s face, the goggles on her helmet, and the embroidered “ModelFold AI” patch.\\nREFERENCES: @first_frame is the exact opening frame.","first_frame_url":"https://static.aiquickdraw.com/tools/example/1793862976499_p1yBE2dY.png","duration":5,"resolution":"720p","aspect_ratio":"16:9"}}',
]);
echo curl_exec($ch);
curl_close($ch);
csharp
using System;
using System.Net.Http;
using System.Text;

var client = new HttpClient();
var req = new HttpRequestMessage(new HttpMethod("POST"), "https://modelfold.ai/v1/jobs/createTask");
req.Headers.TryAddWithoutValidation("Authorization", "Bearer " + Environment.GetEnvironmentVariable("MODELFOLD_API_KEY"));
req.Content = new StringContent("{\"model\":\"kling-4.0/flash-keyframe-to-video\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"input\":{\"prompt\":\"Animate the supplied image as one continuous 10-second shot. Keep the camera fixed to the opposite bench as the gondola ascends. Preserve the skier’s face, the goggles on her helmet, and the embroidered “ModelFold AI” patch.\\nREFERENCES: @first_frame is the exact opening frame.\",\"first_frame_url\":\"https://static.aiquickdraw.com/tools/example/1793862976499_p1yBE2dY.png\",\"duration\":5,\"resolution\":\"720p\",\"aspect_ratio\":\"16:9\"}}", Encoding.UTF8, "application/json");
var resp = await client.SendAsync(req);
Console.WriteLine(await resp.Content.ReadAsStringAsync());
json
{
  "model": "kling-4.0/flash-keyframe-to-video",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "prompt": "Animate the supplied image as one continuous 10-second shot. Keep the camera fixed to the opposite bench as the gondola ascends. Preserve the skier’s face, the goggles on her helmet, and the embroidered “ModelFold AI” patch.\nREFERENCES: @first_frame is the exact opening frame.",
    "first_frame_url": "https://static.aiquickdraw.com/tools/example/1793862976499_p1yBE2dY.png",
    "duration": 5,
    "resolution": "720p",
    "aspect_ratio": "16:9"
  }
}

响应 ​

200 — 请求成功 ​

参数类型必填说明
codeinteger否响应状态码
- 200: 成功 - 请求已处理完成
- 401: 未授权 - 身份验证凭据缺失或无效
- 402: 余额不足 - 账户余额不足以执行该操作
- 404: 未找到 - 请求的资源或接口不存在
- 422: 参数验证错误 - 请求参数未通过校验
- 429: 调用频率超限 - 已超出该资源的请求限制
- 433: 子密钥使用超限
- 455: 服务不可用 - 系统正在维护中
- 500: 服务器内部错误 - 处理请求时发生意外故障
- 501: 生成失败 - 内容生成任务执行失败
- 505: 功能禁用 - 当前请求的功能已被禁用 可选值:200 / 401 / 402 / 404 / 422 / 429 / 433 / 455 / 500 / 501 / 505。 示例:200。
msgstring否响应消息,请求失败时返回错误描述 示例:success。
dataobject是—
  data.taskIdstring是任务 ID,可结合「获取任务详情」接口查询任务状态
json
{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_kling-4.0-flash-keyframe-to-video_abc123"
  }
}

回调 ​

videoTaskCompleted ​

回调地址:{request.body#/callBackUrl}(即请求体里的 callBackUrl)。

当 kling-4.0/flash-keyframe-to-video 任务成功或失败时,系统会向 callBackUrl 发送此 POST 回调。

回调体参数

参数类型必填说明
codeinteger是统一回调状态码:成功为 200,失败为 501。 可选值:200 / 501。 示例:200。
msgstring是统一回调消息。 可选值:Playground task completed successfully. / Playground task failed.。 示例:Playground task completed successfully.。
dataobject是任务结果。成功时 resultJson 包含 resultUrls;失败时返回 failCode、failMsg,不含 resultJson。
  data.completeTimeinteger否任务完成时间戳(毫秒)。完成时间请以该字段为准。
  data.costTimeinteger否处理耗时(秒)。成功和失败回调都会返回。
  data.createTimeinteger否任务创建时间戳(毫秒)。
  data.modelstring是任务使用的模型。 可选值:kling-4.0/flash-keyframe-to-video。 示例:kling-4.0/flash-keyframe-to-video。
  data.paramstring是已提交任务的 JSON 字符串,包含 model、callBackUrl 和 input。input 对应该接口参数(prompt、duration、resolution、aspect_ratio、first_frame_url)。
  data.resultJsonstring否生成结果的 JSON 字符串。仅在 state 为 success 时出现。该模型里包含 resultUrls,即 .mp4 地址数组。
  data.statestring是任务最终状态。 可选值:success / fail。 示例:success。
  data.taskIdstring是任务唯一标识符,与创建任务接口返回的 data.taskId 一致。
  data.updateTimeinteger否任务更新时间戳(毫秒)。可能与 createTime 相同;完成时间请以 completeTime 为准。
  data.failCodestring否失败码,数字字符串,如 "400"、"500"。仅在 state 为 fail 时出现。
  data.failMsgstring否失败原因,仅在 state 为 fail 时出现。该模型可能是总帧数超过 duration 上限(duration 5s allows at most 6 frames (first + keyframes + last), got 7)、未传 first_frame_url、prompt 引用了未提供的 @first_frame / @keyframe_N / @last_frame,或图片拉取/审核/尺寸相关的上游原文。

任务成功完成

json
{
  "code": 200,
  "data": {
    "completeTime": 1792670085074,
    "costTime": 718,
    "createTime": 1792669367000,
    "model": "kling-4.0/flash-keyframe-to-video",
    "param": "{\"input\":\"{\\\"duration\\\":10,\\\"keyframe_urls\\\":[],\\\"prompt\\\":\\\"女孩出门\\\",\\\"resolution\\\":\\\"720p\\\"}\",\"callBackUrl\":\"https://webhook.uutool.cn/bfa7de80-8dd8-4844-9e34-4032ddbbf3c1\",\"model\":\"kling-4.0/flash-keyframe-to-video\"}",
    "resultJson": "{\"resultUrls\":[\"https://tempfile.aiquickdraw.com/k/ce115adfa78260a99009eebddac1d187_1_1792670083_1582.mp4\"]}",
    "state": "success",
    "taskId": "ce115adfa78260a99009eebddac1d187",
    "updateTime": 1792669367000
  },
  "msg": "Playground task completed successfully."
}

任务失败

json
{
  "code": 501,
  "data": {
    "completeTime": 1792670085074,
    "costTime": 718,
    "createTime": 1792669367000,
    "failCode": "400",
    "failMsg": "duration 5s allows at most 6 frames (first + keyframes + last), got 7",
    "model": "kling-4.0/flash-keyframe-to-video",
    "param": "{\"input\":\"{\\\"duration\\\":5,\\\"first_frame_url\\\":\\\"https://example.com/first.png\\\",\\\"keyframe_urls\\\":[\\\"https://example.com/k1.png\\\",\\\"https://example.com/k2.png\\\",\\\"https://example.com/k3.png\\\",\\\"https://example.com/k4.png\\\",\\\"https://example.com/k5.png\\\"],\\\"last_frame_url\\\":\\\"https://example.com/last.png\\\",\\\"prompt\\\":\\\"女孩出门\\\",\\\"resolution\\\":\\\"720p\\\"}\",\"callBackUrl\":\"https://webhook.uutool.cn/bfa7de80-8dd8-4844-9e34-4032ddbbf3c1\",\"model\":\"kling-4.0/flash-keyframe-to-video\"}",
    "state": "fail",
    "taskId": "ce115adfa78260a99009eebddac1d187",
    "updateTime": 1792669367000
  },
  "msg": "Playground task failed."
}

ModelFold — 一个 API,接入所有主流 AI 模型。