---
title: "Generate Background"
method: POST
path: "/background/replace"
tags: ["Image Editing"]
---

# Generate Background

`POST /background/replace`

**Description**


The *Replace BG Route* is used to replace the background of any image with a generated background using the state-of-the-art BRIA 2.3 ControlNet BG-Gen model (<a href="https://huggingface.co/briaai/BRIA-2.3-ControlNet-BG-Gen" target="_blank">available on Hugging Face</a>). 
We offer a fast version of this feature, powered by Bria 2.3 Fast LoRA (<a href="https://huggingface.co/briaai/BRIA-2.3-FAST-LORA" target="_blank">model card on Hugging Face</a>), which provides an optimal balance between speed and quality.
This endpoint also supports solid colors - you can take a color code and use it in the prompt.        
Here are some examples:

**original image**: 

<img src="https://i.ibb.co/n6JtktM/unnamed-13.jpg" width="200"/>

**bg_prompt**: in a parking lot
        

**num_results**: 3

**results**:

<img src="https://i.ibb.co/1zvT5h4/unnamed-14.jpg" width="200"/> <img src="https://i.ibb.co/MkVDxc8/unnamed-15.jpg" width="200"/> <img src="https://i.ibb.co/pfgQ34p/unnamed-16.jpg" width="200"/>

## Headers

- `api_token` string, required

## Request body

- object
  - `sync` boolean — Determines the response mode. When true, responses are synchronous. With false, responses are asynchronous, immediately providing URLs for images that are generated in the background. It is recommended to use sync=false for optimal performance. When generating more than 1 result, you should use the value false.
  - `fast` boolean — Determines the generation mode. When true, the generation will utilize the fast mode which provides the best balance between speed and quality. When false, the regular mode will be utilized.
  - `image_url` string — The URL of the image to which a new background should be generated. If both image_url and image_file are provided, image_url will be used. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB.
  - `file` string — The product of the image to which a new background should be generated, in base64 format. Used if image_url is not provided. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB.
  - `ref_image_url` string — The URL of the reference image to be used for generating the new background. Either ref_image_url or bg_prompt has to be provided but not both. If both ref_image_url and ref_image_file are provided, ref_image_url will be used. Accepted formats are jpeg, jpg, png, webp.
  - `ref_image_file` string — The reference image file to be used for generating the new background. If both ref_image_url and ref_image_file are provided, ref_image_url will be used. Accepted formats are jpeg, jpg, png, webp.
  - `bg_prompt` string — Text description of the new scene or background for the provided image. Either ref_image_url or bg_prompt has to be provided but not both. Bria currently supports prompts in English only, excluding special characters.
  - `refine_prompt` boolean — When true, an additional logic takes the bg_prompt that was included and adjusts it to achieve optimal results. Built with Meta Llama 3.
  - `enhance_ref_image` boolean — When set to true, additional logic processes the included reference image to make adjustments for optimal results.
  - `original_quality` boolean — When true, the output image retains the original input image's size; otherwise, the image is scaled to 1 megapixel (1MP) while preserving its aspect ratio.
  - `num_results` integer — The number of results you would like to generate.
  - `force_rmbg` boolean — Forces background removal, even if the original image already contains an alpha channel. Useful for refining existing foreground/background separation or ignoring unnecessary alpha channels.
  - `negative_prompt` string — Elements or features that should be excluded from the generated scene. This parameter is optional and is available only when fast=false. Bria currently supports descriptions in English only.
  - `seed` integer — You can choose whether you want your generated results to be random or predictable. You can recreate the same result in the future by using the seed value of a result from the response. You can exclude this parameter if you are not interested in recreating your results. This parameter is optional.

## Response `200`

Successful operation.

- object
  - `result` array[] — The array contains the results created in the request. In each result, the first value represents the URL of the result, the second value represents the seed, and the third value represents the sessions id of the result. Bria recognizes offensive and inappropriate images. The URL will lead to a 0-byte file if an image like that is generated. It will take a few seconds for the image to become available via the URL if sync=false. You can recreate the same result in the future by using the seed as part of the request. The sid (session id) represents the result of the current route request.
    - unknown[]
      - unknown

## Other responses

- `400` — Bad request. Missing or invalid parameters.
- `401` — Unauthorized. Invalid API key or authentication token.
- `404` — Not found. Image could not be found at the provided URL.
- `413` — Payload too large. Image file size exceeds the 12MB limit.
- `415` — Unsupported media type. Invalid file type. Supported file types are jpeg, jpg, png, webp.
- `429` — Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.
- `451` — Unavailable for legal reasons.
- `460` — Failed to download image.
- `500` — Internal server error. An error occurred on the server.

---

[API](https://skmtc.net/bria-ai/apis/the-bria-api.md) · [All operations](https://skmtc.net/bria-ai/apis/the-bria-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/bria-ai/the-bria-api/versions/2768230345a5/schema)
