> ## 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 video Kling Omni

> Tạo tác vụ video Kling Omni với ID mô hình trong URL, sau đó truy xuất kết quả bằng ID tác vụ.

Sử dụng `POST /omni-video/{model}` để tạo tác vụ video Kling Omni bất đồng bộ. Đặt ID mô hình trong URL và cung cấp dữ liệu đầu vào trong `contents`.

## Chọn mô hình

* `kling-4.0`: `720p` hoặc `1080p`; 3-30 giây; không có trường `audio`. Hỗ trợ tỷ lệ khung hình `adaptive` bên cạnh các tỷ lệ cố định và chấp nhận nội dung `middle_frame`.
* `kling-3.0-omni`: `720p`, `1080p`, hoặc `4k`; 3-15 giây; âm thanh `native`, `original` hoặc `off`.
* `kling-o1`: `720p` hoặc `1080p`; 3-10 giây; âm thanh `original` hoặc `off`.

Ví dụ chỉ dùng văn bản sử dụng `kling-3.0-omni`. Để tạo video không có âm thanh, đặt `settings.audio` thành `off`.

## Tham số yêu cầu

| Trường | Bắt buộc | Mô tả |
| - | - | - |
| Đường dẫn `model` | Có | ID mô hình trong URL. Chọn một ID từ danh sách ở trên; không thêm ID này vào phần thân yêu cầu. |
| `contents` | Có | Mảng đầu vào video không được để trống. Đối với yêu cầu chỉ có văn bản, hãy thêm một mục `prompt`. |
| `contents[].type` | Có | `prompt`, `first_frame`, `middle_frame`, `last_frame`, `refer_image`, `feature_video`, hoặc `base_video`. `middle_frame` có sẵn với `kling-4.0`. Một `last_frame` cần có `first_frame`. |
| `contents[].text` | Đối với mục `prompt` | Văn bản mô tả video. |
| `contents[].url` | Đối với các mục hình ảnh hoặc video | URL hình ảnh hoặc dữ liệu hình ảnh Base64; các mục video sử dụng URL video công khai. |
| `settings.resolution` | Không | Độ phân giải đầu ra. Nếu bỏ qua, yêu cầu sẽ sử dụng `720p`. Các giá trị có thể dùng phụ thuộc vào `model`. |
| `settings.aspect_ratio` | Không | Tỷ lệ khung hình: `adaptive` (chỉ dành cho `kling-4.0`), `16:9`, `9:16` hoặc `1:1`. Giá trị mặc định là `16:9`. |
| `settings.duration` | Không | Thời lượng video tính bằng giây nguyên. Giá trị mặc định là `10` đối với `kling-4.0` và `5` đối với các mô hình khác. Sử dụng thời lượng nằm trong phạm vi của mô hình đã chọn. Gửi một số nguyên, không phải chuỗi. |
| `settings.multi_shot` | Không | Đối với `kling-3.0-omni`, đặt `true` để tạo nhiều cảnh quay hoặc `false` để tạo một cảnh quay liên tục. Không đưa trường này vào yêu cầu đối với `kling-o1`. |
| `settings.audio` | Không | Đặt `native`, `original` hoặc `off` tùy theo mô hình và đầu vào đã chọn. Không được hỗ trợ bởi `kling-4.0`. |
| `options.callback_url` | Không | URL HTTPS nhận các lệnh gọi lại về trạng thái tác vụ. |
| `options.external_task_id` | Không | Mã định danh tác vụ của riêng bạn để đối chiếu; hãy giữ lại `data.id` được trả về để truy vấn. |
| `options.watermark_info.enabled` | Không | Đặt thành `true` để yêu cầu thêm hình mờ. |

Đối với `kling-4.0`, chỉ được phép có tối đa một mục nội dung `base_video`. Đối với `kling-3.0-omni`, đầu vào `feature_video` yêu cầu `settings.multi_shot: true` và `settings.audio: off`. Đầu vào `base_video` yêu cầu `settings.multi_shot: false` và không thể sử dụng `settings.audio: native`. Không kết hợp `base_video` với khung hình đầu hoặc cuối.

Giá trị mặc định chính thức của `kling-3.0-omni` là `multi_shot: true`; hãy đặt trường này một cách tường minh khi cần xác định chế độ cảnh quay. Đối với `kling-o1`, Prompt có thể chứa tối đa 2500 ký tự. Nếu yêu cầu chỉ chứa một `first_frame` và không có hình ảnh hoặc video tham chiếu nào khác, hãy sử dụng thời lượng 5 hoặc 10 giây.

