---
title: "Kling VIDEO 4.0 / Flash"
url: "/docs/kling-4"
base_url:
  - "https://api.o1key.com"  # 主地址
auth: "Authorization: Bearer <API Key>"
endpoints:
  - "POST /text-to-video/kling-4.0"
  - "POST /text-to-video/kling-4.0-flash"
  - "POST /image-to-video/kling-4.0"
  - "POST /image-to-video/kling-4.0-flash"
  - "POST /omni-video/kling-4.0"
  - "POST /omni-video/kling-4.0-flash"
  - "GET /tasks"
  - "POST /tasks"
---

# Kling VIDEO 4.0 / Flash

可灵 4.0 与 4.0 Flash 的文生视频、图生视频（多关键帧）和 Omni 多素材 / 视频编辑。路径与可灵官方一致。客户端使用任务 ID 轮询状态，提交时请省略 `callback_url`。

## Agent 调用规则

1. 按需求选路径 POST `/{text-to-video|image-to-video|omni-video}/{kling-4.0|kling-4.0-flash}`，请求体不传 `model`。记录 `data.id`。
2. Flash 只用 720p、3–20 秒；4.0 时长 3–30 秒。
3. 定期 GET `/tasks?task_ids={id}`，`submitted` 或 `processing` 时继续查询。
4. `succeeded`：把 `outputs[].url` 返回给用户，提醒约 30 天有效。
5. `failed`：把 `message` 告诉用户，不要自动重试。

## 简明说明

### 这个接口做什么？

用可灵 4.0 或 4.0 Flash 生成视频。用法和可灵官方完全一样，只需把 Base URL 换成本站、使用本站 API Key。模型由路径决定，请求体里不用写 `model`。

### 你需要提供的信息

- **做什么**：选路径：文生视频 `text-to-video`、图生视频 `image-to-video`、多素材与编辑 `omni-video`。
- **用哪个版本**：路径末尾 `kling-4.0` 或 `kling-4.0-flash`。Flash 只支持 720p、3–20 秒。
- **想要什么画面**：文生视频填 `prompt`；其余两种用 `contents` 数组放提示词和素材。
- **时长与分辨率（可选）**：`settings.duration`、`settings.resolution`、`settings.aspect_ratio`。

### 怎么拿到结果

- **状态**：`submitted`、`processing` 继续等待；`succeeded` 成功；`failed` 失败。
- **视频地址**：`data[].outputs[].url`，通常保留 30 天，请及时保存。

## 路径、参数与价格

> **Flash**：使用相应的 Flash 路径，将路径里的 `kling-4.0` 换成 `kling-4.0-flash`。只支持 `720p`（默认也是 `720p`），时长 3–20 秒。不要传 `1080p`，也不要超过 20 秒。

### 创建与单任务查询

| 类型 | 提交 | 按任务 ID 查询 |
|---|---|---|
| 文生视频 | `POST /text-to-video/kling-4.0` | `GET /text-to-video/kling-4.0/{task_id}` |
| 图生视频 | `POST /image-to-video/kling-4.0` | `GET /image-to-video/kling-4.0/{task_id}` |
| Omni | `POST /omni-video/kling-4.0` | `GET /omni-video/kling-4.0/{task_id}` |
| Flash 文生视频 | `POST /text-to-video/kling-4.0-flash` | `GET /text-to-video/kling-4.0-flash/{task_id}` |
| Flash 图生视频 | `POST /image-to-video/kling-4.0-flash` | `GET /image-to-video/kling-4.0-flash/{task_id}` |
| Flash Omni | `POST /omni-video/kling-4.0-flash` | `GET /omni-video/kling-4.0-flash/{task_id}` |

