> ## 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 3.0 Turbo

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

`kling/kling-3.0-turbo` 的 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-3.0-turbo`

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

<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-3.0-turbo",
              {
                  "prompt": "A neon-lit alley in the rain, slow dolly forward.",
                  "settings": {
                      "aspect_ratio": "16:9",
                      "duration": 5,
                      "resolution": "1080p",
                  },
              },
          )

      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-3.0-turbo", {
        prompt: "A neon-lit alley in the rain, slow dolly forward.",
        settings: {
          aspect_ratio: "16:9",
          duration: 5,
          resolution: "1080p",
        },
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/kling/kling-3.0-turbo \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt\": \"A neon-lit alley in the rain, slow dolly forward.\", \"settings\": {\"aspect_ratio\":\"16:9\",\"duration\":5,\"resolution\":\"1080p\"}}"
      ```
    </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-3.0-turbo",
              {
                  "prompt": "A neon-lit alley in the rain, slow dolly forward.",
                  "settings": {
                      "aspect_ratio": "16:9",
                      "duration": 5,
                      "resolution": "1080p",
                  },
              },
          )
          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-3.0-turbo", {
        prompt: "A neon-lit alley in the rain, slow dolly forward.",
        settings: {
          aspect_ratio: "16:9",
          duration: 5,
          resolution: "1080p",
        },
      });
      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-3.0-turbo/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt\": \"A neon-lit alley in the rain, slow dolly forward.\", \"settings\": {\"aspect_ratio\":\"16:9\",\"duration\":5,\"resolution\":\"1080p\"}}"

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

## 结构

### 输入

<ParamField body="options" type="object">
  常规配置，例如回调地址和水印选项。
</ParamField>

<ParamField body="options.callback_url" type="string">
  任务结果回调通知 URL。当任务状态发生变化时，服务器会发送通知。
</ParamField>

<ParamField body="options.external_task_id" type="string">
  自定义任务 ID。不会覆盖系统生成的任务 ID，但可用于查询。在单个用户账号内必须唯一。
</ParamField>

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

<ParamField body="options.watermark_info.enabled" type="boolean">
  true 表示生成带水印的结果，false 表示不生成。默认 false。
</ParamField>

<ParamField body="prompt" type="string" required>
  提示词，可同时包含正面和负面描述。推荐长度不超过 2500 个字符。多镜头视频使用格式 "shot n, m, words; shot n, m, words;"。
</ParamField>

<ParamField body="settings" type="object">
  输出配置，例如分辨率、宽高比和时长。
</ParamField>

<ParamField body="settings.aspect_ratio" type="string">
  已生成画面的宽高比（width:height）。取值为 "16:9"、"9:16" 或 "1:1" 之一。默认 "16:9"。

  Possible values: `16:9`, `9:16`, `1:1`
</ParamField>

<ParamField body="settings.duration" type="integer">
  视频长度，以秒为单位。支持的取值为 3 到 15。默认 5。

  Range: `3` to `15`
</ParamField>

<ParamField body="settings.resolution" type="string">
  已生成视频的清晰度。取值为 "720p" 或 "1080p" 之一。默认 "720p"。

  Possible values: `720p`, `1080p`
</ParamField>

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

### 输出

<ResponseField name="code" type="integer">
  错误码。0 表示成功。
</ResponseField>

<ResponseField name="data" type="object[]">
  匹配该查询的任务。
</ResponseField>

<ResponseField name="data[].billing" type="object[]">
  任务的计费详情。
</ResponseField>

<ResponseField name="data[].billing[].amount" type="string">
  消耗金额，精确到小数点后两位。
</ResponseField>

<ResponseField name="data[].billing[].charge_type" type="string">
  消耗账户类型。"cash" 表示余额，"unit" 表示资源包。
</ResponseField>

<ResponseField name="data[].billing[].package_type" type="string">
  可消耗资源包类型（仅在 charge\_type 为 "unit" 时存在）。取值为 "video"、"image" 或 "audio" 之一。
</ResponseField>

<ResponseField name="data[].create_time" type="integer">
  任务创建时间。Unix 时间戳，以毫秒为单位。

  Format: `int64`
</ResponseField>

<ResponseField name="data[].external_id" type="string">
  此任务的自定义任务 ID（如果有）。
</ResponseField>

<ResponseField name="data[].id" type="string">
  任务 ID。
</ResponseField>

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

<ResponseField name="data[].outputs" type="object[]">
  任务已生成的输出。
</ResponseField>

<ResponseField name="data[].outputs[].duration" type="string">
  已生成视频的时长，以秒为单位。
</ResponseField>

<ResponseField name="data[].outputs[].group_id" type="string">
  分组标记，仅对已分组的图像存在。
</ResponseField>

<ResponseField name="data[].outputs[].id" type="string">
  由系统生成的输出 ID。
</ResponseField>

<ResponseField name="data[].outputs[].mp3_duration" type="string">
  已生成 MP3 音频的时长，以秒为单位。
</ResponseField>

<ResponseField name="data[].outputs[].mp3_url" type="string">
  已生成音频的 MP3 URL（防盗链保护）。
</ResponseField>

<ResponseField name="data[].outputs[].name" type="string">
  已生成素材的名称。
</ResponseField>

<ResponseField name="data[].outputs[].owned_by" type="string">
  素材来源。"kling" 表示官方库；数字为创作者 ID。
</ResponseField>

<ResponseField name="data[].outputs[].status" type="string">
  素材状态。取值为 "succeeded" 或 "deleted" 之一。
</ResponseField>

<ResponseField name="data[].outputs[].type" type="string">
  输出内容类型。取值为 "video"、"image"、"audio"、"voice" 或 "element" 之一。
</ResponseField>

<ResponseField name="data[].outputs[].url" type="string">
  已生成结果的 URL（防盗链保护）。30 天后清除。
</ResponseField>

<ResponseField name="data[].outputs[].watermark_url" type="string">
  带水印结果的 URL（防盗链保护）。
</ResponseField>

<ResponseField name="data[].outputs[].wav_duration" type="string">
  已生成 WAV 音频的时长，以秒为单位。
</ResponseField>

<ResponseField name="data[].outputs[].wav_url" type="string">
  已生成音频的 WAV URL（防盗链保护）。
</ResponseField>

<ResponseField name="data[].status" type="string">
  任务状态。取值为 "submitted"、"processing"、"succeeded" 或 "failed" 之一。
</ResponseField>

<ResponseField name="data[].update_time" type="integer">
  任务更新时间。Unix 时间戳，以毫秒为单位。

  Format: `int64`
</ResponseField>

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

<ResponseField name="request_id" type="string">
  由系统生成的请求 ID。
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "prompt": "A neon-lit alley in the rain, slow dolly forward.",
  "settings": {
    "aspect_ratio": "16:9",
    "duration": 5,
    "resolution": "1080p"
  }
}
```

### 输出

```json theme={null}
{
  "code": 0,
  "data": [
    {
      "create_time": 1798761600000,
      "id": "kling-v2-task-7c8d9e0f1a2b",
      "message": "",
      "outputs": [
        {
          "duration": "5",
          "id": "kling-v2-output-2b1a0f9e8d7c",
          "type": "video",
          "url": "https://example.invalid/kling/kling-3.0-turbo/generated.mp4"
        }
      ],
      "status": "succeeded",
      "update_time": 1798761820000
    }
  ],
  "message": "SUCCEED",
  "request_id": "3d7e5c91-0b42-4f68-9a13-8e2c6d4b0a75"
}
```

## 发布前须知

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>
