> ## 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 V2.1 を使用する

> Comfy Router 経由で kling/kling-v2-1 を呼び出します。エンドポイント、リクエスト形状、Router が返すレスポンスについて説明します。

`kling/kling-v2-1` の 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-v2-1`

**エンドポイント:** `POST https://api.comfy.org/v2/models/kling/kling-v2-1`

<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-v2-1",
              {
                  "duration": "5",
                  "image": "https://example.invalid/kling/reference.png",
                  "mode": "std",
                  "prompt": "The fox turns its head towards the camera.",
              },
          )

      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-v2-1", {
        duration: "5",
        image: "https://example.invalid/kling/reference.png",
        mode: "std",
        prompt: "The fox turns its head towards the camera.",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/kling/kling-v2-1 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"duration\": \"5\", \"image\": \"https://example.invalid/kling/reference.png\", \"mode\": \"std\", \"prompt\": \"The fox turns its head towards the camera.\"}"
      ```
    </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-v2-1",
              {
                  "duration": "5",
                  "image": "https://example.invalid/kling/reference.png",
                  "mode": "std",
                  "prompt": "The fox turns its head towards the camera.",
              },
          )
          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-v2-1", {
        duration: "5",
        image: "https://example.invalid/kling/reference.png",
        mode: "std",
        prompt: "The fox turns its head towards the camera.",
      });
      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-v2-1/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"duration\": \"5\", \"image\": \"https://example.invalid/kling/reference.png\", \"mode\": \"std\", \"prompt\": \"The fox turns its head towards the camera.\"}"

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

## スキーマ

### 入力

<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="dynamic_masks" type="object[]">
  動的ブラシ設定リスト（最大6グループ）。5秒のビデオの場合、軌跡の長さは77座標を超えてはなりません。
</ParamField>

<ParamField body="dynamic_masks[].mask" type="string (uri)">
  動的ブラシの適用領域（ユーザーがモーションブラシを使用して作成したマスク画像）。アスペクト比は入力画像と一致している必要があります。

  形式: `uri`
</ParamField>

<ParamField body="dynamic_masks[].trajectories" type="object[]" />

<ParamField body="dynamic_masks[].trajectories[].x" type="integer">
  軌跡ポイントの水平座標。画像の左下隅を原点（0,0）とします。
</ParamField>

<ParamField body="dynamic_masks[].trajectories[].y" type="integer">
  軌跡ポイントの垂直座標。画像の左下隅を原点（0,0）とします。
</ParamField>

<ParamField body="element_list" type="object[]">
  エレメントID設定に基づく参照エレメントリスト。最大3つの参照エレメントをサポートします。element\_list パラメータと voice\_list パラメータは同時に使用できません。
</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" type="string">
  参照画像: URL または Base64 エンコード文字列。10MB を超えることはできず、解像度は 300\*300px 以上、アスペクト比は 1:2.5 ～ 2.5:1 の範囲である必要があります。Base64 には data:image プレフィックスを含めないでください。
</ParamField>

<ParamField body="image_tail" type="string">
  参照画像: 終了フレーム制御。URL または Base64 エンコード文字列。10MB を超えることはできず、解像度は 300\*300px 以上である必要があります。Base64 には data:image プレフィックスを含めないでください。dynamic\_masks/static\_mask または camera\_control と同時に使用することはできません。
</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">
  Negative text prompt. It is recommended to supplement negative prompt information through negative sentences directly within positive prompts.
</ParamField>

<ParamField body="prompt" type="string">
  ポジティブテキストプロンプト。\<voice\_1>> を使用して、voice\_list パラメータの順序に対応する音声を指定します。1つのタスクで最大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="static_mask" type="string">
  静的ブラシ適用領域（ユーザーがモーションブラシを使用して作成するマスク画像）。アスペクト比は入力画像と一致する必要があります。
</ParamField>

<ParamField body="voice_list" type="object[]">
  動画生成時に参照する音声のリスト。最大2つの音声をサポートします。element\_list パラメータと voice\_list パラメータは相互に排他的です。
</ParamField>

<ParamField body="voice_list[].voice_id" type="string" required>
  音声カスタマイズ API を通じて返される音声 ID、またはシステムプリセットの音声 ID。
</ParamField>

<ParamField body="watermark_info" type="object">
  ウォーターマーク付きの結果を同時に生成するかどうか。現時点ではカスタムウォーターマークはサポートされていません。
</ParamField>

<ParamField body="watermark_info.enabled" type="boolean">
  true はウォーターマークを生成する、false は生成しないことを意味します。
</ParamField>

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

### 出力

<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}
{
  "duration": "5",
  "image": "https://example.invalid/kling/reference.png",
  "mode": "std",
  "prompt": "The fox turns its head towards the camera."
}
```

### 出力

```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` を生成し、自動リトライで再利用します。手動リトライでは元のキーを再利用してください。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>