- 请求头：`Authorization: Bearer <API Key>`，`Content-Type: application/json`。
- 路径与可灵官方完全一致，Base URL 换成本站即可。模型由路径决定，请求体不要传 `model`。
- 创建和查询的响应与可灵官方一致：`{code, message, request_id, data}`。`data.id` 是任务 ID；`data.external_id` 对应 `options.external_task_id`。状态：`submitted`、`processing`、`succeeded`、`failed`。
- 单任务 GET 的响应也是任务数组。批量查询和游标查询与官方相同，见下表。

### 批量与游标查询

| 查询 | 方法 | 说明 |
|---|---|---|
| 按任务 ID | `GET /tasks?task_ids=id1,id2` | 系统任务 ID，逗号分隔。不能与 `external_task_ids` 同时使用。 |
| 按自定义 ID | `GET /tasks?external_task_ids=a,b` | 对应 `options.external_task_id`。同一 API Key 下必须唯一。 |
| 游标 | `POST /tasks` | `start_time`、`end_time` 为毫秒时间戳。`cursor` 用上次返回的 `next_cursor`，传入后忽略起止时间。`limit` 默认 100，最大 500。 |

### 通用设置

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `settings.duration` | integer | 否 | 4.0：3–30 秒；Flash：3–20 秒。有填写值时以填写值为准。省略时识别提示词时长；Omni 若仍没有，则取 `base_video` 时长（取整），否则 10 秒。计费看 `usage.output_duration`。 |
| `settings.resolution` | string | 否 | 4.0 支持 `720p`、`1080p`、`4k`，默认 `1080p`。Flash 只支持 `720p`，默认也是 `720p`。 |
| `settings.dynamic_range` | string | 否 | 标准版默认 `sdr`。1080p 和 4K 也可设为 `hdr`。Flash 使用默认 SDR。 |
| `settings.aspect_ratio` | string | 否 | 仅文生视频和 Omni：`21:9`、`16:9`、`9:16`、`1:1`、`4:3`、`3:4`。Omni 另支持 `adaptive`。图生视频不能传。 |
| `settings.audio` | string | 否 | 仅 Omni。`native`（默认）按画面生成音频；`original` 保留输入视频原声。`original` 不能同时引用 `voice`，且至少要有一条 `base_video` 或 `feature_video`。有 `base_video` 用它的声音，否则用 `contents` 第一条 `feature_video` 的声音。 |
| `options.external_task_id` | string | 否 | 自定义任务 ID，不覆盖 `data.id`。同一 API Key 下必须唯一。用 `GET /tasks?external_task_ids=` 查询。 |
| `options.watermark_info.enabled` | boolean | 否 | 是否同时生成带水印结果，默认 `false`。传入 `false` 也会按 `false` 提交，不会省掉。不支持自定义水印。 |

