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

# Kling V2 Master を Comfy Router で使用する

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

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

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

<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-master",
              {
                  "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-v2-master", {
        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-v2-master \
        -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-v2-master",
              {
                  "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-v2-master", {
        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-v2-master/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-v2-master/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-master/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\_list パラメータの順序に対応する音声を指定するには \<\<\<voice\_1>>> を使用します。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="watermark_info" type="object">
  透かし入りの結果を同時に生成するかどうか。現時点ではカスタム透かしはサポートされていません。
</ParamField>

<ParamField body="watermark_info.enabled" type="boolean">
  true の場合は透かしを生成し、false の場合は生成しません。
</ParamField>

Router が `GET /v2/models/kling/kling-v2-master/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}
{
  "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` を生成し、自動リトライで再利用します。手動リトライでは元のキーを再利用してください。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>
