> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dreamto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Kling 4.0

> 可灵 Kling 4.0：一次生成 3 ~ 30 秒、音画同出的视频，支持文生视频、图生视频和首尾帧，最高 4K。

`kling-4.0` 是快手可灵 AI 于 2026 年 10 月正式发布的新一代视频生成模型，定位专业级视频创作：单次生成即可得到长达 30 秒的长镜头，适合连续叙事，复杂运镜和快速动作下的画面连贯性也更好。画面和声音同步生成；支持文生视频、首帧图生视频和首尾帧生视频。原生输出 720P / 1080P，并提供 2K / 4K 超分输出。需要多张参考图、参考视频、参考音频或视频编辑时，请使用 [Kling 4.0 Omni](https://docs.dreamto.ai/video/models/kling-4-0-omni.md)。

* **长时长**：单次生成 3 \~ 30 秒，无需分段拼接。
* **原生音画同出**：视频自带与画面同步生成的声音。
* **分辨率**：720P / 1080P 原生输出，2K / 4K 超分输出。
* **宽高比**：16:9、9:16、1:1、21:9。
* **生成模式**：文生视频、图生视频（首帧）、首尾帧生视频。

## 能力一览

| 模式 | 参数 | 说明 |
| - | - | - |
| 文生视频 | `prompt` | 用 `aspect_ratio` 指定宽高比 |
| 图生视频（首帧） | `image_url`，可选 `prompt` | 输出比例跟随首帧图片 |
| 首尾帧生视频 | `image_url` + `last_frame_url`，可选 `prompt` | 从首帧过渡到尾帧 |

## 接口

接口为异步任务：创建任务后轮询查询，完成后从 `video_url` 下载视频。`model` 填 `kling-4.0`，生成参数全部放在 `input` 中。

| 接口 | 用途 |
| - | - |
| [`POST /v1/videos`](https://docs.dreamto.ai/api-reference/kling-4-0/create-task) | 创建视频生成任务 |
| [`GET /v1/videos/{task_id}`](https://docs.dreamto.ai/api-reference/kling-4-0/query-task) | 查询视频生成任务 |

## 快速开始

创建任务拿到 `task_id`，每 10 \~ 15 秒查询一次，`status` 为 `completed` 时从 `video_url` 下载视频。示例中的 `$DREAMTO_API_KEY` 为你的 API Key。

```bash cURL theme={null}
# 1. 创建任务
curl -X POST "https://api.dreamto.ai/v1/videos" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-4.0",
    "input": {
      "prompt": "一只小熊猫在雪地里慢慢行走，回头看向镜头，电影感，浅景深",
      "resolution": "1080P",
      "duration": 5,
      "aspect_ratio": "16:9"
    }
  }'

# 2. 查询任务
curl "https://api.dreamto.ai/v1/videos/job_02b88886c4fda5be35baff61" \
  -H "Authorization: Bearer $DREAMTO_API_KEY"
```

```python Python theme={null}
import os
import time

import requests

BASE_URL = "https://api.dreamto.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['DREAMTO_API_KEY']}"}

payload = {
    "model": "kling-4.0",
    "input": {
        "prompt": "一只小熊猫在雪地里慢慢行走，回头看向镜头，电影感，浅景深",
        "resolution": "1080P",
        "duration": 5,
        "aspect_ratio": "16:9"
    }
}

task = requests.post(f"{BASE_URL}/v1/videos", headers=HEADERS, json=payload, timeout=60).json()
task_id = task["task_id"]
while task["status"] not in ("completed", "failed"):
    time.sleep(10)
    task = requests.get(f"{BASE_URL}/v1/videos/{task_id}", headers=HEADERS, timeout=60).json()
print(task["status"], task.get("video_url"), task.get("error"))
```

## 生成模式

### 文生视频

只传提示词，用 `aspect_ratio` 指定宽高比。

```bash cURL theme={null}
curl -X POST "https://api.dreamto.ai/v1/videos" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-4.0",
    "input": {
      "prompt": "一只小熊猫在雪地里慢慢行走，回头看向镜头，电影感，浅景深",
      "resolution": "1080P",
      "duration": 5,
      "aspect_ratio": "16:9"
    }
  }'
```

### 图生视频（首帧）

`image_url` 作为视频的第一帧，输出比例跟随图片。

```bash cURL theme={null}
curl -X POST "https://api.dreamto.ai/v1/videos" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-4.0",
    "input": {
      "prompt": "女孩转过头，对着狐狸微笑，微风吹动头发",
      "image_url": "https://your-cdn.example.com/first-frame.png",
      "resolution": "720P",
      "duration": 5
    }
  }'
```

### 首尾帧生视频

同时传 `image_url` 和 `last_frame_url`，生成从首帧过渡到尾帧的视频。

```bash cURL theme={null}
curl -X POST "https://api.dreamto.ai/v1/videos" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-4.0",
    "input": {
      "prompt": "镜头缓慢推进，白天逐渐变为夜晚，城市灯光亮起",
      "image_url": "https://your-cdn.example.com/first-frame.png",
      "last_frame_url": "https://your-cdn.example.com/last-frame.png",
      "resolution": "1080P",
      "duration": 8
    }
  }'
```

### 4K 竖屏长视频

一次生成 15 秒的 9:16 竖屏视频，4K 超分输出。

```bash cURL theme={null}
curl -X POST "https://api.dreamto.ai/v1/videos" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-4.0",
    "input": {
      "prompt": "雨后的霓虹街头，一位撑伞的行人从远处走来，镜头跟随，地面倒映灯光",
      "resolution": "4K",
      "duration": 15,
      "aspect_ratio": "9:16"
    }
  }'
```

## 参数

以下参数都放在请求体的 `input` 中。

| 参数 | 类型 | 必填 | 默认值 | 取值 | 说明 |
| - | - | - | - | - | - |
| `prompt` | string | 否 | — | — | 提示词，描述视频的内容、动作和镜头。文生视频时必填。 |
| `image_url` | string（图片 URL） | 否 | — | — | 首帧图片的公网 URL，传入后为图生视频。支持 jpeg / jpg / png，不超过 10MB。 |
| `last_frame_url` | string（图片 URL） | 否 | — | — | 尾帧图片的公网 URL，必须与 `image_url` 一起使用，生成从首帧过渡到尾帧的视频。支持 jpeg / jpg / png，不超过 10MB。 |
| `resolution` | string | 否 | `720P` | `720P` / `1080P` / `2K` / `4K` | 输出分辨率，默认 `720P`。 |
| `duration` | integer | 否 | `5` | `3` \~ `30` | 输出视频时长，单位秒，`3` \~ `30` 的整数，默认 `5`。 |
| `aspect_ratio` | string | 否 | — | `16:9` / `9:16` / `1:1` / `21:9` | 输出宽高比，用于文生视频。传入首帧图片时输出比例跟随图片。 |

完整的请求与响应定义见 [创建视频生成任务](https://docs.dreamto.ai/api-reference/kling-4-0/create-task.md)。

## 响应与任务状态

创建任务返回 `task_id`、`status`、`model`、`created_at` 和 `request_id`。查询任务在此基础上返回 `completed_at`（任务结束后）、`video_url`（成功时）和 `error`（失败时）。

| `status` | 含义 |
| - | - |
| `queued` | 排队中。 |
| `in_progress` | 生成中。 |
| `completed` | 生成成功，从 `video_url` 下载视频。 |
| `failed` | 生成失败，原因见 `error`，不扣费。 |

生成成功的查询响应：

```json theme={null}
{
  "task_id": "job_02b88886c4fda5be35baff61",
  "status": "completed",
  "model": "kling-4.0",
  "created_at": 1794846663,
  "completed_at": 1794847019,
  "request_id": "req_6a9a539502118ba1c33f1bfc",
  "video_url": "https://cdn.example.com/videos/02b88886c4fda5be35baff61.mp4"
}
```

生成失败的查询响应：

```json theme={null}
{
  "task_id": "job_02b88886c4fda5be35baff61",
  "status": "failed",
  "model": "kling-4.0",
  "created_at": 1794846663,
  "completed_at": 1794847019,
  "request_id": "req_6a9a539502118ba1c33f1bfc",
  "error": {
    "type": "api_error",
    "message": "InvalidParameterValue: Please input the ImageURL that can be retrieved from the external network."
  }
}
```

## 计费

按输出视频时长（秒）× 所选分辨率的单价计费。

| 分辨率 | 美元 / 秒 | 人民币 / 秒 |
| - | - | - |
| 720P | \$0.157 | ¥1.0 |
| 1080P | \$0.2355 | ¥1.5 |
| 2K | \$0.2826 | ¥1.8 |
| 4K | \$0.471 | ¥3.0 |

以上为刊例价，实际价格以控制台显示的模型价格为准。生成失败的任务和参数错误的请求不扣费。

## 限制与注意事项

* `video_url` 自任务完成起 7 天内有效，请及时下载并保存到自己的存储。
* 输入素材必须是公网可直接下载的 URL；托管在海外的素材也可以使用。
* 生成的视频均带有声音；本模型没有关闭声音的参数。
* `last_frame_url` 必须和 `image_url` 一起使用；传入首帧图片后 `aspect_ratio` 不生效，输出比例跟随图片。
* 2K、4K 为超分输出，按对应分辨率的单价计费。
* 失败的任务返回 `status: "failed"`，原因在 `error.message` 中（例如 `InvalidParameterValue: Please input the ImageURL that can be retrieved from the external network.`），不扣费。
* 创建任务时按请求的预估价格（分辨率单价 × 时长）预先冻结余额，任务完成后按实际用量结算。余额不足时创建请求直接返回 HTTP 402（`insufficient_balance`），不创建任务。
* 参数不合法的请求返回 HTTP 400，不创建任务、不扣费。时长和素材数量超出范围时，错误信息会指出字段和允许范围（形如 `input.duration must be a number between <最小值> and <最大值>`）；`resolution`、`aspect_ratio` 等枚举参数取值不在允许列表内时，错误信息是通用的，不会指出具体字段，请对照参数表检查。素材格式和内容由模型校验：不符合要求时任务以 `failed` 结束，同样不扣费。
* 视频生成需要数分钟，建议每 10 \~ 15 秒查询一次任务，不要更频繁。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.