Bria Erase Foreground

Seamlessly removes foreground subjects and regenerates backgrounds for flawless image editing.


API

If you're looking for an API, you can choose from your desired programming language.

POST
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 import requests import base64 # Use this function to convert an image file from the filesystem to base64 def image_file_to_base64(image_path): with open(image_path, 'rb') as f: image_data = f.read() return base64.b64encode(image_data).decode('utf-8') # Use this function to fetch an image from a URL and convert it to base64 def image_url_to_base64(image_url): response = requests.get(image_url) image_data = response.content return base64.b64encode(image_data).decode('utf-8') # Use this function to convert a list of image URLs to base64 def image_urls_to_base64(image_urls): return [image_url_to_base64(url) for url in image_urls] api_key = "YOUR_API_KEY" url = "https://api.segmind.com/v1/bria-erase-foreground" # Request payload data = { "image": "https://segmind-resources.s3.amazonaws.com/input/5fbaea92-e956-4290-b872-0b2e13a71ff0-a36a0e31-c0af-4528-8da1-03f57237e8a6.jpeg", "preserve_alpha": True, "visual_input_content_moderation": False, "visual_output_content_moderation": False } headers = {'x-api-key': api_key} response = requests.post(url, json=data, headers=headers) print(response.content) # The response is the generated image
RESPONSE
image/jpeg
HTTP Response Codes
200 - OKImage Generated
401 - UnauthorizedUser authentication failed
404 - Not FoundThe requested URL does not exist
405 - Method Not AllowedThe requested HTTP method is not allowed
406 - Not AcceptableNot enough credits
500 - Server ErrorServer had some issue with processing

Attributes


imagestr *

Provide a source image through a URL or Base64 string. Use a URL for faster processing.


preserve_alphaboolean ( default: true )

Choose to retain the image's alpha channel. Set to false for opaque outputs.


visual_input_content_moderationboolean ( default: 1 )

Enable to filter inappropriate content. Use for sensitive image handling.


visual_output_content_moderationboolean ( default: 1 )

Apply moderation on the output image. Ideal for public display verification.

To keep track of your credit usage, you can inspect the response headers of each API call. The x-remaining-credits property will indicate the number of remaining credits in your account. Ensure you monitor this value to avoid any disruptions in your API usage.

Resources to get you started

Everything you need to know to get the most out of Bria Erase Foreground

# Bria Erase Foreground: Quickstart & Best Practices

Bria Erase Foreground streamlines masking and inpainting in a single API call, automatically removing the main subject and regenerating the background with pixel-perfect accuracy. Use this guide to choose the right parameters for your workflow and maximize output quality.

## Parameter Overview
- **image** (required): URL or Base64-encoded image.  
- **preserve_alpha** (boolean, default: true):  
  – `true` to retain transparency (PNG cutouts).  
  – `false` for fully opaque outputs.  
- **visual_input_content_moderation** (boolean, default: false):  
  – `true` to pre-filter NSFW or sensitive content.  
- **visual_output_content_moderation** (boolean, default: false):  
  – `true` to enforce content checks on the generated image.

## Parameter Recommendations by Use Case

1. E-Commerce Catalogs  
   - **preserve_alpha**: false  
   - **moderation**: input=false, output=false  
   - **Why**: Consistent opaque backgrounds speed up batch product uploads and printing pipelines.

2. Marketing Assets & Social Media  
   - **preserve_alpha**: true  
   - **moderation**: input=false, output=true  
   - **Why**: Use transparent cutouts for dynamic backgrounds; enable output moderation to ensure brand safety.

3. Photo Restoration & Historical Edits  
   - **preserve_alpha**: false  
   - **moderation**: input=false, output=false  
   - **Why**: Fully blend removed subjects with original scene context for authenticity.

4. App & UI Design  
   - **preserve_alpha**: true  
   - **moderation**: input=false, output=false  
   - **Why**: Generate layered assets (buttons, icons) directly in your design tool.

5. User-Generated Content Platforms  
   - **preserve_alpha**: based on downstream use  
   - **moderation**: input=true, output=true  
   - **Why**: Enforce safe-for-work standards and prevent unwanted artifacts.

## Best Practices
1. **High Contrast Sources**  
   Provide images where foreground and background differ in color or brightness to improve mask accuracy.  
2. **Consistent Lighting & Textures**  
   Test across varying scenes—Bria excels at natural gradients and subtle details.  
3. **Batch Processing**  
   Leverage the high-throughput API for large catalogs. Keep `preserve_alpha` consistent across a batch for uniformity.  
4. **Format Matching**  
   Input JPEGs for faster processing; use PNG if you need alpha channels.  
5. **Moderation Workflow**  
   Integrate both moderation flags into your CI/CD to catch edge-case artifacts before publishing.

## Sample Payload
```json
POST /v1/erase_foreground
{
  "image": "https://example.com/product.jpg",
  "preserve_alpha": true,
  "visual_input_content_moderation": false,
  "visual_output_content_moderation": true
}

With these guidelines, you’ll harness Bria Erase Foreground’s full power—automating complex edits, maintaining quality, and scaling confidently.

Other Popular Models

Discover other models you might be interested in.

Cookie settings

We use cookies to enhance your browsing experience, analyze site traffic, and personalize content. By clicking "Accept all", you consent to our use of cookies.