> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 Bria 编辑图像

> 通过 CometAPI 使用 Bria 图像编辑 API，可通过 POST /bria/image/edit/{action} 执行 erase、gen_fill、expand、enhance、upscale 或替换背景。

## 概述

Bria 的图像编辑 API 提供了一套全面的工具，用于处理和增强图像。

<Note>
  API 调用成功后，使用返回的 `request_id` 通过 [查询状态](/api/image/bria/query-status) 端点查询结果。

  此接口中的 `sync` 参数是固定的——你无需指定它。
</Note>

### 支持的操作

| Operation             | Description  | Documentation                                                                              |
| --------------------- | ------------ | ------------------------------------------------------------------------------------------ |
| `erase`               | 从图像中移除对象     | [Bria Erase Docs](https://docs.bria.ai/image-editing/v2-endpoints/erase)                   |
| `gen_fill`            | 对蒙版区域进行生成式填充 | [Bria Gen Fill Docs](https://docs.bria.ai/image-editing/v2-endpoints/gen-fill)             |
| `expand`              | 扩展图像画布       | [Bria Expand Docs](https://docs.bria.ai/image-editing/v2-endpoints/image-expansion)        |
| `enhance`             | 增强图像质量       | [Bria Enhance Docs](https://docs.bria.ai/image-editing/v2-endpoints/enhance)               |
| `increase_resolution` | 提升图像分辨率      | [Bria Upscale Docs](https://docs.bria.ai/image-editing/v2-endpoints/increase-resolution)   |
| `replace_background`  | 替换图像背景       | [Bria Background Docs](https://docs.bria.ai/image-editing/v2-endpoints/background-replace) |

请参考官方文档，查看各操作对应的参数列表。


## OpenAPI

````yaml api/openapi/image/bria/post-image-editing.openapi.json POST /bria/image/edit/{action}
openapi: 3.1.0
info:
  title: Image Editing API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /bria/image/edit/{action}:
    post:
      summary: Image Editing
      operationId: image_editing
      parameters:
        - name: action
          in: path
          required: true
          description: >-
            Editing action to perform. Supported values: `erase`, `gen_fill`,
            `expand`, `enhance`, `increase_resolution`, `replace_background`.
          schema:
            type: string
        - name: Content-Type
          in: header
          required: false
          description: Must be `application/json`.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                image:
                  type: string
                  description: >-
                    Source image as a public URL or base64-encoded data URI.
                    Accepted formats: JPEG, PNG, WebP. Maximum 12 MB.
                mask:
                  type: string
                  description: >-
                    Mask image as a public URL or base64. White areas mark the
                    region to edit; black areas are preserved. Required for
                    `erase`, `gen_fill`, and `expand` actions.
                prompt:
                  type: string
                  description: >-
                    Text description of the desired edit. Required for
                    `gen_fill` and `replace_background` actions.
                num_results:
                  type: integer
                  description: 'Number of result variants to generate. Default: 1.'
                sync:
                  type: boolean
                  description: >-
                    When `true`, the response blocks until results are ready.
                    When `false` (default), returns immediately with placeholder
                    URLs that can be polled.
            examples:
              eraser:
                summary: eraser
                value:
                  image: >-
                    https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png
                  mask: >-
                    https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png
              gen_fill:
                summary: gen_fill
                value:
                  image: >-
                    https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png
                  mask: >-
                    https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png
                  prompt: textual description
              increase_resolution:
                summary: increase_resolution
                value:
                  image: https://images.unsplash.com/photo-1506905925346-21bda4d32df4
              replace_background:
                summary: replace_background
                value:
                  image: https://images.unsplash.com/photo-1506905925346-21bda4d32df4
                  prompt: in a living room interior, on a kitchen counter
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties: {}
              example:
                request_id: <request_id>
      x-codeSamples:
        - lang: Shell
          label: Default
          source: >
            # Replace replace_background with the action you need: erase,
            gen_fill,

            # increase_resolution, remove_background, ...

            curl https://api.cometapi.com/bria/image/edit/replace_background \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "image": "https://your-image-host/source.jpg",
                "prompt": "in a cozy living room"
              }'
        - lang: Python
          label: Default
          source: >
            import os

            import requests


            # Replace replace_background with the action you need: erase,
            gen_fill,

            # increase_resolution, remove_background, ...

            response = requests.post(
                "https://api.cometapi.com/bria/image/edit/replace_background",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                    "image": "https://your-image-host/source.jpg",
                    "prompt": "in a cozy living room",
                },
            )


            task = response.json()

            print(task["request_id"])  # poll GET /bria/{request_id} until
            status COMPLETED
        - lang: JavaScript
          label: Default
          source: >
            // Replace replace_background with the action you need: erase,
            gen_fill,

            // increase_resolution, remove_background, ...

            const response = await
            fetch("https://api.cometapi.com/bria/image/edit/replace_background",
            {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                    image: "https://your-image-host/source.jpg",
                    prompt: "in a cozy living room",
                }),
            });


            const task = await response.json();

            console.log(task.request_id); // poll GET /bria/{request_id} until
            status COMPLETED
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````