Để tạo video dài năm giây chỉ từ văn bản, hãy gửi phần thân yêu cầu này đến `POST /omni-video/kling-3.0-omni`:

```json theme={null}
{
  "contents": [
    {
      "type": "prompt",
      "text": "A paper boat drifts on a pond."
    }
  ],
  "settings": {
    "resolution": "720p",
    "aspect_ratio": "16:9",
    "duration": 5,
    "multi_shot": false,
    "audio": "off"
  }
}
```

Phản hồi trả về một `id` cho tác vụ bất đồng bộ:

```json theme={null}
{
  "code": 0,
  "message": "SUCCEED",
  "data": {
    "id": "example-task-id",
    "status": "submitted"
  }
}
```

Sử dụng giá trị `data.id` với [Lấy tác vụ Kling](https://apidoc.cometapi.com/vi/api/video/kling/model-routes/tasks.md) cho đến khi tác vụ hoàn tất. Đọc URL video đã hoàn thành từ mảng `outputs` của tác vụ. Lưu video vào hệ thống lưu trữ của bạn nếu cần quyền truy cập lâu dài.

Bảng OpenAPI chứa các yêu cầu Shell, Python và JavaScript tương ứng. Để xem thêm các tổ hợp đầu vào, hãy tham khảo [tài liệu tham chiếu API video Kling 3.0 Omni](https://kling.ai/document-api/api/video/3-0-omni/video-omni) hoặc [tài liệu tham chiếu API video Kling O1 Omni](https://kling.ai/document-api/api/video/o1/video-omni).


## OpenAPI

````yaml api/openapi/video/kling/model-routes/post-omni-video.openapi.json POST /omni-video/{model}
openapi: 3.1.0
info:
  title: Kling Omni video model routes
  version: 1.0.0
  description: Create a Kling Omni video task with a model ID in the URL.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /omni-video/{model}:
    post:
      summary: Create a Kling Omni video task
      description: Submit video inputs and save the returned task ID for status queries.
      operationId: createKlingModelRouteOmniVideo
      parameters:
        - name: model
          in: path
          required: true
          description: >-
            Kling Omni model ID. The selected model controls resolution,
            duration, and audio choices. `kling-4.0` adds the `adaptive` ratio
            and the `middle_frame` input role.
          schema:
            type: string
            enum:
              - kling-4.0
              - kling-3.0-omni
              - kling-o1
          example: kling-3.0-omni
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OmniVideoRequest'
            example:
              contents:
                - type: prompt
                  text: A paper boat drifts on a pond.
              settings:
                resolution: 720p
                aspect_ratio: '16:9'
                duration: 5
                multi_shot: false
                audio: 'off'
      responses:
        '200':
          description: Task created. Store `data.id` for a `GET /tasks` query.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubmitResponse'
              example:
                code: 0
                message: SUCCEED
                data:
                  id: example-task-id
                  status: submitted
      x-codeSamples:
        - lang: Shell
          label: Create task
          source: |
            curl https://api.cometapi.com/omni-video/kling-3.0-omni \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary @- <<'JSON'
            {
              "contents": [
                {
                  "type": "prompt",
                  "text": "A paper boat drifts on a pond."
                }
              ],
              "settings": {
                "resolution": "720p",
                "aspect_ratio": "16:9",
                "duration": 5,
                "multi_shot": false,
                "audio": "off"
              }
            }
            JSON
        - lang: Python
          label: Create task
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/omni-video/kling-3.0-omni",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                    "contents": [
                        {
                            "type": "prompt",
                            "text": "A paper boat drifts on a pond.",
                        }
                    ],
                    "settings": {
                        "resolution": "720p",
                        "aspect_ratio": "16:9",
                        "duration": 5,
                        "multi_shot": False,
                        "audio": "off",
                    },
                },
            )
            response.raise_for_status()
            result = response.json()
            print(result["data"]["id"])
        - lang: JavaScript
          label: Create task
          source: |
            const response = await fetch(
              "https://api.cometapi.com/omni-video/kling-3.0-omni",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify({
                  "contents": [
                    {
                      "type": "prompt",
                      "text": "A paper boat drifts on a pond."
                    }
                  ],
                  "settings": {
                    "resolution": "720p",
                    "aspect_ratio": "16:9",
                    "duration": 5,
                    "multi_shot": false,
                    "audio": "off"
                  }
                }),
              },
            );
            if (!response.ok) throw new Error(`HTTP ${response.status}`);
            const result = await response.json();
            console.log(result.data.id);
