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

# Kling 4.0 图生视频

> Kling 4.0 I2V 是 APIPod 面向可灵 Kling 4.0 提供的关键帧图生视频模式，按首帧、最多 8 张中间帧与可选尾帧生成 3-30 秒视频。

## 使用说明

* **帧**：`image_urls[0]` 为必填的首帧，可选的 `image_urls[1]` 为尾帧；中间帧按时间顺序放在 `keyframe_urls`（最多 8 张）。输出画幅跟随首帧，因此不接受 `aspect_ratio`。
* **帧数上限**：帧总数（首帧 + 中间帧 + 尾帧）受 `duration` 限制：3 秒 4 帧、4 秒 5 帧、5 秒 6 帧、6 秒 7 帧、7 秒 8 帧、8 秒 9 帧，9 秒及以上 10 帧。超出上限会在创建任务前直接返回 400。
* **引用帧**：在 prompt 中用 `@first_frame`、`@keyframe_1`..`@keyframe_N`、`@last_frame` 描述各帧发生的内容，只能引用实际提供的帧。
* **音频**：每段视频都带原生音频，因此没有 `generate_audio` 参数，传入会被拒绝。
* **不支持**：`negative_prompt`、`multi_shot` / `multi_prompt`、参考视频、`kling_elements`、`voices` 与 4K 输出。

## 计费

