Image Modifications

Generate Campaign

Description

Note: This API route requires the image to be registered via the /register route.

Note: This API route and functionality can be accessed only after a consultation with our sales and support team. Please reach out to us at support@bria.ai for more information and assistance.

The campaign_generator Route enables users to create visual campaigns for various ad channels using a visual_id. This route facilitates the generation of templates featuring diverse layouts that incorporate elements like text, logos, and calls to action (CTA), branded to various resolutions (placements) and target audiences.

Ad backgrounds are expanded to fit the necessary layout specifications.

Examples

original image (Generated by Bria):

Results:

Request
path Parameters
visual_id
required
string
header Parameters
api_token
required
string
Request Body schema: application/json
required
sid
string

Session ID. Optional. obtained from a previous route response. Optional.

preset_id
string

Preset id. Optional. The brand preset that defines which logo, colors and typography should be used. If one isn’t provided, and some or none of the following are not provided (header1_color, header1_font, header1_size,header1_color, header1_font, header1_size, logo), the default public brand will be used.

template_id
string

Template ID, Mandatory. template_id or layout_ids must be provided. You can contact Bria to get your own templates and layouts.

layout_ids
Array of strings

Layout IDs, Mandatory. the ids of the layouts to generate. template_id or layout_ids must be provided. You can contact Bria to get your own templates and layouts.

logo
string

Logo URL. Optional. Supported inputs include public image URL or a URL inside Bria s3.

cta
string

CTA image URL. Optional. Supported inputs include public image URL or a URL inside Bria s3.

header1_text
string

Header1 text. Optional.

header1_font
string

Header1 font. Optional. Supported inputs include public ttf URL or a URL inside Bria s3.

header1_size
integer

Header1 size. Optional.

header1_color
Array of integers

Header1 color in hex format. Optional.

header2_text
string

Header2 text. Optional.

header2_font
string

Header2 font. Optional. Supported inputs include public tiff URL or a URL inside Bria s3.

header2_size
integer

Header2 size. Optional.

header2_color
Array of integers

Header2 color in hex format. Optional.

seed
integer

Seed used for image expansion. Optional. Use this to recreate the same ad.

background_type
string
Default: "original"

Background type. Optional.

Enum: "original" "generated" "solid"
bg_prompt
string

Background generation prompt. Mandatory when background_type is generated. Bria currently supports prompts in English only.

bg_seed
integer

Background seed. Optional. Relevant when background_type is generated.

bg_color
string

Background color in hex code. Mandatory when background_type is solid.

Responses
200

Successful response with generated campaign visuals.

400

Bad request.

404

Specified Image does not exist.

405

Method not allowed.

500

Internal server error.

506

Insufficient data. The given input is not supported by the Bria API.

post/{visual_id}/campaign_generator
Request samples
Response samples
application/json
{
  • "ads": [
    ]
}

Get Masks

Description

Note: This API route requires the image to be registered via the /register route.

The Objects/Mask Generator Route is used to generate all possible masks for an image, creating a full segmentation of the image.

The response contains a zip file named as the visual_id of the provided image.

There are k mask files in the zip, each named with the visual_id and mask_id.

The zip file contains an additional file whose name ends with "panoptic". It's not an image, it's a panoptic map. It can be transformed into a regular matrix.

Each point in the image (x,y) is mapped to the mask that applies to that point. In the panoptic map, each pixel's grayscale value includes the mask_id.

You can display those masks to the user, let them pick one or more masks, and use objects/remove route to remove the masked area.

In order to use the objects/remove route on the mask the user selected, you should provide the mask_id, and use the parameter mask_source=generated.

You can see below an example of the content of the zip:

  92bf8ce17584de82_panoptic.png

  
  92bf8ce17584de82_1.png

  
  92bf8ce17584de82_2.png

  
  92bf8ce17584de82_3.png

  
  ...

  
  92bf8ce17584de82_86.png

You can access the SDK that demonstrates how to use this endpoint in a UI in the following link.

Request
path Parameters
visual_id
required
string

