AI Backgrounds

The Image Editing API allows you to easily create new backgrounds for your images.

This feature works by using Generative AI to dynamically create new backgrounds, that perfectly match the subject of the original picture.

Here's an example of how you can use AI Backgrounds to personalize product images at scale:

You can see even more examples of AI Backgrounds in our competitors benchmark.

Important: Model selection

You can switch to our new AI Backgrounds model by adding the following HTTP header in your request when calling the Image Editing API: pr-ai-background-model-version: 3

Here's an example of the difference in result between the current model and the new model:

current model

new model

Text Prompt

To add an AI Background using a text prompt, set the argument background.prompt with a description of the new background that you want to generate:

(original image)

background.prompt="the image displays a pair of blue sneakers on a tropical beach on a bright day with a slightly blurred background of the ocean"

background.prompt="the image features a pair of blue sneakers on a boulder with a breathtaking mountain view in the background"

background.prompt="the image depicts a pair of blue sneakers placed within a bustling city street background. The atmosphere is urban and replete with architectural details"

If you want to give it a try, here's the code to reproduce the first example above:

curl --request POST \
  --url https://image-api.photoroom.com/v2/edit \
  --header 'x-api-key: YOUR_API_KEY' \
  --form 'imageFile=@"/path/to/image.jpeg"' \
  --form 'referenceBox="originalImage"' \
  --form 'background.prompt="the image displays a pair of blue sneakers on a tropical beach on a bright day with a slightly blurred background of the ocean"' \
  --output result-ai-background.png

Image Prompt

Alternatively to providing a text prompt, you can also use an existing image as the prompt to generate an AI Background.

To use this feature, set either the argument background.guidance.imageFile or background.guidance.imageUrl:

original image

guidance image

result

If you want to give it a try, here's the code to reproduce it:

curl --request POST \
  --url https://image-api.photoroom.com/v2/edit \
  --header 'x-api-key: YOUR_API_KEY' \
  --form 'imageFile=@"/path/to/original-image.jpeg"' \
  --form 'referenceBox="originalImage"' \
  --form 'background.guidance.imageFile=@"/path/to/guidance-image.jpeg"' \
  --output result-ai-background-with-guidance.png

background.guidance.scale

Additionally, you can use the parameter background.guidance.scale to control how closely the generated background will be matching the guidance image.

A value of 1 means it will match the guiding image as much as possible, a value of 0 means the guiding image will be ignored. (Default value is 0.6)

background.guidance.scale=0.2

background.guidance.scale=0.4

background.guidance.scale=0.6

background.guidance.scale=0.8

background.guidance.scale=1.0

How to write a high-quality prompt

To use this feature, you will need to set the argument background.prompt.

The argument background.prompt is a textual description of what the new background should look like.

It can feel challenging to write a good prompt.

However, we have a way to provide you with good examples:

  1. Go to the Photoroom Web App and upload an image for which you'd like to generate a new background

  2. Open “Instant Backgrounds” on the left panel

  • The first 2 results are backgrounds that have been generated specifically for your image, and the prompt is visible below the tile!

  • And if you tap on any of the “scenes”, you'll see the full prompt on top. You can even edit it to see how variations of the prompt would impact the generated background!

If you want a result that looks similar to the 4 options generated by the apps, make sure that, in addition to the background.prompt, you also use the same background.seed than the apps.

Additional Parameters

In addition to background.prompt, the Image Editing API also provides two optional parameters that give you additional control over how the new background will be generated: background.negativePrompt and background.seed.

background.negativePrompt

background.negativePrompt allows you to refine your generated background by specifying elements our AI won’t include in the final image.

For example, if you'd like a wedding-themed background without any flowers in view, consider a background.negativePrompt such as "flowers":

background.seed

If you make several calls to the Image Editing API with the same image and the same prompt, you will notice that it will generate a different background each time.

This is great when you're looking for inspiration, but it might become an issue when you need consistency.

In order to reduce the randomness, you can set a fixed value for the seed that the API's random generator will use. The value of the argument background.seed can be any positive integer.

If you provide a value for background.seed, then the API should produce similar-looking backgrounds for the same prompt.

The iOS, Android and Web versions of PhotoRoom always use the same seeds for the first 4 generated background options they present to the user.

You can use the same values if you want to have results similar to that of the PhotoRoom apps: 117879368, 55994449, 48672244 and 65080068.

Last updated