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

# Khởi tạo một phiên chỉnh sửa Kling

> Khởi tạo các phần tử video thông qua endpoint Kling init-selection trong CometAPI để bắt đầu chỉnh sửa đa phương thức với các vùng và mốc thời gian có thể chọn.

Sử dụng endpoint này để mở một phiên chỉnh sửa video và lấy `session_id` cần thiết cho mọi bước chỉnh sửa đa phương thức về sau.

## Chọn một đường dẫn đầu vào

* Video do Kling tạo: gửi `video_id`
* Video bên ngoài hoặc đã được lưu trữ sẵn: gửi `video_url`
* Không gửi cả hai đường dẫn đầu vào cùng một lúc
* Không gửi `task_id` gốc ở đây; hãy lưu `session_id` được trả về cho các bước tiếp theo

## Vai trò trong quy trình

<Steps>
  <Step title="Khởi tạo phiên">
    Gửi clip nguồn và lưu `session_id` được trả về.
  </Step>

  <Step title="Đánh dấu các điểm chọn">
    Tiếp tục với [Add Video Selection](./add-video-selection) để xác định vùng bạn muốn chỉnh sửa.
  </Step>

  <Step title="Gửi tác vụ chỉnh sửa cuối cùng">
    Sau khi hoàn tất lựa chọn, tiếp tục với [Create Task](./create-task).
  </Step>
</Steps>

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


## OpenAPI

````yaml api/openapi/video/kling/multimodal-video-editing/post-initialize-video-for-editing.openapi.json POST /kling/v1/videos/multi-elements/init-selection
openapi: 3.1.0
info:
  title: Initialize Video for Editing API
  version: 1.0.0
  description: >-
    Open a Kling multimodal editing session from either a Kling-generated video
    or an external video URL.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /kling/v1/videos/multi-elements/init-selection:
    post:
      summary: Initialize a Kling multimodal editing session
      description: >-
        Send exactly one source: either `video_id` from a completed Kling video
        task, or `video_url` for an already-hosted video. The response opens the
        session used by later selection-editing calls.
      operationId: initialize_video_for_editing
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              oneOf:
                - required:
                    - video_id
                - required:
                    - video_url
              properties:
                video_id:
                  type: string
                  description: >-
                    Kling video id from a completed task. Send exactly one of
                    video_id or video_url.
                video_url:
                  type: string
                  description: >-
                    Public MP4 or MOV URL. Send exactly one of video_id or
                    video_url.
              default:
                video_id: <video_id>
            examples:
              From video_id:
                summary: Initialize from a Kling video id
                value:
                  video_id: <video_id>
              From video_url:
                summary: Initialize from a video URL
                value:
                  video_url: https://your-video-host/source.mp4
      responses:
        '200':
          description: Session initialized.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - data
                properties:
                  code:
                    type: integer
                  message:
                    type: string
                  data:
                    type: object
                    properties:
                      session_id:
                        type: string
                    additionalProperties: true
      x-codeSamples:
        - lang: Shell
          label: Default
          source: >
            curl
            https://api.cometapi.com/kling/v1/videos/multi-elements/init-selection
            \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                  "video_id": "<video_id>"
                }'
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/kling/v1/videos/multi-elements/init-selection",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                  "video_id": "<video_id>"
                },
            )

            result = response.json()
            print(result.get("code"), result.get("data", {}).get("session_id"))
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/kling/v1/videos/multi-elements/init-selection",
            {
              method: "POST",
              headers: {
                Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                "video_id": "<video_id>"
              }),
            });


            const result = await response.json();

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

````