visual id of the image, received after using the /upload or register route.

Example: 92bf8ce17584de82
header Parameters
api_token
required
string
Responses
200

Successful operation.

400

Bad request.

404

Specified Image does not exist.

405

Method not allowed.

500

Internal server error.

506

Insufficient data. The given input is not supported by the Bria API.

post/{visual_id}/objects/mask_generator
Request samples

Erase Foreground

Description

This route is used to erase the foreground from a provided image, while generating the area behind it.

Request
header Parameters
api_token
required
string
Request Body schema: application/json
image_url
string

The URL of the input image. 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 file of the input image, in base64 format. Used if image_url is not provided. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB.

Responses
200

Successful operation.

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.

451

Unavailable for legal reasons.

460

Failed to download image.

500

Internal server error. An error occurred on the server.

post/erase_foreground
Request samples
Response samples
application/json
{
  • "result_url": "URL"
}

Eraser

Description

The Eraser Route enables the removal of elements or specific areas from a given image.

You can define the area to be removed by providing a mask that outlines the region to be erased. There are two main ways recommended to generate these masks:

  1. Masks can be created by allowing users to draw directly on the image with a brush, for example. To access the SDK that demonstrates how to implement a brush feature in your interface, please refer to the following link.
  2. By using the /objects/mask_generator route, which will generate all the possible masks for an image.

This capability is powered by our fast ControlNet inpainting model. HF model card is available here, and the HF demo space can be found here

Additionally, ComfyUI nodes that enable running this API route can be found here

Request
header Parameters
api_token
required
string
Request Body schema: application/json
image_url
string

The URL of the input image. If both image_url and image_file are provided, image_url will be used. Accepted formats are jpeg, jpg, png, webp.

file
string

The file of the input image, in base64 format. Used if image_url is not provided. Accepted formats are jpeg, jpg, png, webp.

mask_url
string

The URL of the binary mask image that represents the area that will be cleaned. If both mask_url and mask_file are provided, mask_url will be used. Accepted formats - jpeg, jpg, png, webp. The area to be removed should have the value 255 (white), while the rest of the image should have the value 0 (black).

mask_file
string

The file of the binary mask image that represents the area that will be cleaned, in base64 format. This parameter is used if mask_url is not provided. Accepted formats - jpeg, jpg, png, webp. The area to be removed should have the value 255 (white), while the rest of the image should have the value 0 (black).

mask_type
string
Default: "manual"

You can use this parameter to specify the type of the input mask from the list. 'manual' opttion should be used in cases in which the mask had been generated by a user (e.g. with a brush tool), and 'automatic' mask type should be used when mask had been generated by an algorithm like 'SAM'.

Enum: "manual" "automatic"
Responses
200

Successful operation.

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.

415

Unsupported media type. Invalid file type. Supported file types are jpeg, jpg, png, webp.

460

Failed to download image.

500

Internal server error. An error occurred on the server.

post/eraser
Request samples
Response samples
application/json
{
  • "result_url": "URL"
}

Remove Background

Description

The Remove BG Route can be used to remove the background of an image.

The main difference between the regular and this isolated background removal endpoint is that you can use this endpoint without uploading or registering the image to Bria.

Constraints

The Bria API currently supports only JPEG and PNG files in RGB, RGBA, or CMYK color modes. When the file is of a different type or color mode, the status code 415 will be returned.

Remove the background from an image using the image file

In our documentation request example, we demonstrate how to remove the background from an image using the image URL.

If you want to use an image from a file, follow the example below:

  import requests

  url = "https://engine.prod.bria-api.com/v1/background/remove"

  payload = {}
  files=[
    ('file',('image_name.jpeg',open('/path_to_local_file/image_name.jpeg','rb'),'image/jpeg'))
  ]
  headers = {
    'api_token': 'xxxx'
  }

  response = requests.request("POST", url, headers=headers, data=payload, files=files)

  print(response.text)
Request
header Parameters
api_token
required
string
Request Body schema: application/x-www-form-urlencoded
required
file
string <binary>