按输出视频时长逐秒计费，每秒费率按分辨率（720p / 1080p）区分，与帧数无关。具体价格以 [模型页](https://www.apipod.ai/models) 展示为准。

## 任务流程

创建请求返回 `data.task_id`。使用[查询视频任务](https://docs.apipod.ai/zh-CN/query-video-task.md)轮询，直到 `status` 变为 `completed`（结果位于 `data.result`）或 `failed`；也可以传入 `callback_url`，在任务进入终态时接收通知。


## OpenAPI

````yaml api-reference/openapi/kling-4.0--kling-4.0-i2v.zh.yaml POST /v1/videos/generations
openapi: 3.1.0
info:
  title: Kling 4.0 Image to Video API
  version: 1.0.0
  description: >-
    Kling 4.0 I2V 是 APIPod 面向可灵 Kling 4.0 提供的关键帧图生视频模式，按首帧、最多 8 张中间帧与可选尾帧生成 3-30
    秒视频。在 APIPod 中，公开模型 ID 为 kling-4.0-i2v。它接受文本与图片输入，可在提示词中以 @first_frame /
    @keyframe_N / @last_frame 引用，并通过异步视频任务返回结果。
servers:
  - url: https://api.apipod.ai
    description: 生产环境
security: []
paths:
  /v1/videos/generations:
    post:
      tags:
        - Kling 4.0 Image to Video
      summary: 创建生成任务
      description: >-
        Kling 4.0 I2V 是 APIPod 面向可灵 Kling 4.0 提供的关键帧图生视频模式，按首帧、最多 8 张中间帧与可选尾帧生成
        3-30 秒视频。在 APIPod 中，公开模型 ID 为 kling-4.0-i2v。它接受文本与图片输入，可在提示词中以
        @first_frame / @keyframe_N / @last_frame 引用，并通过异步视频任务返回结果。
      operationId: create-kling-4.0-kling-4.0-i2v
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              title: Kling 4.0 Image to Video
              properties:
                model:
                  type: string
                  title: Model ID
                  description: APIPod 公开模型 ID。
                  const: kling-4.0-i2v
                prompt:
                  type: string
                  title: Prompt
                  description: >-
                    必填，最多 8000 字。可用
                    `@first_frame`、`@keyframe_1`..`@keyframe_N`、`@last_frame`
                    引用已上传的帧；只能引用实际提供的帧，否则请求会被拒绝。
                  minLength: 1
                  maxLength: 8000
                image_urls:
                  type: array
                  title: First / Last Frame
                  description: >-
                    必填。`image_urls[0]` 为首帧，可选的 `image_urls[1]` 为尾帧；中间帧请放在
                    `keyframe_urls`。输出画幅跟随首帧。也接受 `first_frame_image` /
                    `last_frame_image` 别名。
                  minItems: 1
                  maxItems: 2
                  items:
                    type: string
                keyframe_urls:
                  type: array
                  title: Keyframes
                  description: >-
                    可选的中间帧，按时间顺序排列（最多 8 张），以 `@keyframe_1`..`@keyframe_N`
                    引用。需要先提供首帧；帧总数受 `duration` 限制。
                  maxItems: 8
                  items:
                    type: string
                duration:
                  type: integer
                  title: Duration
                  description: >-
                    输出时长（秒），3-30，默认 5。同时限制帧总数（首帧 + 中间帧 + 尾帧）：3 秒 4 帧、4 秒 5 帧、5 秒
                    6 帧、6 秒 7 帧、7 秒 8 帧、8 秒 9 帧，9 秒及以上 10 帧。
                  minimum: 3
                  maximum: 30
                  default: 5
                resolution:
                  type: string
                  title: Resolution
                  description: 输出分辨率，默认 720p。Kling 4.0 不提供 4K。
                  enum:
                    - 720p
                    - 1080p
                  default: 720p
                callback_url:
                  type: string
                  title: Callback URL
                  description: 接收任务终态通知的 HTTPS 地址。
                  default: ''
              required:
                - model
                - prompt
                - image_urls
            examples:
              keyframes:
                summary: 首帧、中间帧与尾帧
                value:
                  model: kling-4.0-i2v
                  prompt: >-
                    The girl in @first_frame walks out, passes the street in
                    @keyframe_1 and arrives at the party in @last_frame.
                  image_urls:
                    - https://cdn.example.com/first.png
                    - https://cdn.example.com/last.png
                  keyframe_urls:
                    - https://cdn.example.com/street.png
                  duration: 10
                  resolution: 720p
              first_frame:
                summary: 仅首帧
                value:
                  model: kling-4.0-i2v
                  prompt: The camera slowly pushes in as @first_frame comes alive.
                  image_urls:
                    - https://cdn.example.com/first.png
                  duration: 5
      responses:
        '200':
          description: 任务已受理
          content:
            application/json:
              schema:
                type: object
                title: Task Submit Response
                description: 创建任务的标准响应
                properties:
                  code:
                    type: integer
                  data:
                    type: object
                    title: Task Submit Data
                    description: 创建任务的数据内容
                    properties:
                      task_id:
                        type: string
                        description: 用于查询任务状态的 APIPod 任务 ID。
                  message:
                    type: string
                required:
                  - code
                  - message
                  - data
              example:
                code: 200
                message: success
                data:
                  task_id: vid_task_01JEXAMPLE
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: Shell
          label: cURL
          source: |-
            curl https://api.apipod.ai/v1/videos/generations \
              -H "Authorization: Bearer $APIPOD_API_KEY" \
              -H "Content-Type: application/json" \
              -d '{
              "model": "kling-4.0-i2v",
              "prompt": "The girl in @first_frame walks out, passes the street in @keyframe_1 and arrives at the party in @last_frame.",
              "image_urls": [
                "https://cdn.example.com/first.png",
                "https://cdn.example.com/last.png"
              ],
              "keyframe_urls": [
                "https://cdn.example.com/street.png"
              ],
              "duration": 10,
              "resolution": "720p"
            }'
        - lang: Python
          label: Python
          source: |-
            import os
            import requests

            payload = {
              "model": "kling-4.0-i2v",
              "prompt": "The girl in @first_frame walks out, passes the street in @keyframe_1 and arrives at the party in @last_frame.",
              "image_urls": [
                "https://cdn.example.com/first.png",
                "https://cdn.example.com/last.png"
              ],
              "keyframe_urls": [
                "https://cdn.example.com/street.png"
              ],
              "duration": 10,
              "resolution": "720p"
            }

            response = requests.post(
                "https://api.apipod.ai/v1/videos/generations",
                headers={
                    "Authorization": f"Bearer {os.environ['APIPOD_API_KEY']}",
                    "Content-Type": "application/json",
                },
                json=payload,
                timeout=60,
            )
            response.raise_for_status()
            print(response.json())
        - lang: Go
          label: Go
          source: |-
            package main

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

            func main() {
                body := []byte(`{
              "model": "kling-4.0-i2v",
              "prompt": "The girl in @first_frame walks out, passes the street in @keyframe_1 and arrives at the party in @last_frame.",
              "image_urls": [
                "https://cdn.example.com/first.png",
                "https://cdn.example.com/last.png"
              ],
              "keyframe_urls": [
                "https://cdn.example.com/street.png"
              ],
              "duration": 10,
              "resolution": "720p"
            }`)

                req, err := http.NewRequest(http.MethodPost, "https://api.apipod.ai/v1/videos/generations", bytes.NewReader(body))
                if err != nil {
                    panic(err)
                }
                req.Header.Set("Authorization", "Bearer "+os.Getenv("APIPOD_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(resp.Status, string(out))
            }
        - lang: Rust
          label: Rust
          source: |-
            use reqwest::Client;
            use serde_json::json;
            use std::env;

            #[tokio::main]
            async fn main() -> Result<(), Box<dyn std::error::Error>> {
                let payload = json!({
                  "model": "kling-4.0-i2v",
                  "prompt": "The girl in @first_frame walks out, passes the street in @keyframe_1 and arrives at the party in @last_frame.",
                  "image_urls": [
                    "https://cdn.example.com/first.png",
                    "https://cdn.example.com/last.png"
                  ],
                  "keyframe_urls": [
                    "https://cdn.example.com/street.png"
                  ],
                  "duration": 10,
                  "resolution": "720p"
                });
                let response = Client::new()
                    .post("https://api.apipod.ai/v1/videos/generations")
                    .bearer_auth(env::var("APIPOD_API_KEY")?)
                    .json(&payload)
                    .send()
                    .await?
                    .error_for_status()?;

                println!("{}", response.text().await?);
                Ok(())
            }
        - lang: JavaScript
          label: JavaScript
          source: >-
            const response = await
            fetch("https://api.apipod.ai/v1/videos/generations", {
              method: "POST",
              headers: {
                Authorization: `Bearer ${process.env.APIPOD_API_KEY}`,
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                "model": "kling-4.0-i2v",
                "prompt": "The girl in @first_frame walks out, passes the street in @keyframe_1 and arrives at the party in @last_frame.",
                "image_urls": [
                  "https://cdn.example.com/first.png",
                  "https://cdn.example.com/last.png"
                ],
                "keyframe_urls": [
                  "https://cdn.example.com/street.png"
                ],
                "duration": 10,
                "resolution": "720p"
              }),
            });


            if (!response.ok) {
              throw new Error(`APIPod request failed: ${response.status} ${await response.text()}`);
            }


            console.log(await response.json());
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: APIPod API key
      description: 在 Authorization 请求头中使用 Bearer APIPod_API_KEY。

````

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