> ## 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 で SwitchX を使用する

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

Comfy Router が Beeble から提供する `beeble/switchx` の API リファレンスです。

## クイックスタート

[あなたの 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:** `beeble/switchx`

**エンドポイント:** `POST https://api.comfy.org/v2/models/beeble/switchx`

<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(
              "beeble/switchx",
              {
                  "alpha_mode": "auto",
                  "generation_type": "image",
                  "max_resolution": 720,
                  "prompt": "A cinematic product photo of a glass lamp on a marble table",
                  "source_uri": "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80",
              },
          )

      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("beeble/switchx", {
        alpha_mode: "auto",
        generation_type: "image",
        max_resolution: 720,
        prompt: "A cinematic product photo of a glass lamp on a marble table",
        source_uri: "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/beeble/switchx \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"alpha_mode\": \"auto\", \"generation_type\": \"image\", \"max_resolution\": 720, \"prompt\": \"A cinematic product photo of a glass lamp on a marble table\", \"source_uri\": \"https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80\"}"
      ```
    </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(
              "beeble/switchx",
              {
                  "alpha_mode": "auto",
                  "generation_type": "image",
                  "max_resolution": 720,
                  "prompt": "A cinematic product photo of a glass lamp on a marble table",
                  "source_uri": "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80",
              },
          )
          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("beeble/switchx", {
        alpha_mode: "auto",
        generation_type: "image",
        max_resolution: 720,
        prompt: "A cinematic product photo of a glass lamp on a marble table",
        source_uri: "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80",
      });
      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/beeble/switchx/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"alpha_mode\": \"auto\", \"generation_type\": \"image\", \"max_resolution\": 720, \"prompt\": \"A cinematic product photo of a glass lamp on a marble table\", \"source_uri\": \"https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80\"}"

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

## スキーマ

### 入力

<ParamField body="alpha_mode" type="string" required>
  アルファモード: auto、fill、custom、または select

  指定可能な値: `auto`、`fill`、`custom`、`select`
</ParamField>

<ParamField body="alpha_uri" type="string">
  カスタムアルファマットの URI。alpha\_mode が custom または select の場合に必須です。auto または fill では無視されます。
</ParamField>

<ParamField body="callback_url" type="string">
  完了または失敗時に webhook 通知を受け取るための HTTPS URL。
</ParamField>

<ParamField body="generation_type" type="string" required>
  出力タイプ: 画像またはビデオ

  指定可能な値: `image`、`video`
</ParamField>

<ParamField body="idempotency_key" type="string">
  安全な再試行のための冪等性キー。同じキーのジョブがすでにアカウントに存在する場合、API は複製を作成せずに既存のジョブのステータスを返します。
</ParamField>

<ParamField body="max_resolution" type="integer" default="1080">
  最大出力解像度: 720 または 1080 (デフォルト: 1080)。
</ParamField>

<ParamField body="prompt" type="string">
  希望する出力のテキスト説明 (最大 2,000 文字)。prompt または reference\_image\_uri の少なくとも1つが必須です。
</ParamField>

<ParamField body="reference_image_uri" type="string">
  スタイル転送用の参照画像の URI。source\_uri と同じ URI タイプを受け付けます。
</ParamField>

<ParamField body="source_uri" type="string" required>
  ソース画像またはビデオの URI。beeble://uploads/\{id}/\{filename}、https URL、または data:\{mime};base64 URI を受け付けます (最大 50 MB)。
</ParamField>

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

### 出力

<ResponseField name="alpha_mode" type="string">
  auto、fill、custom、または select
</ResponseField>

<ResponseField name="completed_at" type="string">
  ジョブが完了または失敗したときの ISO 8601 タイムスタンプ。
</ResponseField>

<ResponseField name="created_at" type="string">
  ジョブが作成されたときの ISO 8601 タイムスタンプ。
</ResponseField>

<ResponseField name="error" type="string">
  エラーメッセージ (status が failed の場合に存在します)。
</ResponseField>

<ResponseField name="generation_type" type="string">
  画像またはビデオ
</ResponseField>

<ResponseField name="id" type="string" required>
  ジョブ識別子 (swx\_...)
</ResponseField>

<ResponseField name="modified_at" type="string">
  最後のステータス変更の ISO 8601 タイムスタンプ。
</ResponseField>

<ResponseField name="output" type="object">
  SwitchX ジョブの出力に対する署名付き URL。
</ResponseField>

<ResponseField name="output.alpha" type="string">
  アルファマットの URL。
</ResponseField>

<ResponseField name="output.render" type="string">
  合成済み出力の URL。
</ResponseField>

<ResponseField name="output.source" type="string">
  前処理済みソースの URL。
</ResponseField>

<ResponseField name="progress" type="integer">
  進行状況のパーセンテージ (0～100)。
</ResponseField>

<ResponseField name="status" type="string" required>
  現在のジョブステータス。

  指定可能な値: `in_queue`、`processing`、`completed`、`failed`
</ResponseField>

<ResponseField name="webhook" type="object">
  SwitchX ジョブの webhook 配信ステータス。
</ResponseField>

<ResponseField name="webhook.attempts" type="integer">
  これまでの配信試行回数。
</ResponseField>

<ResponseField name="webhook.last_error" type="string">
  最後に失敗した配信試行のエラーメッセージ。
</ResponseField>

<ResponseField name="webhook.status" type="string">
  pending、delivered、または failed
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "alpha_mode": "auto",
  "generation_type": "image",
  "max_resolution": 720,
  "prompt": "A cinematic product photo of a glass lamp on a marble table",
  "source_uri": "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80"
}
```

### 出力

```json theme={null}
{
  "alpha_mode": "auto",
  "completed_at": "2027-01-01T00:01:04Z",
  "created_at": "2027-01-01T00:00:00Z",
  "generation_type": "image",
  "id": "swx_1a2b3c4d5e6f7a8b",
  "modified_at": "2027-01-01T00:01:04Z",
  "output": {
    "alpha": "https://example.invalid/beeble/switchx/alpha.png",
    "render": "https://example.invalid/beeble/switchx/render.png",
    "source": "https://example.invalid/beeble/switchx/source.png"
  },
  "progress": 100,
  "status": "completed"
}
```

## 出荷前の確認

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>
