> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-chore-sync-comfy-api-v2-spec.mintlify.site/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 を呼び出します: エンドポイント、リクエスト形状、Router が返すレスポンスについて説明します。

`kling/kling-3.0-turbo` の API リファレンス。Kling から Comfy Router が提供します。

## クイックスタート

[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 を上書きすることはありませんが、クエリに使用できます。1 つのユーザーアカウント内で一意である必要があります。
</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">
  生成されるフレームのアスペクト比（幅:高さ）。"16:9"、"9:16"、"1:1" のいずれか。デフォルトは "16:9"。

  指定可能な値: `16:9`, `9:16`, `1:1`
</ParamField>

<ParamField body="settings.duration" type="integer">
  ビデオの長さ（秒）。対応する値は 3 から 15 です。デフォルトは 5。

  範囲: `3` から `15`
</ParamField>

<ParamField body="settings.resolution" type="string">
  生成されるビデオの鮮明さ。"720p" または "1080p" のいずれか。デフォルトは "720p"。

  指定可能な値: `720p`, `1080p`
</ParamField>

スキーマから生成されており、Router が `GET /v2/models/kling/kling-3.0-turbo/openapi.json` で提供するドキュメント、つまりリクエストがプロバイダーに到達する前に呼び出しを検証するのと同じドキュメントです。

### 出力

<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">
  消費量。小数点以下 2 桁まで正確です。
</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 タイムスタンプ。

  フォーマット: `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 タイムスタンプ。

  フォーマット: `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` を生成し、自動リトライで再利用します。手動リトライでは元のキーを再利用してください。Router は最大 10 分間接続を保持できます。

リクエストが失敗すると、Router は理由を示す `X-Comfy-Error-Type` レスポンスヘッダーを送信します。`422` は、プロバイダーを呼び出す前に Router が入力を拒否したことを意味します。生成されたアセットは [結果 URL の有効期限](/ja/development/comfy-router/reference#結果アセット) があるため、早めにダウンロードしてください。

<CardGroup cols={3}>
  <Card title="ヘッダー" icon="list" href="/ja/development/comfy-router/quickstart">
    認証、冪等性、リクエスト ID、エラー分類、リトライ間隔、支出上限。
  </Card>

  <Card title="Router API の利用" icon="code" href="/ja/development/comfy-router/quickstart">
    モデルの検出、バリデーションエラー、リトライ、課金。
  </Card>

  <Card title="制限事項" icon="triangle-exclamation" href="/ja/development/comfy-router/limitations">
    Router が現在対応していないことと、代替手段。
  </Card>
</CardGroup>
