> ## 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 で Image Edit Erase By Text を使用する

> Comfy Router 経由で bria/image-edit-erase-by-text を呼び出します: エンドポイント、リクエスト形状、および Router が返すレスポンスについて説明します。

`bria/image-edit-erase-by-text` の API リファレンス。Bria から 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 のスニペットは、raw HTTP による同じ呼び出しです。

**モデル ID:** `bria/image-edit-erase-by-text`

**エンドポイント:** `POST https://api.comfy.org/v2/models/bria/image-edit-erase-by-text`

<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(
              "bria/image-edit-erase-by-text",
              {
                  "image": "https://img.freepik.com/free-psd/close-up-delicious-apple_23-2151868338.jpg",
                  "object_name": "the pie",
              },
          )

      print(result)
      ```

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

      // 環境変数から COMFY_API_KEY を読み取ります。
      // SDK は冪等性キーを自動的に作成し、自動リトライのために再利用します。
      const { data } = await comfy.models.run("bria/image-edit-erase-by-text", {
        image: "https://img.freepik.com/free-psd/close-up-delicious-apple_23-2151868338.jpg",
        object_name: "the pie",
      });

      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(
          "bria/image-edit-erase-by-text",
          input: [
              "image": "https://img.freepik.com/free-psd/close-up-delicious-apple_23-2151868338.jpg",
              "object_name": "the pie",
          ]
      )

      print(result.output)
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/bria/image-edit-erase-by-text \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"image\": \"https://img.freepik.com/free-psd/close-up-delicious-apple_23-2151868338.jpg\", \"object_name\": \"the pie\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="キューに送信して後で収集">
    同じボディを `POST https://api.comfy.org/v2/models/bria/image-edit-erase-by-text/requests` に送信します。実行が受け付けられるとすぐに Router は `request_id` とともに `201` を返し、結果は準備できた時点で、このプロセスまたは別のプロセスから収集します。[キューの配信](/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(
              "bria/image-edit-erase-by-text",
              {
                  "image": "https://img.freepik.com/free-psd/close-up-delicious-apple_23-2151868338.jpg",
                  "object_name": "the pie",
              },
          )
          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("bria/image-edit-erase-by-text", {
        image: "https://img.freepik.com/free-psd/close-up-delicious-apple_23-2151868338.jpg",
        object_name: "the pie",
      });
      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(
          "bria/image-edit-erase-by-text",
          input: [
              "image": "https://img.freepik.com/free-psd/close-up-delicious-apple_23-2151868338.jpg",
              "object_name": "the pie",
          ]
      )
      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/bria/image-edit-erase-by-text/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"image\": \"https://img.freepik.com/free-psd/close-up-delicious-apple_23-2151868338.jpg\", \"object_name\": \"the pie\"}"

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

      # 3. 収集。200 はモデルのネイティブ出力、まだ実行中なら 202 とステータスボディを返します。
      curl https://api.comfy.org/v2/models/bria/image-edit-erase-by-text/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## スキーマ

### 入力

<ParamField body="image" type="string" required>
  編集する画像。サポートされる入力タイプは、Base64 エンコードされた文字列、または公開アクセス可能な画像ファイルを指す URL です。対応フォーマットは JPEG、JPG、PNG、WEBP です。
</ParamField>

<ParamField body="object_name" type="string" required>
  削除するオブジェクトのテキスト記述 (例: "the lamp")。
</ParamField>

Router が `GET /v2/models/bria/image-edit-erase-by-text/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}
{
  "image": "https://img.freepik.com/free-psd/close-up-delicious-apple_23-2151868338.jpg",
  "object_name": "the pie"
}
```

### 出力

```json theme={null}
{
  "request_id": "0b3f9d7e-2c41-4a8b-9f10-6d5c8e2a4b71",
  "result": {
    "image_url": "https://example.invalid/bria/image-edit-erase-by-text/generated.png",
    "seed": 42
  },
  "status": "COMPLETED"
}
```

## 出荷前の確認

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>
