> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-chore-mintlify-theme-mint.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Comfy Router で Wan 2.5 I2I Preview を使用する

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

`wan/wan2.5-i2i-preview` の API リファレンス。Wan の Comfy Router から提供されます。

## クイックスタート

[お使いの Comfy ワークスペース](https://platform.comfy.org/profile/api-keys?onboarding=router)でキーを作成し、`COMFY_API_KEY` としてエクスポートします。Python、TypeScript、Swift のスニペットは Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`、および [`ComfySwiftSDK`](https://github.com/Comfy-Org/comfy-swift-sdk) Swift パッケージ）を使用します。cURL のスニペットは、生の HTTP で同じ呼び出しを行います。

**モデル ID:** `wan/wan2.5-i2i-preview`

**エンドポイント:** `POST https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview`

<Tabs>
  <Tab title="結果を待つ">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # 環境変数 COMFY_API_KEY を読み取ります。
      # SDK は冪等性キーを自動的に作成し、自動リトライのために再利用します。
      with Comfy() as client:
          result = client.models.run(
              "wan/wan2.5-i2i-preview",
              {
                  "input": {
                      "images": ["https://example.invalid/red-maple-leaf.png"],
                      "prompt": "Make the leaf golden.",
                  },
                  "parameters": {
                      "n": 1,
                      "size": "768*768",
                  },
              },
          )

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // 環境変数 COMFY_API_KEY を読み取ります。
      // SDK は冪等性キーを自動的に作成し、自動リトライのために再利用します。
      const { data } = await comfy.models.run("wan/wan2.5-i2i-preview", {
        input: {
          images: ["https://example.invalid/red-maple-leaf.png"],
          prompt: "Make the leaf golden.",
        },
        parameters: {
          n: 1,
          size: "768*768",
        },
      });

      console.log(data);
      ```

      ```swift Swift theme={null}
      import Foundation
      import ComfySwiftSDK

      // 環境変数 COMFY_API_KEY を読み取ります。
      // SDK は呼び出しごとに冪等性キーを生成し、自動リトライのために再利用します。
      let client = ComfyCloudClient(apiKey: ProcessInfo.processInfo.environment["COMFY_API_KEY"]!)
      let result = try await client.models.run(
          "wan/wan2.5-i2i-preview",
          input: [
              "input": [
                  "images": ["https://example.invalid/red-maple-leaf.png"],
                  "prompt": "Make the leaf golden.",
              ],
              "parameters": [
                  "n": 1,
                  "size": "768*768",
              ],
          ]
      )

      print(result.output)
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"images\":[\"https://example.invalid/red-maple-leaf.png\"],\"prompt\":\"Make the leaf golden.\"}, \"parameters\": {\"n\":1,\"size\":\"768*768\"}}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="キューに送信して後で取得">
    同じボディを `POST https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview/requests` に送信します。Router は実行が受け付けられ次第 `201` と `request_id` を返し、結果は準備が整った時点で、このプロセスからでも別のプロセスからでも取得できます。ステータス、キャンセル、結果の取得の詳細は [キュー配信](/ja/development/comfy-router/queue) を参照してください。

    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # 環境変数から COMFY_API_KEY を読み取ります。
      # 各 submit() 呼び出しは独自の Idempotency-Key を発行し、自動リトライで再利用します。
      with Comfy() as client:
          handle = client.models.submit(
              "wan/wan2.5-i2i-preview",
              {
                  "input": {
                      "images": ["https://example.invalid/red-maple-leaf.png"],
                      "prompt": "Make the leaf golden.",
                  },
                  "parameters": {
                      "n": 1,
                      "size": "768*768",
                  },
              },
          )
          print("request_id:", handle.request_id)  # モデル ID とともに、別のプロセスが必要とするすべて

          # リクエストが完了するまでポーリングし、サーバーが指定する Retry-After だけ待機します。
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # プロバイダー自身のペイロードで、models.run() が返す値と同じです。
          # 失敗またはキャンセルされたリクエストは、ここで型付き Router エラーを発生させます。
          result = handle.get()

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // 環境変数から COMFY_API_KEY を読み取ります。
      // 各 submit() 呼び出しは独自の Idempotency-Key を発行し、自動リトライで再利用します。
      const handle = await comfy.models.submit("wan/wan2.5-i2i-preview", {
        input: {
          images: ["https://example.invalid/red-maple-leaf.png"],
          prompt: "Make the leaf golden.",
        },
        parameters: {
          n: 1,
          size: "768*768",
        },
      });
      console.log("requestId:", handle.requestId); // モデル ID とともに、別のプロセスが必要とするすべて

      // リクエストが完了するまでポーリングし、サーバーが指定する Retry-After だけ待機します。
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // models.run() が返すのと同じ結果です。失敗またはキャンセルされたリクエストは、ここで reject されます。
      const result = await handle.get();

      console.log(result.data);
      ```

      ```swift Swift theme={null}
      import Foundation
      import ComfySwiftSDK

      // 環境変数から COMFY_API_KEY を読み取ります。
      // 各 submit() 呼び出しは独自の Idempotency-Key を発行し、自動リトライで再利用します。
      let client = ComfyCloudClient(apiKey: ProcessInfo.processInfo.environment["COMFY_API_KEY"]!)
      let handle = try await client.models.submit(
          "wan/wan2.5-i2i-preview",
          input: [
              "input": [
                  "images": ["https://example.invalid/red-maple-leaf.png"],
                  "prompt": "Make the leaf golden.",
              ],
              "parameters": [
                  "n": 1,
                  "size": "768*768",
              ],
          ]
      )
      print("requestId:", handle.requestId)  // モデル ID とともに、別のプロセスが必要とするすべて

      // リクエストが完了するまでポーリングし、サーバーが指定する Retry-After だけ待機します。
      for try await update in handle.events() {
          print(update.state.rawValue, update.queuePosition.map(String.init) ?? "unknown")
      }

      // プロバイダー自身のペイロードで、models.run() が返す値と同じです。
      // 失敗またはキャンセルされたリクエストは、ここで型付き Router エラーをスローします。
      let result = try await handle.result()

      print(result.output)
      ```

      ```bash cURL theme={null}
      # 1. 送信。Router は request_id、status_url、response_url、cancel_url とともに 201 を返します。
      curl https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"images\":[\"https://example.invalid/red-maple-leaf.png\"],\"prompt\":\"Make the leaf golden.\"}, \"parameters\": {\"n\":1,\"size\":\"768*768\"}}"

      # 2. status が COMPLETED になるまでポーリングし、各レスポンスが指定する Retry-After 秒だけ待機します。
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. 取得。完了時はモデルのネイティブ出力とともに 200 を、まだ実行中はステータスボディとともに 202 を返します。
      curl https://api.comfy.org/v2/models/wan/wan2.5-i2i-preview/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## スキーマ

### 入力

<ParamField body="input" type="object" required>
  プロンプト、画像などの基本情報を入力します。
</ParamField>

<ParamField body="input.images" type="string[]" required>
  画像から画像への生成に使用する画像 URL の配列
</ParamField>

<ParamField body="input.negative_prompt" type="string">
  画像に表示したくないコンテンツを記述するネガティブプロンプト
</ParamField>

<ParamField body="input.prompt" type="string" required>
  期待する画像の要素や視覚的特徴を記述するポジティブプロンプト。中国語と英語をサポートし、長さは 2000 文字以内です
</ParamField>

<ParamField body="model" type="string">
  画像から画像への生成に呼び出すモデルの ID。このコンポーネントでは制約されません。Comfy Router が `POST /v2/models/wan/{model}` の `{model}` パスセグメントから設定します。`POST /proxy/wan/api/v1/services/aigc/image2image/image-synthesis` への直接の v1 呼び出しではこれを必ず指定する必要があり、受け入れられる表記の enum はそのオペレーション自身のコンポーネント `WanImage2ImageGenerationRequest` にあります。
</ParamField>

<ParamField body="parameters" type="object">
  画像処理パラメータ
</ParamField>

<ParamField body="parameters.n" type="integer" default="4">
  生成する画像の数。範囲は 1～4、デフォルトは 4

  範囲: `1` ～ `4`
</ParamField>

<ParamField body="parameters.seed" type="integer">
  ランダム性を制御する乱数シード。範囲 \[0, 2147483647]

  範囲: `0` ～ `2147483647`
</ParamField>

<ParamField body="parameters.size" type="string" default="&#x22;1280*1280&#x22;">
  幅*高さ形式の出力画像の解像度。デフォルトは 1280*1280 です。API は 589824 (768*768) から 1638400 (1280*1280) までのピクセル面積を、1:4 から 4:1 までのアスペクト比で受け付けます
</ParamField>

<ParamField body="parameters.watermark" type="boolean" default="false">
  右下隅に透かしロゴを追加するかどうか
</ParamField>

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

### 出力

<ResponseField name="output" type="object" required />

<ResponseField name="output.actual_prompt" type="string">
  インテリジェントな書き換え後の実際のプロンプト（ビデオタスク用）
</ResponseField>

<ResponseField name="output.check_audio" type="string">
  オーディオ生成を伴う I2V タスク用のオーディオ URL
</ResponseField>

<ResponseField name="output.code" type="string">
  失敗したリクエストのエラーコード（リクエストが成功した場合は返されません）
</ResponseField>

<ResponseField name="output.end_time" type="string">
  タスク完了時間
</ResponseField>

<ResponseField name="output.message" type="string">
  失敗したリクエストの詳細情報（リクエストが成功した場合は返されません）
</ResponseField>

<ResponseField name="output.orig_prompt" type="string">
  オリジナルの入力プロンプト（ビデオタスク用）
</ResponseField>

<ResponseField name="output.results" type="object[]">
  画像生成タスクのタスク結果のリスト
</ResponseField>

<ResponseField name="output.results[].actual_prompt" type="string">
  インテリジェントな書き換え後の実際のプロンプト（有効な場合）
</ResponseField>

<ResponseField name="output.results[].code" type="string">
  画像エラーコード（一部のタスクが失敗した場合に返されます）
</ResponseField>

<ResponseField name="output.results[].message" type="string">
  画像エラー情報（一部のタスクが失敗した場合に返されます）
</ResponseField>

<ResponseField name="output.results[].orig_prompt" type="string">
  オリジナルの入力プロンプト
</ResponseField>

<ResponseField name="output.results[].url" type="string">
  生成された画像の URL アドレス
</ResponseField>

<ResponseField name="output.scheduled_time" type="string">
  タスクの実行時間
</ResponseField>

<ResponseField name="output.submit_time" type="string">
  タスクの送信時間
</ResponseField>

<ResponseField name="output.task_id" type="string" required>
  タスク ID
</ResponseField>

<ResponseField name="output.task_metrics" type="object">
  画像生成タスクのタスク結果統計
</ResponseField>

<ResponseField name="output.task_metrics.FAILED" type="integer">
  失敗したタスクの数
</ResponseField>

<ResponseField name="output.task_metrics.SUCCEEDED" type="integer">
  成功したタスクの数
</ResponseField>

<ResponseField name="output.task_metrics.TOTAL" type="integer">
  タスクの合計数
</ResponseField>

<ResponseField name="output.task_status" type="string" required>
  タスクステータス

  取り得る値: `PENDING`、`RUNNING`、`SUCCEEDED`、`FAILED`、`CANCELED`、`UNKNOWN`
</ResponseField>

<ResponseField name="output.video_url" type="string">
  完了したビデオ生成タスクのビデオ URL。リンクの有効期間は 24 時間です
</ResponseField>

<ResponseField name="request_id" type="string" required>
  一意のリクエスト識別子
</ResponseField>

<ResponseField name="usage" type="object">
  出力情報の統計。成功した結果のみがカウントされます
</ResponseField>

<ResponseField name="usage.SR" type="integer">
  ビデオ解像度レベル（I2V および wan3.0-video タスク）
</ResponseField>

<ResponseField name="usage.duration" type="number">
  生成されたビデオの再生時間（秒）（I2V および wan3.0-video タスク）
</ResponseField>

<ResponseField name="usage.fps" type="integer">
  生成されたビデオのフレームレート（wan3.0-video タスク）
</ResponseField>

<ResponseField name="usage.image_count" type="integer">
  生成された画像の数（T2I および I2I タスク）
</ResponseField>

<ResponseField name="usage.input_video_duration" type="number">
  入力ビデオの再生時間（秒）。ビデオ入力がない場合は 0.0（wan3.0-video タスク）
</ResponseField>

<ResponseField name="usage.output_video_duration" type="number">
  出力ビデオの再生時間（秒）（wan3.0-video タスク）
</ResponseField>

<ResponseField name="usage.ratio" type="string">
  生成されたビデオのアスペクト比（例: 16:9）（wan3.0-video タスク）
</ResponseField>

<ResponseField name="usage.size" type="string">
  画像解像度（T2I および I2I タスク）
</ResponseField>

<ResponseField name="usage.video_count" type="integer">
  生成されたビデオの数（T2V タスク）
</ResponseField>

<ResponseField name="usage.video_duration" type="number">
  生成されたビデオの再生時間（秒）（T2V タスク）
</ResponseField>

<ResponseField name="usage.video_ratio" type="string">
  ビデオ解像度の比率（T2V タスク）
</ResponseField>

<ResponseField name="code" type="string">
  失敗したリクエストのエラーコード。`output` の下ではなく、エンベロープの ROOT で報告されます（リクエストが成功した場合は返されません）。
</ResponseField>

<ResponseField name="message" type="string">
  失敗したリクエストの詳細情報。`output` の下ではなく、エンベロープの ROOT で報告されます（リクエストが成功した場合は返されません）。`output.message` にフォールバックする前にこちらを確認してください。
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "input": {
    "images": [
      "https://example.invalid/red-maple-leaf.png"
    ],
    "prompt": "Make the leaf golden."
  },
  "parameters": {
    "n": 1,
    "size": "768*768"
  }
}
```

### 出力

```json theme={null}
{
  "output": {
    "end_time": "2027-01-01T00:00:12.000Z",
    "results": [
      {
        "actual_prompt": "a single red maple leaf resting on still water, shallow depth of field, soft morning light",
        "orig_prompt": "a single red maple leaf resting on still water",
        "url": "https://example.invalid/wan/generated-1.png"
      },
      {
        "code": "DataInspectionFailed",
        "message": "This candidate was rejected; the task as a whole succeeded.",
        "orig_prompt": "a single red maple leaf resting on still water"
      }
    ],
    "scheduled_time": "2027-01-01T00:00:01.000Z",
    "submit_time": "2027-01-01T00:00:00.000Z",
    "task_id": "0385dc79-5ff8-4d82-bcb6-7c1a9f2e4d60",
    "task_metrics": {
      "FAILED": 1,
      "SUCCEEDED": 1,
      "TOTAL": 2
    },
    "task_status": "SUCCEEDED"
  },
  "request_id": "7574ee8f-38a3-4b1e-9280-11c33ab46e51",
  "usage": {
    "image_count": 1,
    "size": "1280*1280"
  }
}
```

## 出荷前の確認

SDK は `Idempotency-Key` を生成し、自動リトライで再利用します。手動リトライでは元のキーを再利用してください。Router は最大 10 分間接続を保持できます。

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

上記のフィールド説明に記載されているサイズ制限は、プロバイダーの仕様から引用した、そのフィールドに対するプロバイダー自身の上限です。Router はリクエスト本文全体に対して別の上限を適用し、base64 エンコードされたメディアもこれにカウントされます。[リクエスト本文のサイズ](/ja/development/comfy-router/limitations) を参照してください。

このページは、Comfy Router 経由で呼び出す 1 つのパートナーモデルについて説明しています。同じ `comfy-sdk` / `@comfyorg/sdk` パッケージには、Comfy Cloud 上で ComfyUI のワークフローグラフ全体を実行するための 2 つ目のクライアントも含まれています: `Comfy(api_key=...)` / `new Comfy({ apiKey })`、および `client.workflows`、`client.assets`、`client.jobs`。[Comfy SDKs](/ja/development/api-development/sdks) を参照してください。

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

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

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