> ## 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

> First/last frames, multi-keyframe generation, image and video references, and video editing.



## OpenAPI

````yaml en/openapi/videos/kling-4-0.yaml POST /v1/videos/generate
openapi: 3.1.0
info:
  title: Kling 4.0
  version: '1.0'
  description: >-
    First/last frames, multi-keyframe generation, image and video references,
    and video editing.
servers:
  - url: https://openapi.imini.ai/imini/router
security:
  - ApiKeyAuth: []
paths:
  /v1/videos/generate:
    post:
      summary: Kling 4.0
      description: >
        - Keyframes can be mixed with references. Use at most one first and last
        frame and any supported number of `middle_frame` images.

        - Editing requires exactly one `edit_source`. Input video uses MP4 or
        MOV, 3–30 seconds per clip and 30 seconds total.

        - Audio references, audio controls, background music, and `extra_params`
        are not supported.


        After submission, [poll the task](/en/api-reference/videos/task-query).
        See [pricing](/en/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: Video prompt.
                resolution:
                  type: string
                  enum:
                    - 720P
                    - 1080P
                  default: 720P
                  description: Output resolution.
                duration:
                  type: integer
                  minimum: 3
                  maximum: 30
                  default: 5
                  description: Output duration in seconds.
                aspect_ratio:
                  type: string
                  enum:
                    - '21:9'
                    - '16:9'
                    - '9:16'
                    - '1:1'
                    - adaptive
                  description: >-
                    First-frame-only generation follows the source image aspect
                    ratio; other modes can specify a ratio.
                reference_images:
                  type: array
                  maxItems: 10
                  description: Includes keyframes.
                  items:
                    type: object
                    required:
                      - url
                    properties:
                      url:
                        type: string
                        description: >-
                          Public image URL or Base64 data URI (up to 20 MiB
                          decoded).
                      reference_type:
                        type:
                          - string
                          - 'null'
                        enum:
                          - asset
                          - first_frame
                          - middle_frame
                          - last_frame
                          - null
                        default: asset
                        description: '`null` is treated as `asset`.'
                reference_videos:
                  type: array
                  maxItems: 5
                  description: Reference videos or an edit source.
                  items:
                    type: object
                    required:
                      - url
                    properties:
                      url:
                        type: string
                        description: Public HTTP(S) video URL.
                      reference_type:
                        type:
                          - string
                          - 'null'
                        enum:
                          - asset
                          - edit_source
                          - null
                        default: asset
                        description: Mark the video to edit as `edit_source`.
                      keep_original_sound:
                        type: boolean
                        description: Keep the original audio track.
            examples:
              text:
                summary: Text to video
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: A slow forward camera move over a bay in the morning mist.
                  aspect_ratio: '16:9'
              first_frame:
                summary: First-frame generation
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: Let the clouds drift slowly while the camera remains steady.
                  reference_images:
                    - url: https://example.com/first.png
                      reference_type: first_frame
              first_last:
                summary: First and last frames
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: Make a smooth transition between the first and last frame.
                  reference_images:
                    - url: https://example.com/first.png
                      reference_type: first_frame
                    - url: https://example.com/last.png
                      reference_type: last_frame
              reference:
                summary: Mixed references
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: >-
                    Use the image for composition and the video as a guide for
                    camera movement.
                  reference_images:
                    - url: https://example.com/reference.png
                      reference_type: asset
                  reference_videos:
                    - url: https://example.com/motion.mp4
                      reference_type: asset
              edit:
                summary: Edit a source video
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: >-
                    Keep the camera motion and change the weather in the source
                    video to clear skies.
                  reference_videos:
                    - url: https://example.com/source.mp4
                      reference_type: edit_source
              multi_frame:
                summary: Multiple keyframes
                value:
                  model: kling-4.0
                  resolution: 720P
                  duration: 5
                  prompt: >-
                    Move through the corridor from the entrance to the sunlit
                    courtyard.
                  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: Task accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - task_id
                  - model
                  - created_at
                  - request_id
                properties:
                  task_id:
                    type: string
                    description: Task ID to poll.
                  model:
                    type: string
                    description: Echoes the supplied model ID.
                  created_at:
                    type: string
                    format: date-time
                    description: Task creation time (UTC).
                  request_id:
                    type: string
                    description: Request ID.
              example:
                task_id: task_2041350318103396352
                model: kling-4.0
                created_at: '2026-11-16T07:00:00.000Z'
                request_id: task_2041350318103396352
        '400':
          description: Invalid model or request parameters.
          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: Insufficient credits.
          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: Request body or Base64 media exceeds a size limit.
          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`. Manage keys in [API
        Keys](https://imini.ai/api-keys).

````

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