components:
  schemas:
    OmniVideoRequest:
      type: object
      required:
        - contents
      properties:
        contents:
          type: array
          minItems: 1
          description: Video input items. Send a prompt item for text-only generation.
          items:
            $ref: '#/components/schemas/ContentItem'
        settings:
          $ref: '#/components/schemas/OmniSettings'
        options:
          $ref: '#/components/schemas/TaskOptions'
      additionalProperties: false
      description: >-
        Omni video request fields exposed by the CometAPI route. The model ID is
        a path parameter, not a body field.
    SubmitResponse:
      type: object
      required:
        - code
        - message
        - data
      properties:
        code:
          type:
            - integer
            - string
          description: Result code. `0` indicates task creation.
        message:
          type: string
          description: Result message.
        msg:
          type: string
          description: Additional result message, when included.
        data:
          type: object
          description: Task identification and submission status.
          required:
            - id
            - status
          properties:
            id:
              type: string
              description: System task ID for a `GET /tasks` query.
            status:
              type: string
              enum:
                - submitted
                - processing
                - succeeded
                - failed
              description: Task status.
    ContentItem:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - prompt
            - first_frame
            - last_frame
            - refer_image
            - feature_video
            - base_video
          description: >-
            Input role. Use `prompt` for text, an image role for a frame or
            image reference, or a video role for a video reference. A last frame
            requires a first frame.
        text:
          type: string
          maxLength: 3072
          description: >-
            Text prompt, required when `type` is `prompt`. `kling-3.0-omni`
            accepts up to 3072 characters; `kling-o1` accepts up to 2500
            characters.
        url:
          type: string
          description: >-
            Required for non-prompt items. Image items accept a public URL or
            Base64 JPG/PNG; video items accept a public MP4/MOV URL.
      allOf:
        - if:
            properties:
              type:
                const: prompt
                description: Text-prompt input role.
          then:
            required:
              - text
          else:
            required:
              - url
      additionalProperties: false
      description: Content input fields exposed by the CometAPI route.
    OmniSettings:
      type: object
      description: >-
        Output settings exposed by the CometAPI route. Set model-specific fields
        explicitly for the intended result.
      properties:
        resolution:
          type: string
          enum:
            - 720p
            - 1080p
            - 4k
          default: 720p
          description: Output resolution. `4k` applies only to `kling-3.0-omni`.
        aspect_ratio:
          type: string
          enum:
            - adaptive
            - '16:9'
            - '9:16'
            - '1:1'
          default: '16:9'
          description: >-
            Output frame shape. If you omit it, the request uses `16:9`. Set
            `adaptive` with `kling-4.0` to infer the frame from the prompt and
            reference inputs; the other models accept only the fixed ratios.
        duration:
          type: integer
          minimum: 3
          maximum: 30
          description: >-
            Requested duration in whole seconds. `kling-4.0` accepts 3 to 30
            seconds; `kling-3.0-omni` accepts 3 to 15 seconds; `kling-o1`
            accepts 3 to 10 seconds. If omitted, the request uses 10 seconds for
            `kling-4.0` and 5 seconds for the other models. For `kling-o1`, a
            request with only a `first_frame` and no other reference image or
            video must use 5 or 10 seconds. Send a JSON number, not a string.
        multi_shot:
          type: boolean
          description: >-
            For `kling-3.0-omni` only, set `true` for multiple shots or `false`
            for one continuous shot. Omit this field for `kling-o1`; the
            official default for `kling-3.0-omni` is `true`.
        audio:
          type: string
          enum:
            - native
            - original
            - 'off'
          default: 'off'
          description: >-
            `native` creates audio with `kling-3.0-omni`; `original` retains
            sound from an input video; `off` makes silent output. `kling-o1`
            accepts only `original` and `off`.
      additionalProperties: false
    TaskOptions:
      type: object
      description: Optional task fields exposed by the CometAPI route.
      properties:
        callback_url:
          type: string
          format: uri
          description: HTTPS URL that receives task status callbacks.
        external_task_id:
          type: string
          description: >-
            Your own task identifier, unique within your account. The response
            still returns the system task ID.
        watermark_info:
          type: object
          description: Watermark setting for the generated output.
          required:
            - enabled
          properties:
            enabled:
              type: boolean
              description: Set to `true` to request a watermarked result.
          additionalProperties: false
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Authenticate with your CometAPI API key.

````

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