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

# 将 Kling V1.6 与 Comfy Router 配合使用

> 通过 Comfy Router 调用 kling/kling-v1-6：endpoint、请求结构以及 Router 返回的响应。

`kling/kling-v1-6` 的 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-v1-6`

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

<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-v1-6",
              {
                  "aspect_ratio": "16:9",
                  "duration": "5",
                  "mode": "std",
                  "prompt": "A red fox trotting through falling snow, cinematic lighting.",
              },
          )

      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-v1-6", {
        aspect_ratio: "16:9",
        duration: "5",
        mode: "std",
        prompt: "A red fox trotting through falling snow, cinematic lighting.",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/kling/kling-v1-6 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"aspect_ratio\": \"16:9\", \"duration\": \"5\", \"mode\": \"std\", \"prompt\": \"A red fox trotting through falling snow, cinematic lighting.\"}"
      ```
    </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-v1-6",
              {
                  "aspect_ratio": "16:9",
                  "duration": "5",
                  "mode": "std",
                  "prompt": "A red fox trotting through falling snow, cinematic lighting.",
              },
          )
          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-v1-6", {
        aspect_ratio: "16:9",
        duration: "5",
        mode: "std",
        prompt: "A red fox trotting through falling snow, cinematic lighting.",
      });
      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-v1-6/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\": \"std\", \"prompt\": \"A red fox trotting through falling snow, cinematic lighting.\"}"

      # 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-v1-6/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-v1-6/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## 数据结构

### 输入

<ParamField body="aspect_ratio" type="string" default="&#x22;16:9&#x22;">
  视频宽高比

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

<ParamField body="callback_url" type="string (uri)">
  回调通知地址

  格式：`uri`
</ParamField>

<ParamField body="camera_control" type="object" />

<ParamField body="camera_control.config" type="object" />

<ParamField body="camera_control.config.horizontal" type="number">
  控制相机沿水平轴（x 轴）的移动。负值表示向左，正值表示向右。

  范围：`-10` 到 `10`
</ParamField>

<ParamField body="camera_control.config.pan" type="number">
  控制相机在竖直平面内的旋转（x 轴）。负值表示向下旋转，正值表示向上旋转。

  范围：`-10` 到 `10`
</ParamField>

<ParamField body="camera_control.config.roll" type="number">
  控制相机的翻滚幅度（z 轴）。负值表示逆时针，正值表示顺时针。

  范围：`-10` 到 `10`
</ParamField>

<ParamField body="camera_control.config.tilt" type="number">
  控制相机在水平平面内的旋转（y 轴）。负值表示向左旋转，正值表示向右旋转。

  范围：`-10` 到 `10`
</ParamField>

<ParamField body="camera_control.config.vertical" type="number">
  控制相机沿竖直轴（y 轴）的移动。负值表示向下，正值表示向上。

  范围：`-10` 到 `10`
</ParamField>

<ParamField body="camera_control.config.zoom" type="number">
  控制相机焦距的变化。负值表示视野变窄，正值表示视野变宽。

  范围：`-10` 到 `10`
</ParamField>

<ParamField body="camera_control.type" type="string">
  预设的相机运动类型。simple：可自定义的相机运动。down\_back：相机下降并向后移动。forward\_up：相机向前移动并向上倾斜。right\_turn\_forward：向右旋转并向前移动。left\_turn\_forward：向左旋转并向前移动。

  可选值：`simple`、`down_back`、`forward_up`、`right_turn_forward`、`left_turn_forward`
</ParamField>

<ParamField body="cfg_scale" type="number" default="0.5">
  视频生成时的灵活度。值越高，模型的灵活度越低，与用户提示词的相关性越强。

  范围：`0` 到 `1`

  格式：`float`
</ParamField>

<ParamField body="duration" type="string" default="&#x22;5&#x22;">
  视频时长，单位为秒

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

<ParamField body="external_task_id" type="string">
  自定义任务 ID
</ParamField>

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

  可选值：`std`、`pro`
</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="negative_prompt" type="string">
  负面文本提示词。建议直接在正面提示词中用否定语句补充负面提示信息。
</ParamField>

<ParamField body="prompt" type="string">
  正面文本提示词。使用 \<\<\<voice\_1>>> 指定与 voice\_list 参数顺序相匹配的声音。一个任务最多可引用 2 种音色。指定音色时，sound 参数的值必须为 on。
</ParamField>

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

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

<ParamField body="sound" type="string" default="&#x22;off&#x22;">
  生成视频时是否同时生成声音。仅 V2.6 及后续版本的模型支持该参数。

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

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

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

生成本页内容依据的是 Router 在 `GET /v2/models/kling/kling-v1-6/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

  Format: `uri`
</ResponseField>

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

  Format: `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": "std",
  "prompt": "A red fox trotting through falling snow, cinematic lighting."
}
```

### 输出

```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>
