> ## 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 T2I Preview を使用する

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

`wan/wan2.5-t2i-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-t2i-preview`

**エンドポイント:** `POST https://api.comfy.org/v2/models/wan/wan2.5-t2i-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-t2i-preview",
              {
                  "input": {
                      "prompt": "A single red maple leaf on a plain white background.",
                  },
                  "parameters": {
                      "n": 1,
                      "size": "1280*1280",
                  },
              },
          )

      print(result)
      ```

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

      // 環境から COMFY_API_KEY を読み取ります。
      // SDK は自動的に冪等性キーを作成し、自動リトライ時に再利用します。
      const { data } = await comfy.models.run("wan/wan2.5-t2i-preview", {
        input: {
          prompt: "A single red maple leaf on a plain white background.",
        },
        parameters: {
          n: 1,
          size: "1280*1280",
        },
      });

      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-t2i-preview",
          input: [
              "input": [
                  "prompt": "A single red maple leaf on a plain white background.",
              ],
              "parameters": [
                  "n": 1,
                  "size": "1280*1280",
              ],
          ]
      )

      print(result.output)
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/wan/wan2.5-t2i-preview \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"prompt\":\"A single red maple leaf on a plain white background.\"}, \"parameters\": {\"n\":1,\"size\":\"1280*1280\"}}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="キューに送信して後で取得">
    同じボディを `POST https://api.comfy.org/v2/models/wan/wan2.5-t2i-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-t2i-preview",
              {
                  "input": {
                      "prompt": "A single red maple leaf on a plain white background.",
                  },
                  "parameters": {
                      "n": 1,
                      "size": "1280*1280",
                  },
              },
          )
          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-t2i-preview", {
        input: {
          prompt: "A single red maple leaf on a plain white background.",
        },
        parameters: {
          n: 1,
          size: "1280*1280",
        },
      });
      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-t2i-preview",
          input: [
              "input": [
                  "prompt": "A single red maple leaf on a plain white background.",
              ],
              "parameters": [
                  "n": 1,
                  "size": "1280*1280",
              ],
          ]
      )
      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-t2i-preview/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": {\"prompt\":\"A single red maple leaf on a plain white background.\"}, \"parameters\": {\"n\":1,\"size\":\"1280*1280\"}}"

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

## スキーマ

### 入力

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

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

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

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

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

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

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

<ParamField body="parameters.prompt_extend" type="boolean" default="true">
  プロンプトのインテリジェント書き換えを有効にします。デフォルトは true
</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 は 1638400 (1280*1280) から 2073600 (1440*1440) までのピクセル面積を、1:4 から 4:1 の間のアスペクト比で受け入れます。そのため 768\*2700 も有効です。
</ParamField>

<ParamField body="parameters.watermark" type="boolean" default="false">
  右下隅にウォーターマークロゴを追加するかどうか
</ParamField>

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

### 出力

<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` の下ではなく、エンベロープのルートで報告されます（リクエストが成功した場合は返されません）。
</ResponseField>

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

## 例

### 入力

```json theme={null}
{
  "input": {
    "prompt": "A single red maple leaf on a plain white background."
  },
  "parameters": {
    "n": 1,
    "size": "1280*1280"
  }
}
```

### 出力

```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>
