> ## 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 Omni 影片

> 在 URL 中指定模型 ID 以建立 Kling Omni 影片任務，然後使用任務 ID 取得結果。

使用 `POST /omni-video/{model}` 建立非同步的 Kling Omni 影片任務。將模型 ID 放在 URL 中，並在 `contents` 中提供輸入。

## 選擇模型

* `kling-4.0`: `720p` 或 `1080p`；3–30 秒；不含 `audio` 欄位。除了固定的長寬比，也支援 `adaptive` 長寬比，並接受 `middle_frame` 內容。
* `kling-3.0-omni`: `720p`, `1080p`，或 `4k`；3–15 秒；`native`、`original` 或 `off` 音訊。
* `kling-o1`: `720p` 或 `1080p`；3–10 秒；`original` 或 `off` 音訊。

純文字範例使用 `kling-3.0-omni`。若要建立無聲影片，請將 `settings.audio` 設為 `off`。

## 請求參數

| 欄位 | 必填 | 說明 |
| - | - | - |
| 路徑 `model` | 是 | URL 中的模型 ID。請從上述清單中選擇一個 ID，不要將其加入請求主體。 |
| `contents` | 是 | 非空的影片輸入陣列。若為純文字請求，請包含一個 `prompt` 項目。 |
| `contents[].type` | 是 | `prompt`, `first_frame`, `middle_frame`, `last_frame`, `refer_image`, `feature_video`，或 `base_video`。`middle_frame` 可搭配 `kling-4.0` 使用。`last_frame` 需要 `first_frame`. |
| `contents[].text` | 對於 `prompt` 項目 | 描述影片的文字。 |
| `contents[].url` | 對於圖片或影片項目 | 圖片 URL 或 Base64 圖片資料；影片項目使用公開的影片 URL。 |
| `settings.resolution` | 否 | 輸出解析度。若省略，請求會使用 `720p`。可用值取決於 `model`. |
| `settings.aspect_ratio` | 否 | 畫面比例：`adaptive`（僅限 `kling-4.0`）、`16:9`、`9:16` 或 `1:1`。預設為 `16:9`. |
| `settings.duration` | 否 | 影片長度，以整數秒為單位。`kling-4.0` 的預設值為 `10`，其他模型的預設值為 `5`。請使用所選模型範圍內的長度。請傳送整數，而非字串。 |
| `settings.multi_shot` | 否 | 對於 `kling-3.0-omni`，設定 `true` 以使用多個鏡頭，或設定 `false` 以使用單一連續鏡頭。請勿在以下情況包含此欄位： `kling-o1`. |
| `settings.audio` | 否 | 根據所選模型和輸入，設定 `native`、`original` 或 `off`。不支援此欄位的模型： `kling-4.0`. |
| `options.callback_url` | 否 | 接收任務狀態回呼的 HTTPS URL。 |
| `options.external_task_id` | 否 | 用於關聯的自訂任務識別碼；請保留傳回的 `data.id` 以供查詢。 |
| `options.watermark_info.enabled` | 否 | 設定為 `true` 以要求加入浮水印。 |

對於 `kling-4.0`，最多允許一個 `base_video` 內容項目。對於 `kling-3.0-omni`，`feature_video` 輸入需要 `settings.multi_shot: true` 和 `settings.audio: off`。`base_video` 輸入需要 `settings.multi_shot: false`，且不能使用 `settings.audio: native`。請勿將 `base_video` 與首影格或末影格一起使用。

`kling-3.0-omni` 的官方預設值為 `multi_shot: true`；需要指定鏡頭模式時，請明確設定此欄位。對於 `kling-o1`，Prompt 最多可包含 2500 個字元。若請求只包含 `first_frame`，且沒有其他參考圖片或影片，請使用 5 秒或 10 秒的長度。

若要建立一段五秒的純文字影片，請將此請求主體傳送至 `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"
  }
}
```

回應會傳回非同步任務的 `id`：

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

將 `data.id` 值用於 [取得 Kling 任務](https://apidoc.cometapi.com/zh-Hant/api/video/kling/model-routes/tasks.md) ，直到任務完成。從任務的 `outputs` 陣列中取得完成的影片 URL。如果需要長期存取，請將影片儲存在自己的儲存空間中。

OpenAPI 面板包含對應的 Shell、Python 和 JavaScript 請求。如需更多輸入組合，請參閱 [Kling 3.0 Omni 影片 API 參考](https://kling.ai/document-api/api/video/3-0-omni/video-omni) 或 [Kling O1 Omni 影片 API 參考](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.