> ## 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?onboarding=router) でキーを作成し、`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`

> [tab] 結果を待つ
>
> ```python Python theme={null}
> from comfy_sdk import Comfy
>
> # 環境変数から COMFY_API_KEY を読み取ります。
> # SDK は自動的に冪等キーを作成し、自動リトライのために再利用します。
> 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";
>
> // 環境変数から COMFY_API_KEY を読み取ります。
> // SDK は自動的に冪等キーを作成し、自動リトライのために再利用します。
> 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\"}"
> ```

> [tab] キューに送信して後で収集
>
> 同じボディを `POST https://api.comfy.org/v2/models/beeble/switchx/requests` に送信します。Router は実行が受け付けられ次第 `201` と `request_id` を返し、結果は準備が整った時点で、このプロセスからでも別のプロセスからでも取得できます。ステータス、キャンセル、結果の収集については [キュー配信](https://docs.comfy.org/ja/development/comfy-router/queue.md) を参照してください。
>
> ```python Python theme={null}
> import asyncio
> from comfy_sdk import AsyncComfy
>
> # 環境変数から COMFY_API_KEY を読み取ります。
> # 各 submit() 呼び出しは独自の Idempotency-Key を生成し、自動リトライ時に再利用します。
> async def main():
>     async with AsyncComfy() as client:
>         handle = await 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)  # モデル ID があれば、別のプロセスに必要なものはそれだけです
>
>         # リクエストが完了するまでポーリングし、サーバーが指定する Retry-After の秒数だけ待機します。
>         async for update in handle.iter_events():
>             print(update.status, update.queue_position)
>
>         # プロバイダー自身のペイロードで、models.run() が返すのと同じ値です。
>         # 失敗またはキャンセル済みのリクエストは、ここで型付きの Router エラーを発生させます。
>         result = await handle.get()
>
>     print(result)
>
> asyncio.run(main())
> ```
>
> ```typescript TypeScript theme={null}
> import { comfy } from "@comfyorg/sdk";
>
> // 環境変数から COMFY_API_KEY を読み取ります。
> // 各 submit() 呼び出しは独自の Idempotency-Key を生成し、自動リトライ時に再利用します。
> 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); // モデル 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);
> ```
>
> ```bash cURL theme={null}
> # 1. 送信。Router は request_id、status_url、response_url、cancel_url とともに 201 を返します。
> 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. ステータスが COMPLETED になるまでポーリングし、各レスポンスが指定する Retry-After 秒だけ待機します。
> 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. 収集。モデルのネイティブ出力とともに 200、まだ実行中はステータスボディとともに 202 を返します。
> curl https://api.comfy.org/v2/models/beeble/switchx/requests/$REQUEST_ID \
>   -H "X-API-Key: $COMFY_API_KEY"
> ```

## スキーマ

### 入力

**alpha\_mode** `string` *required*

アルファモード: auto、fill、custom、または select

指定可能な値: `auto`、`fill`、`custom`、`select`

**alpha\_uri** `string`

カスタムアルファマットの URI。alpha\_mode が custom または select の場合に必須です。auto または fill では無視されます。

**callback\_url** `string`

完了または失敗時に webhook 通知を受け取るための HTTPS URL。

**generation\_type** `string` *required*

出力タイプ: 画像またはビデオ

指定可能な値: `image`、`video`

**idempotency\_key** `string`

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

**max\_resolution** `integer` (default: 1080)

最大出力解像度: 720 または 1080 (デフォルト: 1080)。

**prompt** `string`

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

**reference\_image\_uri** `string`

スタイル転送用の参照画像の URI。source\_uri と同じ URI タイプを受け付けます。

**source\_uri** `string` *required*

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

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

### 出力

**alpha\_mode** `string`

auto、fill、custom、または select

**completed\_at** `string`

ジョブが完了または失敗したときの ISO 8601 タイムスタンプ。

**created\_at** `string`

ジョブが作成されたときの ISO 8601 タイムスタンプ。

**error** `string`

エラーメッセージ (status が failed の場合に存在します)。

**generation\_type** `string`

画像またはビデオ

**id** `string` *required*

ジョブ識別子 (swx\_...)

**modified\_at** `string`

最後のステータス変更の ISO 8601 タイムスタンプ。

**output** `object`

SwitchX ジョブの出力に対する署名付き URL。

**output.alpha** `string`

アルファマットの URL。

**output.render** `string`

合成済み出力の URL。

**output.source** `string`

前処理済みソースの URL。

**progress** `integer`

進行状況のパーセンテージ (0～100)。

**status** `string` *required*

現在のジョブステータス。

指定可能な値: `in_queue`、`processing`、`completed`、`failed`

**webhook** `object`

SwitchX ジョブの webhook 配信ステータス。

**webhook.attempts** `integer`

これまでの配信試行回数。

**webhook.last\_error** `string`

最後に失敗した配信試行のエラーメッセージ。

**webhook.status** `string`

pending、delivered、または failed

## 例

### 入力

```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 が入力を拒否したことを意味し、`413` はリクエスト本文が Router の受け入れ可能なサイズを超えていたことを意味します。生成されたアセットは [結果 URL の有効期限](https://docs.comfy.org/ja/development/comfy-router/reference.md#結果アセット) があるため、早めにダウンロードしてください。

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

このページは、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](https://docs.comfy.org/ja/development/api-development/sdks.md) を参照してください。

> [card] [ヘッダー](https://docs.comfy.org/ja/development/comfy-router/headers.md)
>
> 認証、冪等性、リクエスト ID、エラー分類、リトライ間隔、支出上限。

> [card] [Router API の利用](https://docs.comfy.org/ja/development/comfy-router/api.md)
>
> モデルの検出、バリデーションエラー、リトライ、課金。

> [card] [制限事項](https://docs.comfy.org/ja/development/comfy-router/limitations.md)
>
> Router が現在対応していないことと、代替手段。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.