> ## Documentation Index
> This page is part of the Image and Video APIs product. Fetch the complete documentation index for Image and Video APIs at: https://cloudinary.com/documentation/llms-image-and-video-apis.txt?referrer=docpage and then use it to discover all relevant pages before exploring further.
> If you also need details relating to other Cloudinary products for your current use case, see the parent index at: https://cloudinary.com/documentation/llms.txt?referrer=docpage

# Generative background replace


Use AI to generate an alternative background for your images. The new background takes into account the foreground elements, positioning them naturally within the scene.

For product and lifestyle photography, this means you can place the same subject in entirely different settings, such as seasonal scenes, branded backdrops, or new campaign concepts, without a new photo shoot. One source photo can be reused across many contexts, each with a background suited to its audience.

> **See also**:
>
> Explore the complete syntax and all options for this effect, or try it out on your own images in the Console:

> * **See full syntax**: [e_gen_background_replace](transformation_reference#e_gen_background_replace) in the _Transformation Reference_

> * **Try it out**: [Generative background replace](https://console.cloudinary.com/app/image/playground/generative-background-replace?media=image&collection=objects&sample=me%2Fgen-bgr-object-1&prompt=Minimalist+background+with+a+soft+pastel+gradient+even+lighting)

## Generative background replace overview

> **INFO**:
>
> **Generative background replace** is currently in Beta. There may be minor changes in functionality before the general access release. We would appreciate any feedback via our [support team](https://support.cloudinary.com/hc/en-us/requests/new).

For images with transparency, the generated background replaces the transparent area. For images without transparency, the effect first determines the foreground elements and leaves those areas intact, while replacing the background. 

You can use generative background replace without a prompt, and let the AI decide what to show in the background, based on the foreground elements. For example, replace the background of this image (`e_gen_background_replace`):

![Background replaced in image of a model](https://res.cloudinary.com/demo/image/upload/e_gen_background_replace/docs/woman-sitting.jpg "with_image:false")

```nodejs
cloudinary.image("docs/woman-sitting.jpg", {effect: "gen_background_replace"})
```

```react
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace()
);
```

```vue
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace()
);
```

```angular
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace()
);
```

```js
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace()
);
```

```python
CloudinaryImage("docs/woman-sitting.jpg").image(effect="gen_background_replace")
```

```php
use Cloudinary\Transformation\Effect;

(new ImageTag('docs/woman-sitting.jpg'))
	->effect(Effect::generativeBackgroundReplace());
```

```java
cloudinary.url().transformation(new Transformation().effect("gen_background_replace")).imageTag("docs/woman-sitting.jpg");
```

```ruby
cl_image_tag("docs/woman-sitting.jpg", effect: "gen_background_replace")
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation().Effect("gen_background_replace")).BuildImageTag("docs/woman-sitting.jpg")
```

```dart
cloudinary.image('docs/woman-sitting.jpg').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace()));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setEffect("gen_background_replace")).generate("docs/woman-sitting.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation().effect("gen_background_replace")).generate("docs/woman-sitting.jpg");
```

```flutter
cloudinary.image('docs/woman-sitting.jpg').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace()));
```

```kotlin
cloudinary.image {
	publicId("docs/woman-sitting.jpg")
	 effect(Effect.generativeBackgroundReplace()) 
}.generate()
```

```jquery
$.cloudinary.image("docs/woman-sitting.jpg", {effect: "gen_background_replace"})
```

```react_native
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace()
);
```

Original image

Replace the background

Alternatively, you can use a natural language prompt to guide the AI and describe what you want to see in the background. For example, place the model in front of an old castle (`e_gen_background_replace:prompt_an%20old%20castle`):

![Background replaced in image of a model](https://res.cloudinary.com/demo/image/upload/e_gen_background_replace:prompt_an%20old%20castle/docs/woman-sitting.jpg "thumb:c_scale,w_300, width:300")

```nodejs
cloudinary.image("docs/woman-sitting.jpg", {effect: "gen_background_replace:prompt_an old castle"})
```

```react
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle")
);
```

```vue
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle")
);
```

```angular
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle")
);
```

```js
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle")
);
```

```python
CloudinaryImage("docs/woman-sitting.jpg").image(effect="gen_background_replace:prompt_an old castle")
```

```php
use Cloudinary\Transformation\Effect;

(new ImageTag('docs/woman-sitting.jpg'))
	->effect(Effect::generativeBackgroundReplace()->prompt("an old castle"));
```

```java
cloudinary.url().transformation(new Transformation().effect("gen_background_replace:prompt_an old castle")).imageTag("docs/woman-sitting.jpg");
```

```ruby
cl_image_tag("docs/woman-sitting.jpg", effect: "gen_background_replace:prompt_an old castle")
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation().Effect("gen_background_replace:prompt_an old castle")).BuildImageTag("docs/woman-sitting.jpg")
```

```dart
cloudinary.image('docs/woman-sitting.jpg').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace().prompt("an old castle")));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setEffect("gen_background_replace:prompt_an old castle")).generate("docs/woman-sitting.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation().effect("gen_background_replace:prompt_an old castle")).generate("docs/woman-sitting.jpg");
```

```flutter
cloudinary.image('docs/woman-sitting.jpg').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace().prompt("an old castle")));
```

```kotlin
cloudinary.image {
	publicId("docs/woman-sitting.jpg")
	 effect(Effect.generativeBackgroundReplace() { prompt("an old castle") }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/woman-sitting.jpg", {effect: "gen_background_replace:prompt_an old castle"})
```

```react_native
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle")
);
```

## Generate different backgrounds

The same background is generated every time you use the same prompt (and keep any preceding transformations the same). You can generate a different background with the same prompt (or no prompt) by setting the`seed` parameter. A different result is generated for each value you set. For example, regenerate the background for the old castle example (`e_gen_background_replace:prompt_an%20old%20castle;seed_1`):

![Background replaced in image of a model](https://res.cloudinary.com/demo/image/upload/e_gen_background_replace:prompt_an%20old%20castle;seed_1/docs/woman-sitting.jpg "thumb:c_scale,w_300, width:300")

```nodejs
cloudinary.image("docs/woman-sitting.jpg", {effect: "gen_background_replace:prompt_an old castle;seed_1"})
```

```react
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle").seed(1)
);
```

```vue
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle").seed(1)
);
```

```angular
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle").seed(1)
);
```

```js
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle").seed(1)
);
```

```python
CloudinaryImage("docs/woman-sitting.jpg").image(effect="gen_background_replace:prompt_an old castle;seed_1")
```

```php
use Cloudinary\Transformation\Effect;

(new ImageTag('docs/woman-sitting.jpg'))
	->effect(Effect::generativeBackgroundReplace()->prompt("an old castle")
->seed(1));
```

```java
cloudinary.url().transformation(new Transformation().effect("gen_background_replace:prompt_an old castle;seed_1")).imageTag("docs/woman-sitting.jpg");
```

```ruby
cl_image_tag("docs/woman-sitting.jpg", effect: "gen_background_replace:prompt_an old castle;seed_1")
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation().Effect("gen_background_replace:prompt_an old castle;seed_1")).BuildImageTag("docs/woman-sitting.jpg")
```

```dart
cloudinary.image('docs/woman-sitting.jpg').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace().prompt("an old castle")
.seed(1)));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setEffect("gen_background_replace:prompt_an old castle;seed_1")).generate("docs/woman-sitting.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation().effect("gen_background_replace:prompt_an old castle;seed_1")).generate("docs/woman-sitting.jpg");
```

```flutter
cloudinary.image('docs/woman-sitting.jpg').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace().prompt("an old castle")
.seed(1)));
```

```kotlin
cloudinary.image {
	publicId("docs/woman-sitting.jpg")
	 effect(Effect.generativeBackgroundReplace() { prompt("an old castle")
 seed(1) }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/woman-sitting.jpg", {effect: "gen_background_replace:prompt_an old castle;seed_1"})
```

```react_native
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-sitting.jpg").effect(
  generativeBackgroundReplace().prompt("an old castle").seed(1)
);
```

If you want to reproduce a background, use the same seed value, and make sure to keep any preceding transformation parameters the same. Subsequent parameters can be different, for example, scale down the same image:

![Background replaced in image of a model and scaled down](https://res.cloudinary.com/demo/image/upload/e_gen_background_replace:prompt_an%20old%20castle;seed_1/c_scale,w_200/docs/woman-sitting.jpg "width: 200")

```nodejs
cloudinary.image("docs/woman-sitting.jpg", {transformation: [
  {effect: "gen_background_replace:prompt_an old castle;seed_1"},
  {width: 200, crop: "scale"}
  ]})
```

```react
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";
import { scale } from "@cloudinary/url-gen/actions/resize";

new CloudinaryImage("docs/woman-sitting.jpg")
  .effect(generativeBackgroundReplace().prompt("an old castle").seed(1))
  .resize(scale().width(200));
```

```vue
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";
import { scale } from "@cloudinary/url-gen/actions/resize";

new CloudinaryImage("docs/woman-sitting.jpg")
  .effect(generativeBackgroundReplace().prompt("an old castle").seed(1))
  .resize(scale().width(200));
```

```angular
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";
import { scale } from "@cloudinary/url-gen/actions/resize";

new CloudinaryImage("docs/woman-sitting.jpg")
  .effect(generativeBackgroundReplace().prompt("an old castle").seed(1))
  .resize(scale().width(200));
```

```js
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";
import { scale } from "@cloudinary/url-gen/actions/resize";

new CloudinaryImage("docs/woman-sitting.jpg")
  .effect(generativeBackgroundReplace().prompt("an old castle").seed(1))
  .resize(scale().width(200));
```

```python
CloudinaryImage("docs/woman-sitting.jpg").image(transformation=[
  {'effect': "gen_background_replace:prompt_an old castle;seed_1"},
  {'width': 200, 'crop': "scale"}
  ])
```

```php
use Cloudinary\Transformation\Effect;
use Cloudinary\Transformation\Resize;

(new ImageTag('docs/woman-sitting.jpg'))
	->effect(Effect::generativeBackgroundReplace()->prompt("an old castle")
->seed(1))
	->resize(Resize::scale()->width(200));
```

```java
cloudinary.url().transformation(new Transformation()
  .effect("gen_background_replace:prompt_an old castle;seed_1").chain()
  .width(200).crop("scale")).imageTag("docs/woman-sitting.jpg");
```

```ruby
cl_image_tag("docs/woman-sitting.jpg", transformation: [
  {effect: "gen_background_replace:prompt_an old castle;seed_1"},
  {width: 200, crop: "scale"}
  ])
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Effect("gen_background_replace:prompt_an old castle;seed_1").Chain()
  .Width(200).Crop("scale")).BuildImageTag("docs/woman-sitting.jpg")
```

```dart
cloudinary.image('docs/woman-sitting.jpg').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace().prompt("an old castle")
.seed(1))
	.resize(Resize.scale().width(200)));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
  .setEffect("gen_background_replace:prompt_an old castle;seed_1").chain()
  .setWidth(200).setCrop("scale")).generate("docs/woman-sitting.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation()
  .effect("gen_background_replace:prompt_an old castle;seed_1").chain()
  .width(200).crop("scale")).generate("docs/woman-sitting.jpg");
```

```flutter
cloudinary.image('docs/woman-sitting.jpg').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace().prompt("an old castle")
.seed(1))
	.resize(Resize.scale().width(200)));
```

```kotlin
cloudinary.image {
	publicId("docs/woman-sitting.jpg")
	 effect(Effect.generativeBackgroundReplace() { prompt("an old castle")
 seed(1) })
	 resize(Resize.scale() { width(200) }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/woman-sitting.jpg", {transformation: [
  {effect: "gen_background_replace:prompt_an old castle;seed_1"},
  {width: 200, crop: "scale"}
  ]})
```

```react_native
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";
import { scale } from "@cloudinary/url-gen/actions/resize";

new CloudinaryImage("docs/woman-sitting.jpg")
  .effect(generativeBackgroundReplace().prompt("an old castle").seed(1))
  .resize(scale().width(200));
```

## Replace transparent backgrounds 

In this next example, the transparent background of the original image is replaced to give context to the motorbike (`e_gen_background_replace:prompt_a%20deserted%20street`):

![Background replaced with a deserted street](https://res.cloudinary.com/demo/image/upload/e_gen_background_replace:prompt_a%20deserted%20street/docs/motorbike.png "with_image:false")

```nodejs
cloudinary.image("docs/motorbike.png", {effect: "gen_background_replace:prompt_a deserted street"})
```

```react
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/motorbike.png").effect(
  generativeBackgroundReplace().prompt("a deserted street")
);
```

```vue
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/motorbike.png").effect(
  generativeBackgroundReplace().prompt("a deserted street")
);
```

```angular
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/motorbike.png").effect(
  generativeBackgroundReplace().prompt("a deserted street")
);
```

```js
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/motorbike.png").effect(
  generativeBackgroundReplace().prompt("a deserted street")
);
```

```python
CloudinaryImage("docs/motorbike.png").image(effect="gen_background_replace:prompt_a deserted street")
```

```php
use Cloudinary\Transformation\Effect;

(new ImageTag('docs/motorbike.png'))
	->effect(Effect::generativeBackgroundReplace()->prompt("a deserted street"));
```

```java
cloudinary.url().transformation(new Transformation().effect("gen_background_replace:prompt_a deserted street")).imageTag("docs/motorbike.png");
```

```ruby
cl_image_tag("docs/motorbike.png", effect: "gen_background_replace:prompt_a deserted street")
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation().Effect("gen_background_replace:prompt_a deserted street")).BuildImageTag("docs/motorbike.png")
```

```dart
cloudinary.image('docs/motorbike.png').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace().prompt("a deserted street")));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setEffect("gen_background_replace:prompt_a deserted street")).generate("docs/motorbike.png")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation().effect("gen_background_replace:prompt_a deserted street")).generate("docs/motorbike.png");
```

```flutter
cloudinary.image('docs/motorbike.png').transformation(Transformation()
	.effect(Effect.generativeBackgroundReplace().prompt("a deserted street")));
```

```kotlin
cloudinary.image {
	publicId("docs/motorbike.png")
	 effect(Effect.generativeBackgroundReplace() { prompt("a deserted street") }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/motorbike.png", {effect: "gen_background_replace:prompt_a deserted street"})
```

```react_native
import { generativeBackgroundReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/motorbike.png").effect(
  generativeBackgroundReplace().prompt("a deserted street")
);
```

Original image

Replace the background

## Limitations
* The use of generative AI means that results may not be 100% accurate.
* There's a [special transformation count](transformation_counts#special_effect_calculations) for the generative background replace effect.
* If you get blurred results when using this feature, it's likely that the built-in NSFW (Not Safe For Work) check has detected something inappropriate. You can [contact support](https://support.cloudinary.com/hc/en-us/requests/new) to disable this check if you believe it's too sensitive.
* The generative background replace effect isn't supported for [animated](animated_images) images or [fetched](fetch_remote_images#fetch_and_deliver_remote_files) images.
* When Cloudinary is generating a derived version, you may get a 423 response returned until the version is ready. You can prepare derived versions in advance using an [eager transformation](eager_and_incoming_transformations#eager_transformations).
* When Cloudinary is generating an [incoming transformation](eager_and_incoming_transformations#incoming_transformations), you may get a 420 response returned, with status `pending` until the asset is ready.
* If you're using our [Asia Pacific data center](admin_api#alternative_data_centers_and_endpoints_premium_feature), you currently can't apply the generative background replace effect.
