# Bria Background Replace

> Bria Background Replace allows for efficient swapping of backgrounds in images via text prompts or reference image, delivering realistic and polished results. Trained exclusively on licensed data for safe and risk-free commercial use 


## Overview

- **Endpoint**: `https://fal.run/fal-ai/bria/background/replace`
- **Model ID**: `fal-ai/bria/background/replace`
- **Category**: image-to-image
- **Kind**: inference
**Tags**: image editing



## Pricing

- **Price**: $0.04 per generations

For more details, see [fal.ai pricing](https://fal.ai/pricing).

## API Information

This model can be used via our HTTP API or more conveniently via our client libraries.
See the input and output schema below, as well as the usage examples.


### Input Schema

The API accepts the following input parameters:


- **`image_url`** (`string`, _required_):
  Input Image to erase from
  - Examples: "https://storage.googleapis.com/falserverless/bria/bria_bg_replace_fg.jpg"

- **`ref_image_url`** (`string`, _optional_):
  The URL of the reference image to be used for generating the new background. Use "" to leave empty. 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. Default value: `""`
  - Default: `""`
  - Examples: "https://storage.googleapis.com/falserverless/bria/bria_bg_replace_bg.jpg"

- **`prompt`** (`string`, _optional_):
  The prompt you would like to use to generate images.
  - Examples: "Man leaning against a wall"

- **`negative_prompt`** (`string`, _optional_):
  The negative prompt you would like to use to generate images. Default value: `""`
  - Default: `""`

- **`refine_prompt`** (`boolean`, _optional_):
  Whether to refine prompt Default value: `true`
  - Default: `true`

- **`seed`** (`integer`, _optional_):
  The same seed and the same prompt given to the same version of the model
  will output the same image every time.
  - Range: `0` to `2147483647`

- **`fast`** (`boolean`, _optional_):
  Whether to use the fast model Default value: `true`
  - Default: `true`

- **`num_images`** (`integer`, _optional_):
  Number of Images to generate. Default value: `1`
  - Default: `1`
  - Range: `1` to `4`

- **`sync_mode`** (`boolean`, _optional_):
  If `True`, the media will be returned as a data URI and the output data won't be available in the request history.
  - Default: `false`



**Required Parameters Example**:

```json
{
  "image_url": "https://storage.googleapis.com/falserverless/bria/bria_bg_replace_fg.jpg"
}
```

**Full Example**:

```json
{
  "image_url": "https://storage.googleapis.com/falserverless/bria/bria_bg_replace_fg.jpg",
  "ref_image_url": "https://storage.googleapis.com/falserverless/bria/bria_bg_replace_bg.jpg",
  "prompt": "Man leaning against a wall",
  "refine_prompt": true,
  "fast": true,
  "num_images": 1
}
```


### Output Schema

The API returns the following output format:

- **`images`** (`list<Image>`, _required_):
  The generated images
  - Array of Image
  - Examples: [{"content_type":"image/png","url":"https://storage.googleapis.com/falserverless/bria/bria_bg_replace_res.jpg"}]

- **`seed`** (`integer`, _required_):
  Seed value used for generation.



**Example Response**:

```json
{
  "images": [
    {
      "content_type": "image/png",
      "url": "https://storage.googleapis.com/falserverless/bria/bria_bg_replace_res.jpg"
    }
  ]
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/fal-ai/bria/background/replace \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "image_url": "https://storage.googleapis.com/falserverless/bria/bria_bg_replace_fg.jpg"
   }'
```

### Python

Ensure you have the Python client installed:

```bash
pip install fal-client
```

Then use the API client to make requests:

```python
import fal_client

def on_queue_update(update):
    if isinstance(update, fal_client.InProgress):
        for log in update.logs:
           print(log["message"])

result = fal_client.subscribe(
    "fal-ai/bria/background/replace",
    arguments={
        "image_url": "https://storage.googleapis.com/falserverless/bria/bria_bg_replace_fg.jpg"
    },
    with_logs=True,
    on_queue_update=on_queue_update,
)
print(result)
```

### JavaScript

Ensure you have the JavaScript client installed:

```bash
npm install --save @fal-ai/client
```

Then use the API client to make requests:

```javascript
import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/bria/background/replace", {
  input: {
    image_url: "https://storage.googleapis.com/falserverless/bria/bria_bg_replace_fg.jpg"
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});
console.log(result.data);
console.log(result.requestId);
```


## Additional Resources

### Documentation

- [Model Playground](https://fal.ai/models/fal-ai/bria/background/replace)
- [API Documentation](https://fal.ai/models/fal-ai/bria/background/replace/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=fal-ai/bria/background/replace)

### fal.ai Platform

- [Platform Documentation](https://docs.fal.ai)
- [Python Client](https://docs.fal.ai/clients/python)
- [JavaScript Client](https://docs.fal.ai/clients/javascript)
