> ## Documentation Index
> Fetch the complete documentation index at: https://docs.comfy.org/llms.txt
> Use this file to discover all available pages before exploring further.

# 通过 Comfy Router 使用 Kling V3 Omni

> 通过 Comfy Router 调用 kling/kling-v3-omni：端点、请求结构以及 Router 返回的响应。

`kling/kling-v3-omni` 的 API 参考，由 Comfy Router 提供，模型来自 Kling。

## 快速开始

在[你的 Comfy 工作区](https://platform.comfy.org/profile/api-keys)中创建密钥，并将其导出为 `COMFY_API_KEY`。Python 和 TypeScript 代码片段使用 Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`）；cURL 代码片段是通过原始 HTTP 执行的同一调用。

**模型 ID：** `kling/kling-v3-omni`

**端点：** `POST https://api.comfy.org/v2/models/kling/kling-v3-omni`

<Tabs>
  <Tab title="Wait for the result">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # The SDK automatically creates an idempotency key and reuses it for automatic retries.
      with Comfy() as client:
          result = client.models.run(
              "kling/kling-v3-omni",
              {
                  "aspect_ratio": "16:9",
                  "duration": "5",
                  "mode": "pro",
                  "prompt": "A paper boat drifting down a rain-soaked street at dusk.",
              },
          )

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // Reads COMFY_API_KEY from the environment.
      // The SDK automatically creates an idempotency key and reuses it for automatic retries.
      const { data } = await comfy.models.run("kling/kling-v3-omni", {
        aspect_ratio: "16:9",
        duration: "5",
        mode: "pro",
        prompt: "A paper boat drifting down a rain-soaked street at dusk.",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/kling/kling-v3-omni \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"aspect_ratio\": \"16:9\", \"duration\": \"5\", \"mode\": \"pro\", \"prompt\": \"A paper boat drifting down a rain-soaked street at dusk.\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Queue and collect later">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      with Comfy() as client:
          handle = client.models.submit(
              "kling/kling-v3-omni",
              {
                  "aspect_ratio": "16:9",
                  "duration": "5",
                  "mode": "pro",
                  "prompt": "A paper boat drifting down a rain-soaked street at dusk.",
              },
          )
          print("request_id:", handle.request_id)  # with the model ID, all another process needs

          # Poll until the request completes, waiting the Retry-After the server names.
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # The provider's own payload, the same value models.run() returns.
          # A request that failed or was cancelled raises the typed Router error here.
          result = handle.get()

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // Reads COMFY_API_KEY from the environment.
      // Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      const handle = await comfy.models.submit("kling/kling-v3-omni", {
        aspect_ratio: "16:9",
        duration: "5",
        mode: "pro",
        prompt: "A paper boat drifting down a rain-soaked street at dusk.",
      });
      console.log("requestId:", handle.requestId); // with the model ID, all another process needs

      // Poll until the request completes, waiting the Retry-After the server names.
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // The same result models.run() returns. A request that failed or was cancelled rejects here.
      const result = await handle.get();

      console.log(result.data);
      ```

      ```bash cURL theme={null}
      # 1. Submit. Router answers 201 with request_id, status_url, response_url and cancel_url.
      curl https://api.comfy.org/v2/models/kling/kling-v3-omni/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"aspect_ratio\": \"16:9\", \"duration\": \"5\", \"mode\": \"pro\", \"prompt\": \"A paper boat drifting down a rain-soaked street at dusk.\"}"

      # 2. Poll until status is COMPLETED, waiting the Retry-After seconds each response names.
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/kling/kling-v3-omni/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. Collect. 200 with the model's native output, 202 with the status body while it is still running.
      curl https://api.comfy.org/v2/models/kling/kling-v3-omni/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## 数据结构

### 输入

<ParamField body="aspect_ratio" type="string">
  生成视频画面的宽高比（宽度:高度）。当未使用首帧参考或视频编辑功能时，此参数必填。

  可选值：`16:9`、`9:16`、`1:1`
</ParamField>

<ParamField body="callback_url" type="string (uri)">
  本任务结果的回调通知地址。若配置此项，任务状态发生变化时服务器将主动通知。

  格式：`uri`
</ParamField>

<ParamField body="duration" type="string" default="&#x22;5&#x22;">
  视频时长，单位为秒。使用视频编辑功能时（refer\_type: base），输出时长与输入视频相同，此参数无效。

  可选值：`3`、`4`、`5`、`6`、`7`、`8`、`9`、`10`、`11`、`12`、`13`、`14`、`15`
</ParamField>

<ParamField body="element_list" type="object[]">
  基于元素 ID 配置的参考元素列表。
</ParamField>

<ParamField body="element_list[].element_id" type="integer" required>
  元素 ID

  格式：`int64`
</ParamField>

<ParamField body="external_task_id" type="string">
  自定义任务 ID。在单个用户账号内必须唯一。
</ParamField>

<ParamField body="image_list" type="object[]">
  参考图像列表。可包含元素、场景、风格等参考图像，也可用作首帧或结束帧来生成视频。
</ParamField>

<ParamField body="image_list[].image_url" type="string">
  图像 Base64 编码或图片网址（确保可访问）。支持的格式包括 .jpg/.jpeg/.png。文件大小不能超过 10MB。宽度和高度尺寸不得小于 300px，宽高比在 1:2.5 \~ 2.5:1 之间。
</ParamField>

<ParamField body="image_list[].type" type="string">
  该图像是首帧还是结束帧。first\_frame 为首帧，end\_frame 为结束帧。目前不支持仅使用结束帧。

  可选值：`first_frame`、`end_frame`
</ParamField>

<ParamField body="mode" type="string" default="&#x22;pro&#x22;">
  视频生成模式。std：标准模式，生成 720P 视频，性价比高。pro：专业模式，生成 1080P 视频，视频输出质量更高。

  可选值：`pro`、`std`
</ParamField>

<ParamField body="model_name" type="string">
  模型名。使用 Comfy Router 时可省略或发送 null，模型由请求路径选择。若提供名称，则必须与该路径一致。
</ParamField>

<ParamField body="multi_prompt" type="object[]">
  每个分镜的信息，例如提示词和时长。最多支持 6 个分镜，最少 1 个。当 multi\_shot 为 true 且 shot\_type 为 customize 时必填。
</ParamField>

<ParamField body="multi_prompt[].duration" type="string">
  该分镜的时长，单位为秒。不得超过任务总时长，且不得小于 1。所有分镜时长之和等于任务总时长。
</ParamField>

<ParamField body="multi_prompt[].index" type="integer">
  镜头序号
</ParamField>

<ParamField body="multi_prompt[].prompt" type="string">
  该分镜的提示词。最大长度 512 个字符。
</ParamField>

<ParamField body="multi_shot" type="boolean" default="false">
  是否生成多镜头视频。为 true 时，prompt 参数无效。为 false 时，shot\_type 和 multi\_prompt 参数无效。
</ParamField>

<ParamField body="prompt" type="string">
  文本提示词，可包含正面和负面描述。不得超过 2,500 个字符。可通过 \<\<\<>>> 格式指定元素、图像或视频，例如 \<\<element\_1>>、\<\<\<image\_1>>>、\<\<\<video\_1>>>。
</ParamField>

<ParamField body="shot_type" type="string">
  分镜方式。当 multi\_shot 参数设置为 true 时必填。

  可选值：`customize`、`intelligence`
</ParamField>

<ParamField body="sound" type="string" default="&#x22;off&#x22;">
  生成视频时是否同时生成声音。

  可选值：`on`、`off`
</ParamField>

<ParamField body="video_list" type="object[]">
  参考视频列表。可用作功能参考视频，也可用作待编辑的视频，默认为待编辑的视频。
</ParamField>

<ParamField body="video_list[].keep_original_sound" type="string">
  是否保留视频原始声音。yes 表示保留，no 表示不保留。

  可选值：`yes`、`no`
</ParamField>

<ParamField body="video_list[].refer_type" type="string">
  参考视频类型。feature 为功能参考视频，base 为待编辑的视频。

  可选值：`feature`、`base`
</ParamField>

<ParamField body="video_list[].video_url" type="string" required>
  上传视频的网址。仅支持 .mp4/.mov 格式。时长在 3-10 秒之间。分辨率必须在 720px 到 2160px 之间。支持 24-60 fps 的帧率。只能上传 1 个视频，且大小不超过 200MB。
</ParamField>

<ParamField body="watermark_info" type="object">
  是否同时生成带水印的结果。目前不支持自定义水印。
</ParamField>

<ParamField body="watermark_info.enabled" type="boolean">
  true 表示生成水印，false 表示不生成。
</ParamField>

由 Router 在 `GET /v2/models/kling/kling-v3-omni/openapi.json` 提供的 schema 生成，该文档与请求到达提供商之前用于校验调用的文档相同。

### 输出

<ResponseField name="code" type="integer">
  错误码
</ResponseField>

<ResponseField name="data" type="object" />

<ResponseField name="data.created_at" type="integer">
  任务创建时间，Unix 时间戳（毫秒）
</ResponseField>

<ResponseField name="data.final_unit_deduction" type="string">
  任务的扣费单位数
</ResponseField>

<ResponseField name="data.task_id" type="string">
  任务 ID
</ResponseField>

<ResponseField name="data.task_info" type="object" />

<ResponseField name="data.task_info.external_task_id" type="string" />

<ResponseField name="data.task_result" type="object" />

<ResponseField name="data.task_result.videos" type="object[]" />

<ResponseField name="data.task_result.videos[].duration" type="string">
  视频总时长（秒）
</ResponseField>

<ResponseField name="data.task_result.videos[].id" type="string">
  已生成的视频 ID
</ResponseField>

<ResponseField name="data.task_result.videos[].url" type="string (uri)">
  已生成视频的 URL

  格式：`uri`
</ResponseField>

<ResponseField name="data.task_result.videos[].watermark_url" type="string (uri)">
  已生成的带水印视频 URL，防盗链格式

  格式：`uri`
</ResponseField>

<ResponseField name="data.task_status" type="string">
  任务状态

  可能的值：`submitted`、`processing`、`succeed`、`failed`
</ResponseField>

<ResponseField name="data.task_status_msg" type="string">
  任务状态信息，任务失败时显示失败原因
</ResponseField>

<ResponseField name="data.updated_at" type="integer">
  任务更新时间，Unix 时间戳（毫秒）
</ResponseField>

<ResponseField name="data.watermark_info" type="object" />

<ResponseField name="data.watermark_info.enabled" type="boolean" />

<ResponseField name="message" type="string">
  报错信息
</ResponseField>

<ResponseField name="request_id" type="string">
  请求 ID
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "aspect_ratio": "16:9",
  "duration": "5",
  "mode": "pro",
  "prompt": "A paper boat drifting down a rain-soaked street at dusk."
}
```

### 输出

```json theme={null}
{
  "code": 0,
  "data": {
    "created_at": 1798761600000,
    "task_id": "kling-task-1a2b3c4d5e6f",
    "task_result": {
      "videos": [
        {
          "duration": "5",
          "id": "kling-video-6f5e4d3c2b1a",
          "url": "https://example.invalid/kling/kling-v1/generated.mp4"
        }
      ]
    },
    "task_status": "succeed",
    "task_status_msg": "",
    "updated_at": 1798761840000
  },
  "message": "SUCCEED",
  "request_id": "9f2c1a04-7b6e-4d38-8a51-3c0e7d9b2f46"
}
```

## 发布前须知

SDK 会生成 `Idempotency-Key` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

请求失败时，Router 会发送 `X-Comfy-Error-Type` 响应头说明原因。`422` 表示 Router 在调用提供商之前就拒绝了输入。生成的资源请及时下载，因为[结果链接会过期](/zh/development/comfy-router/reference#结果资产)。

<CardGroup cols={3}>
  <Card title="请求头" icon="list" href="/zh/development/comfy-router/quickstart">
    身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
  </Card>

  <Card title="使用 Router API" icon="code" href="/zh/development/comfy-router/quickstart">
    模型发现、校验错误、重试与计费。
  </Card>

  <Card title="限制" icon="triangle-exclamation" href="/zh/development/comfy-router/limitations">
    Router 目前不支持的功能，以及替代方案。
  </Card>
</CardGroup>
