> ## 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 Image O1 を使用する

> Comfy Router を通じて kling/kling-image-o1 を呼び出します: エンドポイント、リクエスト形状、Router が返すレスポンスについて説明します。

Comfy Router が Kling から提供する `kling/kling-image-o1` の API Reference です。

## クイックスタート

[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 で行うものです。

**Model ID:** `kling/kling-image-o1`

**Endpoint:** `POST https://api.comfy.org/v2/models/kling/kling-image-o1`

<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-image-o1",
              {
                  "aspect_ratio": "1:1",
                  "n": 1,
                  "prompt": "A watercolour koi pond at dawn, soft light.",
                  "resolution": "1k",
              },
          )

      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-image-o1", {
        aspect_ratio: "1:1",
        n: 1,
        prompt: "A watercolour koi pond at dawn, soft light.",
        resolution: "1k",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/kling/kling-image-o1 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"aspect_ratio\": \"1:1\", \"n\": 1, \"prompt\": \"A watercolour koi pond at dawn, soft light.\", \"resolution\": \"1k\"}"
      ```
    </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-image-o1",
              {
                  "aspect_ratio": "1:1",
                  "n": 1,
                  "prompt": "A watercolour koi pond at dawn, soft light.",
                  "resolution": "1k",
              },
          )
          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-image-o1", {
        aspect_ratio: "1:1",
        n: 1,
        prompt: "A watercolour koi pond at dawn, soft light.",
        resolution: "1k",
      });
      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-image-o1/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"aspect_ratio\": \"1:1\", \"n\": 1, \"prompt\": \"A watercolour koi pond at dawn, soft light.\", \"resolution\": \"1k\"}"

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

## スキーマ

### 入力

<ParamField body="aspect_ratio" type="string" default="&#x22;auto&#x22;">
  生成画像のアスペクト比 (幅:高さ)。auto は、入力コンテンツに基づいて画像をインテリジェントに生成します。

  指定可能な値: `16:9`, `9:16`, `1:1`, `4:3`, `3:4`, `3:2`, `2:3`, `21:9`, `auto`
</ParamField>

<ParamField body="callback_url" type="string (uri)">
  このタスクの結果を受け取るコールバック通知先アドレス。設定すると、タスクステータスが変化したときにサーバーから能動的に通知されます。

  形式: `uri`
</ParamField>

<ParamField body="element_list" type="object[]">
  要素 ID の設定に基づく参照要素リスト。参照要素と参照画像の合計は 10 を超えてはなりません。
</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_list" type="object[]">
  参照画像リスト。画像の Base64 エンコーディングまたは画像 URL (アクセス可能であること) を入力できます。対応形式は .jpg/.jpeg/.png です。ファイルサイズは 10MB を超えることはできません。幅と高さは 300px 以上、アスペクト比は 1:2.5 \~ 2.5:1 の範囲である必要があります。参照要素と参照画像の合計は 10 を超えてはなりません。
</ParamField>

<ParamField body="image_list[].image" type="string" required>
  画像の Base64 エンコーディングまたは画像 URL (アクセス可能であること)
</ParamField>

<ParamField body="model_name" type="string">
  モデル名。Comfy Router を使用する場合は省略するか null を送信します。モデルはリクエストパスによって選択されます。名前を指定する場合は、そのパスと一致している必要があります。
</ParamField>

<ParamField body="n" type="integer" default="1">
  生成する画像の数。値の範囲 \[1,9]。

  範囲: `1` から `9`
</ParamField>

<ParamField body="prompt" type="string" required>
  テキストプロンプト。ポジティブおよびネガティブの記述を含めることができます。2,500 文字を超えてはなりません。Omni モデルは、要素と画像を含むプロンプトを通じてさまざまな機能を実現できます。画像は \<\<\<>>> の形式で指定します。例: \<\<\<image\_1>>>。
</ParamField>

<ParamField body="resolution" type="string" default="&#x22;1k&#x22;">
  画像生成の解像度。1k は 1K スタンダード、2k は 2K 高解像度、4k は 4K 高解像度です。

  指定可能な値: `1k`, `2k`, `4k`
</ParamField>

<ParamField body="result_type" type="string" default="&#x22;single&#x22;">
  単一の画像を生成するか、一連の画像を生成するかを制御します。

  指定可能な値: `single`, `series`
</ParamField>

<ParamField body="series_amount" type="integer" default="4">
  シリーズ内の画像数。値の範囲 \[2,9]。

  範囲: `2` から `9`
</ParamField>

Router が `GET /v2/models/kling/kling-image-o1/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">
  顧客定義のタスク ID
</ResponseField>

<ResponseField name="data.task_result" type="object" />

<ResponseField name="data.task_result.images" type="object[]" />

<ResponseField name="data.task_result.images[].index" type="integer">
  画像番号 (0-9)
</ResponseField>

<ResponseField name="data.task_result.images[].url" type="string (uri)">
  生成画像の URL

  形式: `uri`
</ResponseField>

<ResponseField name="data.task_result.result_type" type="string">
  結果が単一の画像か一連の画像か

  指定可能な値: `single`, `series`
</ResponseField>

<ResponseField name="data.task_result.series_images" type="object[]">
  シリーズ画像の結果リスト
</ResponseField>

<ResponseField name="data.task_result.series_images[].index" type="integer">
  シリーズ画像のシーケンス番号
</ResponseField>

<ResponseField name="data.task_result.series_images[].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="message" type="string">
  エラーメッセージ
</ResponseField>

<ResponseField name="request_id" type="string">
  リクエスト ID
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "aspect_ratio": "1:1",
  "n": 1,
  "prompt": "A watercolour koi pond at dawn, soft light.",
  "resolution": "1k"
}
```

### 出力

```json theme={null}
{
  "code": 0,
  "data": {
    "created_at": 1798761600000,
    "task_id": "kling-image-task-3c4d5e6f7a8b",
    "task_result": {
      "images": [
        {
          "index": 0,
          "url": "https://example.invalid/kling/kling-image-o1/generated.png"
        }
      ],
      "result_type": "single"
    },
    "task_status": "succeed",
    "task_status_msg": "",
    "updated_at": 1798761660000
  },
  "message": "SUCCEED",
  "request_id": "6a4b2c80-1e93-4d57-b8f2-05c7e9a3d146"
}
```

## 出荷前の確認

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>