The image file you would like to remove the background from.

image_url
string

The URL of the image file you would like to remove the background from. The URL should lead to an image publicly available online. Either a file or an image_url should be provided. If both are provided, then the route will use image_url.

Responses
200

Successful operation.

206

File value was not provided.

400

Request doesn't contain file part.

405

Method not allowed.

415

Unsupported media type.

460

Failed to download image.

500

Internal server error.

506

Insufficient data. The given input is not supported by the Bria API.

post/background/remove
Request samples
Response samples
application/json
{
  • "result_url": "string"
}

Blur Background

Description

The background/blur Route is used to create a blur effect on the background of an image.

Request
header Parameters
api_token
required
string
Request Body schema: application/json
image_url
string

The URL of the input image. 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 file of the input image, in base64 format. Used if image_url is not provided. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB.

scale
integer [ 1 .. 5 ]
Default: 5

A scale for determining how blurry the background of the image should be. The options are 1, 2, 3, 4, 5. This parameter is optional.

Responses
200

Successful operation.

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.

451

Unavailable for legal reasons.

460

Failed to download image.

500

Internal server error. An error occurred on the server.

post/background/blur
Request samples
Response samples
application/json
{
  • "result_url": "URL"
}

Generate Background

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 (available on Hugging Face). We offer a fast version of this feature, powered by Bria 2.3 Fast LoRA (model card on Hugging Face), 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:

bg_prompt: in a parking lot

num_results: 3

results:

Request
header Parameters
api_token
required
string

API token associated with the organization.

Request Body schema: application/json
sync
boolean
Default: false

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
Default: true

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.

bg_prompt
string

Text description of the new scene or background for the provided image. Bria currently supports prompts in English only, excluding special characters.

refine_prompt
boolean
Default: true

When true, an additional logic takes the bg_prompt that was included and adjusts it to achieve optimal results. Built with Meta Llama 3.

original_quality
boolean
Default: false

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
Default: 4

The number of results you would like to generate.

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.

Responses
200

Successful operation.

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.

451

Unavailable for legal reasons.

460

Failed to download image.

500

Internal server error. An error occurred on the server.

post/background/replace
Request samples
Response samples
application/json
{
  • "result": [
    ]
}

Expand Image

Description

The Image Expension Route can be used to expand an image, by utilizing generative AI.

You can decide on the image size of the final result as well as the position and size of the original image compared to the final result.

In this way, you can create unique variations of your original image instead of cropping it into different aspect ratios and losing important details.

Optimal input range

Input Image Area: Ensure that the ratio of the input image area to the canvas area is greater than 15% to achieve optimal results.

Canvas Size: The canvas size should be up to an area of 5000x5000 pixels. Here are some examples:

original image (Generated by Bria):

results:

original image (Stock Image):

results:

Request
header Parameters
api_token
required
string
Request Body schema: application/json
image_url
string

The URL of the input image. 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 file of the input image, in base64 format. Used if image_url is not provided. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB.

canvas_size
Array of integers
Default: [1000,1000]

The desired size of the final image, after the expansion. should have an area of less than 5000x5000 pixels.

original_image_size
Array of integers

The desired size of the original image, inside the full canvas. Ensure that the ratio of original image area to the canvas area is greater than 15% to achieve optimal results.

original_image_location
Array of integers

The desired location of the original image, inside the full canvas. Provide the location of the upper left corner of the original image. The location can also be outside the canvas (the original image will be cropped).

prompt
string

Text on which you wish to base the image expansion. This parameter is optional. Bria currently supports prompts in English only, excluding special characters.

seed
integer

You can choose whether you want your generated expension 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.

negative_prompt
string

This parameter is optional. Bria currently supports prompts in English only.

Responses
200

Successful operation.

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.

451

Unavailable for legal reasons.

460

Failed to download image.

500

Internal server error. An error occurred on the server.

