> ## 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.

# Chỉnh sửa hình ảnh với Bria

> Sử dụng Bria Image Editing API qua CometAPI để erase, gen_fill, expand, enhance, upscale hoặc thay thế nền bằng POST /bria/image/edit/{action}.

## Tổng quan

Bria's Image Editing API cung cấp một bộ công cụ toàn diện để chỉnh sửa và nâng cao chất lượng hình ảnh.

<Note>
  Sau khi gọi API thành công, hãy dùng `request_id` được trả về để truy vấn kết quả qua endpoint [Query Status](/api/image/bria/query-status).

  Tham số `sync` được cố định trên giao diện này — bạn không cần chỉ định nó.
</Note>

### Các thao tác được hỗ trợ

| Thao tác              | Mô tả                                  | Tài liệu                                                                                       |
| --------------------- | -------------------------------------- | ---------------------------------------------------------------------------------------------- |
| `erase`               | Xóa đối tượng khỏi hình ảnh            | [Tài liệu Bria Erase](https://docs.bria.ai/image-editing/v2-endpoints/erase)                   |
| `gen_fill`            | Generative fill cho các vùng được mask | [Tài liệu Bria Gen Fill](https://docs.bria.ai/image-editing/v2-endpoints/gen-fill)             |
| `expand`              | Mở rộng khung hình                     | [Tài liệu Bria Expand](https://docs.bria.ai/image-editing/v2-endpoints/image-expansion)        |
| `enhance`             | Nâng cao chất lượng hình ảnh           | [Tài liệu Bria Enhance](https://docs.bria.ai/image-editing/v2-endpoints/enhance)               |
| `increase_resolution` | Tăng độ phân giải hình ảnh             | [Tài liệu Bria Upscale](https://docs.bria.ai/image-editing/v2-endpoints/increase-resolution)   |
| `replace_background`  | Thay thế nền hình ảnh                  | [Tài liệu Bria Background](https://docs.bria.ai/image-editing/v2-endpoints/background-replace) |

Vui lòng tham khảo tài liệu chính thức để xem danh sách tham số dành riêng cho từng thao tác.


## 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.

````