> ## 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 で Video Edit Replace Background を使用する

> Comfy Router 経由で bria/video-edit-replace-background を呼び出します。エンドポイント、リクエストの形状、Router が返すレスポンスを説明します。

`bria/video-edit-replace-background` の API リファレンスです。Bria から Comfy Router によって提供されます。

## クイックスタート

[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:** `bria/video-edit-replace-background`

**エンドポイント:** `POST https://api.comfy.org/v2/models/bria/video-edit-replace-background`

<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(
              "bria/video-edit-replace-background",
              {
                  "background_url": "https://example.com/background.mp4",
                  "video": "https://example.com/input.mp4",
              },
          )

      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("bria/video-edit-replace-background", {
        background_url: "https://example.com/background.mp4",
        video: "https://example.com/input.mp4",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/bria/video-edit-replace-background \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"background_url\": \"https://example.com/background.mp4\", \"video\": \"https://example.com/input.mp4\"}"
      ```
    </CodeGroup>
  </Tab>

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

    <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(
              "bria/video-edit-replace-background",
              {
                  "background_url": "https://example.com/background.mp4",
                  "video": "https://example.com/input.mp4",
              },
          )
          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("bria/video-edit-replace-background", {
        background_url: "https://example.com/background.mp4",
        video: "https://example.com/input.mp4",
      });
      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/bria/video-edit-replace-background/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"background_url\": \"https://example.com/background.mp4\", \"video\": \"https://example.com/input.mp4\"}"

      # 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/bria/video-edit-replace-background/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/bria/video-edit-replace-background/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 入力

<ParamField body="background_url" type="string" required>
  前景の背後に合成する背景アセット（画像またはビデオ）の公開アクセス可能な URL。前景のアスペクト比と一致している必要があります。
</ParamField>

<ParamField body="output_container_and_codec" type="string">
  出力コンテナとコーデックのプリセット。

  取り得る値: `mp4_h264`, `mp4_h265`, `webm_vp9`, `mov_h265`, `mov_proresks`, `mkv_h264`, `mkv_h265`, `mkv_vp9`, `gif`
</ParamField>

<ParamField body="preserve_audio" type="boolean">
  入力（前景）ビデオのオーディオを保持するかどうか。
</ParamField>

<ParamField body="video" type="string" required>
  入力（前景）ビデオの公開アクセス可能な URL。入力解像度は最大 16000x16000（16K）までサポート。最大再生時間は 60 秒。
</ParamField>

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

### 出力

<ResponseField name="error" type="object">
  エラーオブジェクト（status が ERROR の場合のみ存在）
</ResponseField>

<ResponseField name="error.code" type="integer">
  エラーコード。
</ResponseField>

<ResponseField name="error.details" type="string">
  追加のエラー詳細。
</ResponseField>

<ResponseField name="error.message" type="string">
  エラーメッセージ。
</ResponseField>

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

<ResponseField name="result" type="object">
  結果オブジェクト（status が COMPLETED の場合のみ存在）
</ResponseField>

<ResponseField name="result.image_url" type="string">
  生成または編集された画像の URL。
</ResponseField>

<ResponseField name="result.prompt" type="string">
  オリジナルのプロンプト。
</ResponseField>

<ResponseField name="result.refined_prompt" type="string">
  プロンプトの改良版。Bria が改良を行わなかった COMPLETED の生成では null になります。キーが省略されるのではなく null を保持したまま存在するため nullable です。bria/image-edit-gen-fill で実際に確認されています。
</ResponseField>

<ResponseField name="result.seed" type="integer">
  生成に使用されたシード。
</ResponseField>

<ResponseField name="result.structured_prompt" type="string">
  詳細な JSON 構造化プロンプト。
</ResponseField>

<ResponseField name="result.video_url" type="string">
  生成されたビデオの URL。
</ResponseField>

<ResponseField name="status" type="string">
  リクエストの現在のステータス。

  取り得る値: `IN_PROGRESS`, `COMPLETED`, `ERROR`, `UNKNOWN`
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "background_url": "https://example.com/background.mp4",
  "video": "https://example.com/input.mp4"
}
```

### 出力

```json theme={null}
{
  "request_id": "0b3f9d7e-2c41-4a8b-9f10-6d5c8e2a4b71",
  "result": {
    "video_url": "https://example.invalid/bria/video-edit-replace-background/generated.mp4"
  },
  "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>
