Skip to main content
Replace background finds the background of an image and redraws it from a prompt. Generate background does the same for an area you mark with a mask.

$0.04 / $0.08

per image, raster / vector

Image + prompt → image

up to 10 MB, 16 MP

POST /v1/images/replaceBackground

endpoint, mask variant below

Try it

Get an API token on your profile page (it needs a positive API units balance) and set it once per terminal session:
Then run. The request replaces the background of a public sample illustration:

Response

Both operations return the same result.
  • data has one entry per image (n). Download each image from its url. With recraftv3_vector, each url points to an SVG file.
  • Image URLs are temporary: files are kept for about 24 hours, so download them. See Limits and sizes.
  • credits is the number of API units charged for the request.

Parameters

Parameters of POST /v1/images/replaceBackground:
The input image must be PNG, JPG, WEBP, or SVG, under 10 MB, up to 16 MP, with sides between 256 and 4096 px. See Input images.

Generate background

POST /v1/images/generateBackground works like replace background, but you mark the background with a mask instead of letting the model find it. Use it when you want to control exactly which area is regenerated. The request below uses the sample image and a sample mask that is white over the background and black over the motorcycle and rider, so only the background is generated.

Request parameters

The mask is a grayscale image (PNG, JPG, or WEBP) of exactly the same size as the image. Pure white pixels (255) are regenerated and pure black pixels (0) stay unchanged. Every pixel must be one of the two. model, n, style, style_id, style_match, negative_prompt, text_layout, controls, response_format, and image_format work as in the table above. The image limits are the same.

Examples

For generate background, upload the mask next to the image.
recraftv3_vector returns SVG instead of a raster image. It costs $0.08 per image, for both operations.

Inpainting

Regenerate any masked area, not only the background.

Outpainting

Extend an image beyond its borders.

Recraft V3

The model line behind background operations.

Pricing

Prices of every model and tool.