# Bria Background Replace > Keep the foreground subject of a photo and generate a brand-new background from a text prompt (or match a reference image), with commercially safe outputs. ## Overview - **Endpoint**: `https://queue.modelrunner.run/bria/background/replace` - **Model ID**: `bria/background/replace` - **Category**: image-to-image - **Kind**: inference - **Tags**: bria, background-replacement, background-replace, background-generation, image-editing, image-to-image ## Pricing - **Price**: $0.04 per output ## Request Lifecycle This model runs on the ModelRunner **asynchronous queue API** — a single POST does not return the output. Every call requires an `Authorization: Key $MODEL_RUNNER_KEY` header. Run three steps: 1. **Submit** — `POST https://queue.modelrunner.run/bria/background/replace` with a JSON body holding the input fields at the top level. The body may also include a reserved top-level `metadata` object — a flat string map (max 16 keys, key ≤64 / value ≤512 chars) stored on the request for your own tagging. It is never sent to the model; filter your request history with `GET https://queue.modelrunner.run/requests?metadata=` (exact key=value matches, AND-ed). The response carries request handles only (no output yet): ```json { "status": "IN_QUEUE", "request_id": "<21-char id>", "status_url": "https://queue.modelrunner.run/bria/background/replace/requests//status", "response_url": "https://queue.modelrunner.run/bria/background/replace/requests/", "cancel_url": "https://queue.modelrunner.run/bria/background/replace/requests//cancel" } ``` 2. **Poll status** — `GET ` until `status` is `COMPLETED`. Possible values are `IN_QUEUE`, `IN_PROGRESS`, `COMPLETED`, `FAILED`, `CANCELLED`. A `FAILED` request responds with HTTP 400 and an `error` field. 3. **Read result** — `GET `. Returns the finished request, including the generated `output`: ```json { "id": "", "status": "COMPLETED", "output": ..., "input": ... } ``` The JavaScript and Python SDKs below perform steps 2–3 for you. In any language without an SDK (Swift, Go, Kotlin, etc.) you must implement the polling loop and the final result fetch yourself — see the cURL example for the full flow. ### Input Schema - **`fast`** (`boolean`, _optional_): Trade some quality for faster generation. Turn off for maximum quality. - Default: `true` - **`seed`** (`integer | null`, _optional_): Seed for reproducible generation. Leave unset for a random result. - **`prompt`** (`string | null`, _optional_): Describes the new background to generate behind the subject (e.g. 'a sunlit modern living room'). Provide either a non-empty prompt OR a ref_image_url reference image — not both. - **`image_url`** (`string`, _required_): The source photo whose foreground subject is preserved while a new background is generated around it. The output keeps the input's dimensions. - **`num_images`** (`integer`, _optional_): The number of images to generate. Each generated image is billed. - Default: `1` - Range: `1` to `4` - **`ref_image_url`** (`string`, _optional_): Optional reference image whose background style and colors the model matches instead of using a text prompt. Provide either ref_image_url OR a prompt — not both. - Default: `""` - **`refine_prompt`** (`boolean`, _optional_): Whether to automatically refine the background prompt for better results. - Default: `true` - **`negative_prompt`** (`string`, _optional_): Describes what to avoid in the generated background. - Default: `""` ### Output Schema _No `Output` schema properties are available._ ## Default Example **Input** ```json { "fast": true, "prompt": "in a minimalist Japanese zen garden with raked white gravel, moss-covered stones, and bamboo fencing at dusk", "image_url": "https://media.modelrunner.ai/x1BPEnb19Mdlyq94vWiOa.png", "ref_image_url": "", "refine_prompt": true, "negative_prompt": "" } ``` **Output** ```json [ "https://media.modelrunner.ai/S1Va4L1fRbXpW9IZqTDlL.png" ] ``` ## Usage Examples ### cURL The queue API is asynchronous: submit the request, poll `status_url` until it is `COMPLETED`, then read the result from `response_url`. Requires `jq`. ```bash # 1. Submit the request (returns request handles, not the output) SUBMIT=$(curl --silent --request POST \ --url https://queue.modelrunner.run/bria/background/replace \ --header "Authorization: Key $MODEL_RUNNER_KEY" \ --header "Content-Type: application/json" \ --data '{ "fast": true, "prompt": "in a minimalist Japanese zen garden with raked white gravel, moss-covered stones, and bamboo fencing at dusk", "image_url": "https://media.modelrunner.ai/x1BPEnb19Mdlyq94vWiOa.png", "ref_image_url": "", "refine_prompt": true, "negative_prompt": "" }') STATUS_URL=$(echo "$SUBMIT" | jq -r '.status_url') RESPONSE_URL=$(echo "$SUBMIT" | jq -r '.response_url') # 2. Poll until the request leaves the queue / in-progress state while true; do STATUS=$(curl --silent --url "$STATUS_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" | jq -r '.status') echo "Status: $STATUS" case "$STATUS" in COMPLETED) break ;; FAILED|CANCELLED) echo "Request $STATUS"; exit 1 ;; esac sleep 1 done # 3. Read the finished request, including the generated output curl --silent --url "$RESPONSE_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" ``` ### JavaScript ```javascript import { modelrunner } from "@modelrunner/client"; const result = await modelrunner.subscribe("bria/background/replace", { input: { "fast": true, "prompt": "in a minimalist Japanese zen garden with raked white gravel, moss-covered stones, and bamboo fencing at dusk", "image_url": "https://media.modelrunner.ai/x1BPEnb19Mdlyq94vWiOa.png", "ref_image_url": "", "refine_prompt": true, "negative_prompt": "" } }); console.log(result.data); ``` ### Python ```python import asyncio import modelrunner_ai async def main(): response = await modelrunner_ai.submit_async( "bria/background/replace", arguments={ "fast": true, "prompt": "in a minimalist Japanese zen garden with raked white gravel, moss-covered stones, and bamboo fencing at dusk", "image_url": "https://media.modelrunner.ai/x1BPEnb19Mdlyq94vWiOa.png", "ref_image_url": "", "refine_prompt": true, "negative_prompt": "" } ) result = await response.get() print(result["output"]) asyncio.run(main()) ``` ## Additional Resources - [Playground](https://modelrunner.ai/models/bria/background/replace) - [OpenAPI Schema](https://modelrunner.ai/models/bria/background/replace/openapi.json) - [LLM Instructions](https://modelrunner.ai/models/bria/background/replace/llms.txt)