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

# Tạo một tác vụ video Kling từ nhiều ảnh

> Tạo video Kling từ nhiều ảnh thông qua CometAPI POST /kling/v1/videos/multi-image2video, với điều khiển chuyển động và các thiết lập đầu ra cho quá trình tạo.

Sử dụng endpoint này khi một ảnh nguồn là không đủ và bạn muốn Kling tạo chuyển động từ nhiều ảnh tham chiếu.

## Trước khi gọi

* Chuẩn bị từ 1 đến 4 ảnh trong `image_list`
* Sử dụng ảnh đáp ứng yêu cầu pixel của Kling; các ảnh thu nhỏ quá nhỏ sẽ bị tác vụ tạo từ chối
* Bỏ qua `model_name` trừ khi bạn thực sự cần chọn một model tương thích với route
* Giữ lần thử đầu tiên đơn giản: một prompt ngắn, `duration: 5`, không có thiết lập callback bổ sung
* Không gửi các trường mask của image-to-video như `static_mask` hoặc `dynamic_masks` trên route này

## Luồng tác vụ

<Steps>
  <Step title="Gửi yêu cầu nhiều ảnh">
    Gửi danh sách ảnh, prompt và thời lượng, sau đó lưu Kling `task_id` được trả về.
  </Step>

  <Step title="Thăm dò tác vụ">
    Tiếp tục với [Lấy một tác vụ Kling](./individual-queries) cho đến khi tác vụ đạt trạng thái kết thúc.
  </Step>

  <Step title="Lưu trữ kết quả">
    Lưu video đã hoàn tất nếu bạn cần lưu giữ vượt quá URL phân phối của nhà cung cấp.
  </Step>
</Steps>

<Tip>
  Để xem tài liệu tham chiếu tham số đầy đủ, hãy xem [tài liệu Kling chính thức](https://kling.ai/document-api/apiReference/model/multiImageToVideo).
</Tip>


## OpenAPI

````yaml api/openapi/video/kling/post-multi-image-to-video.openapi.json POST /kling/v1/videos/multi-image2video
openapi: 3.1.0
info:
  title: Multi-Image to Video API
  version: 1.0.0
  description: Create a Kling video task from multiple source images.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /kling/v1/videos/multi-image2video:
    post:
      summary: Create a Kling multi-image-to-video task
      description: >-
        Submit 2 to 4 images plus a motion prompt and receive a task id for
        later polling.
      operationId: multi_image_to_video
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - image_list
              properties:
                model_name:
                  type: string
                  description: >-
                    Kling model variant for multi-image video. Omit to use
                    `kling-v1-6`.
                  default: kling-v1-6
                  enum:
                    - kling-v1-6
                image_list:
                  type: array
                  description: >-
                    Input image references. Provide 1 to 4 items that meet Kling
                    pixel requirements; very small thumbnails are rejected.
                  minItems: 1
                  maxItems: 4
                  items:
                    type: object
                    required:
                      - image
                    properties:
                      image:
                        type: string
                        description: Image URL or base64 image string.
                prompt:
                  type: string
                  description: Text prompt describing the desired motion and scene.
                negative_prompt:
                  type: string
                  description: Elements to avoid in the generated video.
                mode:
                  type: string
                  description: >-
                    Generation mode. Use `std` or `pro`; omitted requests use
                    `std`.
                  enum:
                    - std
                    - pro
                  default: std
                duration:
                  type: string
                  description: >-
                    Output video length in seconds. Use `5` or `10`; omitted
                    requests use `5`.
                  default: '5'
                aspect_ratio:
                  type: string
                  description: >-
                    Requested frame aspect ratio when the model needs an
                    explicit frame shape.
                  enum:
                    - '16:9'
                    - '9:16'
                    - '1:1'
                callback_url:
                  type: string
                  description: Webhook URL to receive task status updates.
                external_task_id:
                  type: string
                  description: >-
                    Custom task id for your own tracking. Must be unique per
                    account.
              default:
                image_list:
                  - image: https://your-image-host/first-frame.jpg
                  - image: https://your-image-host/second-frame.jpg
                prompt: A smooth transition between the two reference moments
                mode: std
                duration: '5'
                aspect_ratio: '1:1'
            examples:
              Default:
                summary: Multi-image video request
                value:
                  image_list:
                    - image: https://your-image-host/first-frame.jpg
                    - image: https://your-image-host/second-frame.jpg
                  prompt: A smooth transition between the two reference moments
                  mode: std
                  duration: '5'
                  aspect_ratio: '1:1'
      responses:
        '200':
          description: Task accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - data
                properties:
                  code:
                    type: integer
                    description: Error code; specifically define the error code
                  message:
                    type: string
                    description: error message
                  data:
                    type: object
                    required:
                      - task_id
                      - task_status
                      - created_at
                      - updated_at
                    properties:
                      task_id:
                        type: string
                        description: Task ID, system generated
                      task_status:
                        type: string
                        description: >-
                          Task status, enumerated values: submitted, processing,
                          succeed, failed.
                      task_status_msg:
                        type: string
                      task_info:
                        type: object
                        additionalProperties: true
                      created_at:
                        type: integer
                        description: Task creation time, Unix timestamp, in ms.
                      updated_at:
                        type: integer
                        description: Task update time, Unix timestamp, in ms.
                example:
                  code: 0
                  message: SUCCEED
                  data:
                    task_id: '861309198188019719'
                    task_status: submitted
                    task_info: {}
                    created_at: 1773380633979
                    updated_at: 1773380633979
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/kling/v1/videos/multi-image2video \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                  "image_list": [
                    {
                      "image": "https://your-image-host/first-frame.jpg"
                    },
                    {
                      "image": "https://your-image-host/second-frame.jpg"
                    }
                  ],
                  "prompt": "A smooth transition between the two reference moments",
                  "mode": "std",
                  "duration": "5",
                  "aspect_ratio": "1:1"
                }'
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/kling/v1/videos/multi-image2video",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                  "image_list": [
                    {
                      "image": "https://your-image-host/first-frame.jpg"
                    },
                    {
                      "image": "https://your-image-host/second-frame.jpg"
                    }
                  ],
                  "prompt": "A smooth transition between the two reference moments",
                  "mode": "std",
                  "duration": "5",
                  "aspect_ratio": "1:1"
                },
            )

            result = response.json()
            print(result.get("code"), result.get("data", {}).get("task_id"))
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/kling/v1/videos/multi-image2video",
            {
              method: "POST",
              headers: {
                Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                "image_list": [
                  {
                    "image": "https://your-image-host/first-frame.jpg"
                  },
                  {
                    "image": "https://your-image-host/second-frame.jpg"
                  }
                ],
                "prompt": "A smooth transition between the two reference moments",
                "mode": "std",
                "duration": "5",
                "aspect_ratio": "1:1"
              }),
            });


            const result = await response.json();

            console.log(result.code, result.data?.task_id);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````