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

# 建立 Kling 多圖影片任務

> 透過 CometAPI POST /kling/v1/videos/multi-image2video 從多張圖片建立 Kling 影片，並提供動作控制與生成輸出設定。

當單一來源圖片不足以滿足需求，而你希望 Kling 根據多張圖片參考建立動作時，請使用此端點。

## 呼叫前準備

* 在 `image_list` 中準備 1 到 4 張圖片
* 使用符合 Kling 像素要求的圖片；過小的縮圖會被生成任務拒絕
* 除非你明確需要選擇與路由相容的模型，否則請省略 `model_name`
* 第一次測試請保持簡單：簡短的 prompt、`duration: 5`，且不要加入額外的 callback 設定
* 請勿在此路由上傳送 image-to-video 的遮罩欄位，例如 `static_mask` 或 `dynamic_masks`

## 任務流程

<Steps>
  <Step title="提交多圖請求">
    傳送圖片清單、prompt 和 duration，然後保存回傳的 Kling `task_id`。
  </Step>

  <Step title="輪詢任務">
    持續使用 [取得 Kling 任務](./individual-queries)，直到任務進入最終狀態。
  </Step>

  <Step title="保存結果">
    如果你需要在供應商提供的交付 URL 之外保留結果，請儲存已完成的影片。
  </Step>
</Steps>

<Tip>
  如需完整的參數參考，請參閱[官方 Kling 文件](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.

````