> ## 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ụ chỉnh sửa đa phương thức của Kling

> Tạo một tác vụ chỉnh sửa video đa phương thức của Kling thông qua CometAPI: POST /kling/v1/videos/multi-elements để kết hợp nhiều phần tử và tạo video bất đồng bộ.

Sử dụng endpoint này để gửi tác vụ chỉnh sửa video đa phương thức cuối cùng sau khi phiên và các lựa chọn của bạn đã sẵn sàng.

## Quy trình đầy đủ

<Steps>
  <Step title="Khởi tạo phiên chỉnh sửa">
    Bắt đầu với [Khởi tạo video để chỉnh sửa](./initialize-video-for-editing) để lấy `session_id` cho clip bạn muốn chỉnh sửa.
  </Step>

  <Step title="Xây dựng vùng lựa chọn">
    Sử dụng [Thêm vùng chọn video](./add-video-selection) và, khi cần, [Xem trước vùng video đã chọn](./preview-selected-video-area) để tinh chỉnh vùng chỉnh sửa.
  </Step>

  <Step title="Gửi tác vụ cuối cùng">
    Gửi `session_id`, `edit_mode`, `prompt` cuối cùng và mọi cài đặt tạo tùy chọn thông qua endpoint này, sau đó lưu task id được trả về để kiểm tra trạng thái.
  </Step>
</Steps>

## Trước khi gọi endpoint này

* Đảm bảo phiên lựa chọn đã được khởi tạo
* Xác nhận vùng bạn chọn là chính xác trước khi dùng một lượt gọi tạo
* Chạy các lệnh gọi tiếp theo cho vùng chọn trên cùng một tài khoản và với đúng `session_id` được trả về từ bước khởi tạo
* Đặt `edit_mode` thành `addition`, `swap` hoặc `removal`
* Cung cấp `image_list` cho `addition` và `swap`; bỏ `image_list` cho `removal`
* Gửi `duration` dưới dạng chuỗi như `"5"` hoặc `"10"`; các ví dụ truyền `"5"` một cách rõ ràng
* Coi route này là bước tạo cuối cùng, không phải bước thiết lập
* Chỉ thêm `image_list`, `negative_prompt`, `mode`, `duration`, `callback_url` hoặc `external_task_id` khi quy trình chỉnh sửa cần đến chúng

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


## OpenAPI

````yaml api/openapi/video/kling/multimodal-video-editing/post-create-task.openapi.json POST /kling/v1/videos/multi-elements
openapi: 3.1.0
info:
  title: Create Task API
  version: 1.0.0
  description: >-
    Submit the final Kling multimodal video-editing job after the selection
    session is ready.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /kling/v1/videos/multi-elements:
    post:
      summary: Create a Kling multimodal edit task
      description: >-
        Send the `session_id`, `edit_mode`, and final edit prompt after the
        selection area has already been prepared.
      operationId: create_task
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - session_id
                - edit_mode
                - prompt
              allOf:
                - if:
                    properties:
                      edit_mode:
                        const: addition
                    required:
                      - edit_mode
                  then:
                    required:
                      - image_list
                - if:
                    properties:
                      edit_mode:
                        const: swap
                    required:
                      - edit_mode
                  then:
                    required:
                      - image_list
              properties:
                session_id:
                  type: string
                  description: >-
                    Selection session id returned by init-selection. Follow-up
                    calls must use the same account and exact session id.
                edit_mode:
                  type: string
                  description: >-
                    Editing operation for the selected video region. Use
                    `addition` to add an element, `swap` to replace a selected
                    element, or `removal` to remove it.
                  enum:
                    - addition
                    - swap
                    - removal
                prompt:
                  type: string
                  description: >-
                    Instruction describing the desired edit. Reference the
                    source video as `<<<video_1>>>` and any reference image as
                    `<<<image_1>>>`.
                model_name:
                  type: string
                  description: >-
                    Kling model variant for the final edit task. Omit to use
                    `kling-v1-6`.
                  enum:
                    - kling-v1-6
                  default: kling-v1-6
                image_list:
                  type: array
                  description: >-
                    Image references used by `addition` and `swap` tasks. Omit
                    this field for `removal` tasks.
                  minItems: 1
                  items:
                    type: object
                    required:
                      - image
                    properties:
                      image:
                        type: string
                negative_prompt:
                  type: string
                  description: Elements to avoid in the edited result.
                mode:
                  type: string
                  description: Generation mode. Use `std` or `pro`.
                  enum:
                    - std
                    - pro
                duration:
                  type: string
                  description: Requested output duration in seconds.
                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:
                session_id: <session_id>
                edit_mode: removal
                prompt: Delete the selected object from <<<video_1>>>
                mode: std
                duration: '5'
            examples:
              Default:
                summary: Multi-elements edit task
                value:
                  session_id: <session_id>
                  edit_mode: removal
                  prompt: Delete the selected object from <<<video_1>>>
                  mode: std
                  duration: '5'
              Addition:
                summary: Add an image element to the selected area
                value:
                  session_id: <session_id>
                  edit_mode: addition
                  image_list:
                    - image: https://your-image-host/object-to-add.jpg
                  prompt: >-
                    Add <<<image_1>>> naturally into <<<video_1>>> at the
                    selected area
                  mode: std
                  duration: '5'
              Swap:
                summary: Swap the selected element with an image reference
                value:
                  session_id: <session_id>
                  edit_mode: swap
                  image_list:
                    - image: https://your-image-host/new-object.jpg
                  prompt: >-
                    Use <<<image_1>>> to replace the selected object in
                    <<<video_1>>>
                  mode: std
                  duration: '5'
      responses:
        '200':
          description: Task accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - data
                properties:
                  code:
                    type: integer
                  message:
                    type: string
                  data:
                    type: object
                    properties:
                      task_id:
                        type: string
                      task_status:
                        type: string
                      created_at:
                        type: integer
                      updated_at:
                        type: integer
                    additionalProperties: true
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/kling/v1/videos/multi-elements \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                  "session_id": "<session_id>",
                  "edit_mode": "removal",
                  "prompt": "Delete the selected object from <<<video_1>>>",
                  "mode": "std",
                  "duration": "5"
                }'
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/kling/v1/videos/multi-elements",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                  "session_id": "<session_id>",
                  "edit_mode": "removal",
                  "prompt": "Delete the selected object from <<<video_1>>>",
                  "mode": "std",
                  "duration": "5"
                },
            )

            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-elements", {
              method: "POST",
              headers: {
                Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                "session_id": "<session_id>",
                "edit_mode": "removal",
                "prompt": "Delete the selected object from <<<video_1>>>",
                "mode": "std",
                "duration": "5"
              }),
            });


            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.

````