提示词用 `@id` 引用素材，并写明每项用途。可灵说明：[文生视频](https://kling.ai/document-api/api/video/4-0/text-to-video)、[图生视频](https://kling.ai/document-api/api/video/4-0/image-to-video)、[Omni](https://kling.ai/document-api/api/video/4-0/video-omni)、[Flash](https://kling.ai/document-api/api/video/4-0-flash/text-to-video)。

### 价格

打开[模型定价](/pricing)，选择模型和分组即可查看当前售价。标准版列出 720p、1080p、4K 及相应的 HDR 加价。HDR 按输出视频时长收费，订单金额可在使用日志查看。

### 创建响应 · 200

```json
{
  "code": 0,
  "message": "",
  "request_id": "req_xxxxxxxxxx",
  "data": {
    "id": "task_xxxxxxxxxx",
    "status": "submitted",
    "create_time": 1781080778802,
    "update_time": 1781080778802,
    "external_id": ""
  }
}
```

用 `data.id` 查询。时间戳单位为毫秒。

## 文生视频

`POST /text-to-video/kling-4.0`
`POST /text-to-video/kling-4.0-flash`

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `prompt` | string | 是 | 可含正向和负向描述。纯英文最多 26,000 字符，纯非英文最多 11,000 字符；混合输入须满足 E/26000 + N/11000 ≤ 1。 |
| `settings.aspect_ratio` | string | 否 | `21:9`、`16:9`、`9:16`、`1:1`、`4:3`、`3:4`，默认 `16:9`。 |

也可传通用设置里的 `settings.duration`、`settings.resolution` 和 `options`。

### 请求示例 · Kling 4.0

```bash
curl https://api.o1key.com/text-to-video/kling-4.0 \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A sunrise over a quiet harbor, gentle waves, cinematic camera movement and ambient sound.",
    "settings": {"duration": 10, "resolution": "1080p", "aspect_ratio": "16:9"},
    "options": {"watermark_info": {"enabled": false}}
  }'
```

### 请求示例 · Kling 4.0 Flash

```bash
curl https://api.o1key.com/text-to-video/kling-4.0-flash \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A sunrise over a quiet harbor, gentle waves, cinematic camera movement and ambient sound.",
    "settings": {"duration": 8, "resolution": "720p", "aspect_ratio": "16:9"},
    "options": {"watermark_info": {"enabled": false}}
  }'
```

## 图生视频 · 多关键帧

`POST /image-to-video/kling-4.0`
`POST /image-to-video/kling-4.0-flash`

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `contents` | array | 是 | 至少 1 张关键帧，可附提示词。图片最多 10 张。 |
| `contents[].type` | string | 是 | `prompt`、`first_frame`、`middle_frame`、`last_frame`。 |
| `contents[].text` | string | 条件 | `type=prompt` 时必填。字符限制与文生视频 `prompt` 相同。 |
| `contents[].url` | string | 条件 | 图片项必填。可传公开 URL 或 Base64。 |
| `contents[].id` | string | 否 | 任务内唯一，提示词里用 `@id` 引用。多个 `middle_frame` 时，每张图都要指定 ID。 |

- 图片：JPG、JPEG、PNG。单张不超过 30 MB，宽高均不小于 300px，宽高比 2:5 至 5:2。文件属性由可灵校验。
- 不支持 `refer_image`、视频、元素、声音、`settings.aspect_ratio`、`settings.audio`。需要这些素材请用 Omni。

### 请求示例 · 首帧 + 中间帧 + 尾帧

```bash
curl https://api.o1key.com/image-to-video/kling-4.0 \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"type": "prompt", "text": "Transition smoothly from @first through @middle to @last; keep the character consistent."},
      {"type": "first_frame", "url": "https://cdn.example.com/first.png", "id": "first"},
      {"type": "middle_frame", "url": "https://cdn.example.com/middle.png", "id": "middle"},
      {"type": "last_frame", "url": "https://cdn.example.com/last.png", "id": "last"}
    ],
    "settings": {"resolution": "1080p", "duration": 12}
  }'
```

## Omni 多素材与视频编辑

`POST /omni-video/kling-4.0`
`POST /omni-video/kling-4.0-flash`

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `contents` | array | 是 | 提示词、图片、视频、元素、声音引用的集合。 |
| `contents[].type` | string | 是 | `prompt`、`first_frame`、`middle_frame`、`last_frame`、`refer_image`、`feature_video`、`base_video`、`element`、`voice`。 |
| `contents[].text` | string | 条件 | 提示词项必填。字符限制与文生视频 `prompt` 相同。写明各素材用途，以及要修改和保留的内容。 |
| `contents[].url` | string | 条件 | 图片或视频项必填。图片可传公开 URL 或 Base64，视频传公开 URL。 |
| `contents[].element_id` | string | 条件 | `type=element` 时必填，来自下方主体接口。 |
| `contents[].voice_id` | string | 条件 | `type=voice` 时必填。可用自定义或系统预设声音 ID。 |
| `contents[].id` | string | 条件 | 任务内唯一，供 `@id` 引用。`element` 和 `voice` 必填；多个中间帧或参考图时也必填。 |
| `settings.audio` | string | 否 | `native` 或 `original`，默认 `native`。省略即按 `native` 处理，不必为了默认值传入。 |
| `settings.aspect_ratio` | string | 否 | `21:9`、`16:9`、`9:16`、`1:1`、`4:3`、`3:4`、`adaptive`，默认 `adaptive`。省略或设为 `adaptive` 时：先用提示词中的比例，再参考基础视频、关键帧及其他视频，最后默认 16:9。 |

### 素材限制

| 素材 | 数量 | 规格 |
|---|---|---|
| 图片 | 最多 10 张 | JPG、JPEG、PNG。单张不超过 30 MB，宽高均不小于 300px，宽高比 2:5 至 5:2。 |
| 参考视频 | 最多 5 个；`base_video` 最多 1 个；与视频角色元素合计最多 5 个 | MP4、MOV，单个不超过 300 MB。每个及合计时长：4.0 为 3–30 秒，Flash 为 3–20 秒（含视频角色元素）。帧率 24–60 fps。宽、高各 700–4553px，总像素不超过 8,294,400，宽高比 2:5 至 5:2。 |
| 元素 / 声音 | 元素最多 7 个，其中视频角色元素最多 3 个；声音最多 3 个 | 图片、视频、元素、声音总数最多 15 个。 |
| 校验 | 本接口先校验字段、枚举、ID 和数量。文件大小、分辨率、输入视频时长和元素类型等媒体属性由可灵校验。 |  |

### 参考视频 + 参考图

```bash
curl https://api.o1key.com/omni-video/kling-4.0 \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"type": "prompt", "text": "Follow the movement rhythm in @video_1; preserve the character appearance from @image_1, not the video background."},
      {"type": "feature_video", "url": "https://cdn.example.com/motion.mp4", "id": "video_1"},
      {"type": "refer_image", "url": "https://cdn.example.com/person.png", "id": "image_1"}
    ],
    "settings": {"duration": 15, "resolution": "1080p", "aspect_ratio": "adaptive", "audio": "original"}
  }'
```

### 编辑视频 + 元素

```bash
curl https://api.o1key.com/omni-video/kling-4.0 \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"type": "prompt", "text": "Edit @video_1: place @element_1 inside the box at the end. Preserve the earlier shots and background."},
      {"type": "base_video", "url": "https://cdn.example.com/source.mp4", "id": "video_1"},
      {"type": "element", "element_id": "164", "id": "element_1"}
    ],
    "settings": {"duration": 10, "resolution": "1080p", "audio": "native"}
  }'
```

### 声音引用

```json
{
  "contents": [
    {"type": "prompt", "text": "Use @image_1 as the character. She says 'Excuse me' using @voice_1, with accurate lip sync."},
    {"type": "refer_image", "url": "https://cdn.example.com/person.png", "id": "image_1"},
    {"type": "voice", "voice_id": "829826751244537879", "id": "voice_1"}
  ],
  "settings": {"duration": 5, "aspect_ratio": "9:16", "audio": "native"}
}
```

## 查询任务（GET / POST /tasks）

`GET /tasks`
`POST /tasks`

用创建响应的 `data.id`，或创建时的 `options.external_task_id`。查询使用同一 API Key。`/tasks` 也能查 [Kling 3.0、3.0 Omni、动作模仿](/docs/kling-3.md) 和 [Kling Image 4.0](/docs/image-kling.md) 的任务，返回结构相同。

| 响应字段 | 说明 |
|---|---|
| `code` | 成功为 `0`。 |
| `data[].id` | 任务 ID，与创建响应的 `data.id` 相同。 |
| `data[].status` | `submitted`、`processing`、`succeeded`、`failed`。 |
| `data[].message` | 失败时为失败原因。 |
| `data[].outputs` | 成功后的结果。视频项含 `type`、`id`、`url`、`watermark_url`、`duration`。`duration` 是成片时长，单位秒。结果链接通常保留 30 天，请及时保存。 |
| `data[].usage.output_duration` | 计费用的输出时长，单位秒。有 `settings.duration` 时用该值；否则用提示词中的时长；都没有时，Omni 用 `base_video` 取整后的时长，再否则为 10 秒。计算费用用这个字段，不要用 `outputs[].duration`。 |
| `data[].usage.input_duration` | 输入视频总时长，保留两位小数的字符串。只在有视频输入且任务结束后返回，含 `feature_video`、`base_video` 和视频角色主体。时长按归一化后的视频计算，可能和原文件略有差别。 |
| `data[].external_id` | 自定义任务 ID。 |
| `data[].create_time` / `update_time` | 毫秒时间戳。 |

游标查询的 `data` 是对象：任务在 `data.result`，并带 `count`、`next_cursor`、`has_more`。`filters.status` 可用 `submitted`、`processing`、`succeeded`、`failed`；`filters.product_type` 中，视频任务为 `video`。

### 批量查询

```bash
curl "https://api.o1key.com/tasks?task_ids=task_a,task_b" \
  -H "Authorization: Bearer $API_KEY"
```

### 成功响应

```json
{
  "code": 0,
  "message": "",
  "request_id": "req_xxxxxxxxxx",
  "data": [
    {
      "id": "task_xxxxxxxxxx",
      "status": "succeeded",
      "message": "",
      "create_time": 1781080778802,
      "update_time": 1781080794151,
      "external_id": "",
      "outputs": [
        {
          "type": "video",
          "id": "video_xxxxxxxxxx",
          "url": "https://cdn.example.com/result.mp4",
          "watermark_url": "",
          "duration": "10.2"
        }
      ],
      "usage": {
        "input_duration": "8.03",
        "output_duration": "10"
      }
    }
  ]
}
```

ID、链接仅为示例。文生、图生、Omni 的单任务 GET（`kling-4.0` 与 `kling-4.0-flash`）返回同一结构，路径见本节开头。

## 主体与声音

主体和声音使用可灵官方路径，Base URL 换成本站即可。请求体和响应字段：`code`、`message`、`request_id`、`data`。创建类任务状态：`submitted`、`processing`、`succeed`、`failed`。

| 操作 | 路径 |
|---|---|
| 创建主体 | `POST /v1/general/advanced-custom-elements` |
| 查询主体 | `GET /v1/general/advanced-custom-elements/{task_id}` |
| 主体列表 | `GET /v1/general/advanced-custom-elements?pageNum=1&pageSize=30` |
| 预设主体 | `GET /v1/general/advanced-presets-elements?pageNum=1&pageSize=30` |
| 删除主体 | `POST /v1/general/delete-advanced-elements`，正文 `{"element_id":"..."}` |
| 创建声音 | `POST /v1/general/custom-voices` |
| 查询声音 | `GET /v1/general/custom-voices/{task_id}` |
| 声音列表 | `GET /v1/general/custom-voices?pageNum=1&pageSize=30` |
| 预设声音 | `GET /v1/general/presets-voices?pageNum=1&pageSize=30` |
| 删除声音 | `POST /v1/general/delete-voices`，正文 `{"voice_id":"..."}` |

| 操作 | 字段 |
|---|---|
| 创建主体 | `element_name`、`element_description`、`reference_type`（`image_refer` 或 `video_refer`）、`element_image_list` 或 `element_video_list`、`element_voice_id`、`tag_list`、`external_task_id` |
| 创建声音 | `voice_name`，且 `voice_url` 与 `video_id` 只填一个 |

### 创建多图主体

```bash
curl https://api.o1key.com/v1/general/advanced-custom-elements \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "element_name": "角色甲",
    "element_description": "正面与侧面参考",
    "reference_type": "image_refer",
    "element_image_list": {
      "frontal_image": "https://cdn.example.com/front.png",
      "refer_images": [{"image_url": "https://cdn.example.com/side.png"}]
    }
  }'
```
