> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runflow.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Background Replace

> Swap the background of any product photo for a new scene defined by a reference image and a short prompt. The model preserves the foreground subject while matching camera angle and lighting to the new background.

<Info>
  Pricing: **\$0.35/request**. Endpoint: `POST /v1/models/runflow/background-replace/runs`.
</Info>

Swap the background of any product photo for a new scene defined by a reference image and a short prompt. The model preserves the foreground subject while matching camera angle and lighting to the new background.

## Overview

* **Endpoint**: [https://api.runflow.io/v1/models/runflow/background-replace/runs](https://api.runflow.io/v1/models/runflow/background-replace/runs)
* **Model ID**: runflow/background-replace
* **Provider**: Runflow
* **Last Updated**: 2026-05-06

## Pricing

* **Base price**: \$0.35/request
* **Note**: Per image - background replace

# Background Replace API

**Endpoint:** `POST /v1/models/runflow/background-replace/runs`

## Run the model

### Python

```python theme={"dark"}
import requests

response = requests.post(
    "https://api.runflow.io/v1/models/runflow/background-replace/runs",
    headers={"Authorization": "Bearer RUNFLOW_API_KEY"},
    json={
        "input": {
            "prompt": "Replace the white area on Image 1 with Image 2 as the background. Keep the perfume bottle perfectly intact and match the soft window light from Image 2.",
            "zip_url": "https://public.runflow.io/images/models/runflow/background-replace/examples/01-perfume-bottle-marble-counter/inputs.zip",
            "file_image": "image.webp",
            "file_reference": "reference.webp"
        },
        "callback_url": "https://your-server.com/webhook"
    },
)

data = response.json()
print(data)
```

### Node.js

```javascript theme={"dark"}
const response = await fetch(
  "https://api.runflow.io/v1/models/runflow/background-replace/runs",
  {
    method: "POST",
    headers: {
      "Authorization": "Bearer RUNFLOW_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
        "input": {
            "prompt": "Replace the white area on Image 1 with Image 2 as the background. Keep the perfume bottle perfectly intact and match the soft window light from Image 2.",
            "zip_url": "https://public.runflow.io/images/models/runflow/background-replace/examples/01-perfume-bottle-marble-counter/inputs.zip",
            "file_image": "image.webp",
            "file_reference": "reference.webp"
        },
        "callback_url": "https://your-server.com/webhook"
    }),
  }
);

const data = await response.json();
console.log(data);
```

### cURL

```bash theme={"dark"}
curl -X POST https://api.runflow.io/v1/models/runflow/background-replace/runs \
  -H "Authorization: Bearer $RUNFLOW_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
    "input": {
        "prompt": "Replace the white area on Image 1 with Image 2 as the background. Keep the perfume bottle perfectly intact and match the soft window light from Image 2.",
        "zip_url": "https://public.runflow.io/images/models/runflow/background-replace/examples/01-perfume-bottle-marble-counter/inputs.zip",
        "file_image": "image.webp",
        "file_reference": "reference.webp"
    },
    "callback_url": "https://your-server.com/webhook"
}
JSON
```

## Request parameters

| Parameter      | Type           | Required | Description                                                 |
| -------------- | -------------- | -------- | ----------------------------------------------------------- |
| `input`        | object         | required | Model input parameters. See "Input schema" below.           |
| `callback_url` | string \| null | optional | Webhook URL - POSTed when the run reaches a terminal state. |
| `metadata`     | object \| null | optional | Arbitrary key-value pairs attached to the run.              |

## Input schema

| Field            | Type   | Required | Allowed values | Description                                                                                                                                                                        |
| ---------------- | ------ | -------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `zip_url`        | file   | required | Any            | URL of a zip archive containing the foreground photo and the background reference image. Set file\_image and file\_reference to the filenames inside the zip.                      |
| `file_image`     | string | required | Any            | Filename of the foreground/product photo inside the zip (e.g. `image.png`). The model keeps this subject and replaces only the background.                                         |
| `file_reference` | string | required | Any            | Filename of the background reference image inside the zip (e.g. `reference.png`). The model uses it as the new scene behind the foreground.                                        |
| `prompt`         | string | optional | Any            | Optional override for the scene description. Leave empty to use the default: replace the white area on Image 1 with Image 2 as the background, matching camera angle and lighting. |

## Output schema

| Field        | Type        | Description                     |
| ------------ | ----------- | ------------------------------- |
| `image_urls` | image\_list | Background-replaced image URLs. |

## Callback payload

When you provide a `callback_url`, Runflow POSTs to it once the run reaches a terminal state.

| Field          | Type           | Description                                                    |
| -------------- | -------------- | -------------------------------------------------------------- |
| `event`        | string         | Event type: "run.completed", "run.failed", or "run.cancelled". |
| `run_id`       | string         | The unique identifier of the run.                              |
| `status`       | string         | Terminal status: "succeeded", "failed", or "cancelled".        |
| `output`       | object \| null | The run output. Null if the run failed or was cancelled.       |
| `duration_ms`  | number \| null | Total run duration in milliseconds.                            |
| `created_at`   | string \| null | ISO 8601 timestamp when the run was created.                   |
| `completed_at` | string \| null | ISO 8601 timestamp when the run reached terminal state.        |
| `metadata`     | object \| null | The metadata object passed at run creation, if any.            |

* **Retries:** 3 attempts with exponential backoff (1s, 2s). Retries on 5xx / network errors only.
* **Headers:** `Runflow-Request-Id` is always sent. `Runflow-Signature` is sent if a signing secret is configured.

## Additional Resources

* [Playground](https://app.runflow.io/models/runflow/background-replace)
* [API Reference](https://app.runflow.io/models/runflow/background-replace?tab=api)
* [Documentation](https://docs.runflow.io)
* [OpenAPI](https://docs.runflow.io/api/openapi.public.json)

## Related

<CardGroup cols={2}>
  <Card title="Browse all models" icon="grid" href="/models">Browse the catalog.</Card>
  <Card title="Run lifecycle" icon="play" href="/concepts/runs">Callbacks, polling, statuses.</Card>
  <Card title="Callbacks" icon="webhook" href="/concepts/callbacks">Handle async results.</Card>
  <Card title="Pricing" icon="coin" href="/concepts/pricing">How requests bill out.</Card>
</CardGroup>
