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

# Kling 4.0

> 首尾帧、智能多帧、图像与视频参考及视频编辑。



## OpenAPI

````yaml zh/openapi/videos/kling-4-0.yaml POST /v1/videos/generate
openapi: 3.1.0
info:
  title: Kling 4.0
  version: '1.0'
  description: 首尾帧、智能多帧、图像与视频参考及视频编辑。
servers:
  - url: https://openapi.imini.ai/imini/router
security:
  - ApiKeyAuth: []
paths:
  /v1/videos/generate:
    post:
      summary: Kling 4.0
      description: >
        - 关键帧可与参考素材混用。首帧、尾帧各最多一张，可传多张 `middle_frame`。

        - 编辑须有且仅有一段 `edit_source`。输入视频为 MP4 / MOV，每段 3–30 秒，合计不超过 30 秒。

        - 不支持参考音频、音频开关、背景音乐或 `extra_params`。


        提交后[查询任务状态](/zh/api-reference/videos/task-query)。参见[模型价格](/zh/guide/pricing)。
      operationId: generateKling40
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - prompt
              properties:
                model:
                  type: string
                  const: kling-4.0
                prompt:
                  type: string
                  minLength: 1
                  maxLength: 26000
                  description: 视频提示词。
                resolution:
                  type: string
                  enum:
                    - 720P
                    - 1080P
                  default: 720P
                  description: 输出分辨率。
                duration:
                  type: integer
                  minimum: 3
                  maximum: 30
                  default: 5
                  description: 输出时长（秒）。
                aspect_ratio:
                  type: string
                  enum:
                    - '21:9'
                    - '16:9'
                    - '9:16'
                    - '1:1'
                    - adaptive
                  description: 单首帧时跟随输入图片；其他模式可指定比例。
                reference_images:
                  type: array
                  maxItems: 10
                  description: 含关键帧。
                  items:
                    type: object
                    required:
                      - url
                    properties:
                      url:
                        type: string
                        description: 公网图片 URL 或 Base64 Data URI（解码后最多 20 MiB）。
                      reference_type:
                        type:
                          - string
                          - 'null'
                        enum:
                          - asset
                          - first_frame
                          - middle_frame
                          - last_frame
                          - null
                        default: asset
                        description: '`null` 等同于 `asset`。'
                reference_videos:
                  type: array
                  maxItems: 5
                  description: 参考视频或编辑源。
                  items:
                    type: object
                    required:
                      - url
                    properties:
                      url:
                        type: string
                        description: 公网 HTTP(S) 视频 URL。
                      reference_type:
                        type:
                          - string
                          - 'null'
                        enum:
                          - asset
                          - edit_source
                          - null
                        default: asset
                        description: 编辑源须显式标为 `edit_source`。
                      keep_original_sound:
                        type: boolean
                        description: 保留原音轨。
            examples:
              text:
                summary: 文生视频
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: 晨雾中的海湾，镜头缓慢向前移动。
                  aspect_ratio: '16:9'
              first_frame:
                summary: 首帧生成
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: 让云朵缓慢飘过，镜头保持稳定。
                  reference_images:
                    - url: https://example.com/first.png
                      reference_type: first_frame
              first_last:
                summary: 首尾帧生成
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: 平滑地从第一帧过渡到最后一帧。
                  reference_images:
                    - url: https://example.com/first.png
                      reference_type: first_frame
                    - url: https://example.com/last.png
                      reference_type: last_frame
              reference:
                summary: 组合参考
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: 参考图片中的构图，并参考视频中的镜头运动。
                  reference_images:
                    - url: https://example.com/reference.png
                      reference_type: asset
                  reference_videos:
                    - url: https://example.com/motion.mp4
                      reference_type: asset
              edit:
                summary: 编辑原视频
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: 保留原镜头，将视频中的天气改成晴天。
                  reference_videos:
                    - url: https://example.com/source.mp4
                      reference_type: edit_source
              multi_frame:
                summary: 智能多帧
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: 从入口穿过长廊，最后抵达日光下的庭院。
                  reference_images:
                    - url: https://example.com/first.png
                      reference_type: first_frame
                    - url: https://example.com/middle.png
                      reference_type: middle_frame
                    - url: https://example.com/last.png
                      reference_type: last_frame
      responses:
        '200':
          description: 任务已受理。
          content:
            application/json:
              schema:
                type: object
                required:
                  - task_id
                  - model
                  - created_at
                  - request_id
                properties:
                  task_id:
                    type: string
                    description: 任务 ID，用于轮询。
                  model:
                    type: string
                    description: 回显请求中的模型 ID。
                  created_at:
                    type: string
                    format: date-time
                    description: 任务创建时间（UTC）。
                  request_id:
                    type: string
                    description: 请求 ID。
              example:
                task_id: task_2041350318103396352
                model: kling-4.0
                created_at: '2026-11-16T07:00:00.000Z'
                request_id: task_2041350318103396352
        '400':
          description: 模型或请求参数无效。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                error:
                  code: INVALID_PARAMETER
                  message: Parameter value is out of range or has incorrect type
                  status: 400
                  request_id: req_example
        '402':
          description: 积分不足。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                error:
                  code: INSUFFICIENT_CREDITS
                  message: >-
                    Insufficient credits. Upgrade your plan or purchase
                    additional credits.
                  status: 402
                  request_id: req_example
        '413':
          description: 请求体或 Base64 素材超出大小限制。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                error:
                  code: PAYLOAD_TOO_LARGE
                  message: Request payload exceeds the supported size
                  status: 413
                  request_id: req_example
components:
  schemas:
    ApiError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - status
          properties:
            code:
              type: string
            message:
              type: string
            status:
              type: integer
            request_id:
              type: string
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: '`Bearer YOUR_API_KEY`。在 [API Keys](https://imini.ai/zh/api-keys) 管理密钥。'

````

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