post/image_expansion
Request samples
Response samples
application/json
{
  • "code": 200,
  • "description": "SUCCESS",
  • "message": "Finished sucessfully",
  • "prompt": "a man in a shirt sitting down in front of a brick wall looking off to the side",
  • "result_url": "URL",
  • "seed": 1525972691,
  • "status": "SUCCESS"
}

Increase Resolution

Description

The Isolated Increase Resolution Route is used to upscale the resolution of any image.

The main difference between the regular and this isolated Increase Resolution endpoint is that you can use this endpoint without uploading or registering the image to Bria.

Constraints

The Bria API currently supports only JPEG and PNG files in RGB, RGBA, or CMYK color modes. When the file is of a different type or color mode, the status code 415 will be returned.

It's possible to increase the resolution of an image up to a total area of 8192x8192 pixels.

Increase the Resolution of an image using the image file

In our documentation request example, we demonstrate how to Increase the Resolution of an image using the image URL.

If you want to use an image from a file, follow the example below:

  import requests

  url = "https://engine.prod.bria-api.com/v1/image/increase_resolution?desired_increase=2"

  payload = {}
  files=[
    ('file',('image_name.jpeg',open('/path_to_local_file/image_name.jpeg','rb'),'image/jpeg'))
  ]
  headers = {
    'api_token': 'xxxx'
  }

  response = requests.request("POST", url, headers=headers, data=payload, files=files)

  print(response.text)
            
Request
query Parameters
desired_increase
integer

The resolution multiplier. The possible value are 2,4. It's possible to increase the resolution of an image up to a total area of 8,192x8,192 pixels.

Example: desired_increase=2
header Parameters
api_token
required
string
Request Body schema: application/x-www-form-urlencoded
required
file
string <binary>

The image file you would like to increase the resolution for. Minimum resolution supported for width and/or height is 216 pixels.

image_url
string

The URL of the image file you would like to increase the resolution for. The URL should lead to an image publicly available online. Either a file or an image_url should be provided. If both are provided, then the route will use image_url. Minimum resolution supported for width and/or height is 216 pixels.

Responses
200

Successful operation.

400

Bad request

405

Method not allowed.

406

The input image's resolution is too low.

460

Failed to download image.

500

Internal server error.

506

Insufficient data. The given input is not supported by the Bria API.

Delayer Image

Description

Note: This API route requires the image to be registered via the /register route. It will be replaced soon with isolated version, that doesn't require image registration.

The Image to PSD Route is used to create a layered PSD file from any image.

The image is divided into different layers (depending on the image): a background layer with all identified objects removed, a foreground layer without the background, and a layer for each object.

You can also use this route on a modified image by providing the sid from the response of the previously used route.

Request
path Parameters
visual_id
required
string

visual id of the image, for which the user would like to create a layered PSD file

Example: 8487fb411f3c6716
query Parameters
sid
string

This session id was obtained from the response of a route that had been applied to this visual id. If you have used another route on the provided visual before, and you would like the current route to apply on the result of that route, please provide this information. This parameter is optional.

Example: sid=Remove this parameter if the image has not been modified using Bria.
header Parameters
api_token
required
string
Responses
200

Successful operation.

400

Bad request.

404

Specified Image does not exist.

405

Method not allowed.

500

Internal server error.

506

Insufficient data. The given input is not supported by the Bria API.

Crop out foreground

Description

The Crop Route is used to crop an image without a background tightly around the remaining region of interest.

You can utilize Bria's /background/remove endpoint and then use the result of that route in the/crop route.

Request
header Parameters
api_token
required
string
Request Body schema: application/json
optional
image_url
string

The URL of the input image. 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 file of the input image, in base64 format. Used if image_url is not provided. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB.

padding
integer
Default: 0

Cropping the object with padding around it. Currently, padding is applied to all four borders of the remaining region. This parameter is optional.

Responses
200

Successful operation.

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.

451

Unavailable for legal reasons.

460

Failed to download image.

500

Internal server error. An error occurred on the server.

post/crop
Request samples
Response samples
application/json
{
  • "result_url": "URL"
}