Background Removal API

Try on PicWish

AI detects the main subject in an image, removes the background in one step, and outputs a high-quality transparent PNG. It works for ecommerce product photos, portraits, ID photos, and design assets, with async and sync request modes.

The result image URL is valid for 1 hour. Please download and store it promptly.

Authentication

Every API request must include your API Key in the X-API-KEY request header. Send it with each request exactly as shown in the examples and parameter descriptions.

X-API-KEY: YOUR_API_KEY

Create a background removal task

POST /api/tasks/visual/segmentation

Body Parameters

image_url string optional

Source image URL. Use either image_url or image_file. If this parameter is present, the other image source parameters must be empty.

one required
image_file file optional

Source image file as binary data. Use either image_file or image_url. If this parameter is present, the other image source parameters must be empty.

For image upload requirements, see Guidelines and Limits #2.

sync string | number optional

Whether to wait for the result and return it immediately. Use 0 to return a task_id asynchronously, then fetch the result later with the task_id. Use 1 to wait and return the result synchronously. Results are kept for up to 1 hour.

type string optional

Foreground type. Empty value means automatic detection; person uses people as the foreground; object uses products or objects; stamp uses stamps.

return_type number optional

Result return format. 1 returns an image URL; 2 returns a base64-encoded string; 3 returns binary data and is only available for sync requests.

output_type number optional

Result image option. 1 returns both image and mask; 2 returns image only (default); 3 returns mask only.

crop number optional

Whether to crop to the subject edge. 0 keeps the original image size (default); 1 crops to the subject edge.

format string optional

Result image format. png returns a transparent PNG (default); jpg returns a white-background JPG and can be combined with bg_color.

bg_color string optional

Adds a solid color background using a hex color value, such as 81d4fa or ffffff. Only effective when format=jpg. If this parameter is used, ensure other bg_ parameters are empty.

bg_image_file file optional

Adds a custom background image file. The image is centered and scaled to fill the canvas while preserving aspect ratio; excess edges are cropped. Limit: size <= 20MB and resolution <= 4K. If this parameter is used, ensure other bg_ parameters are empty.

bg_image_url string optional

Adds a custom background image URL. The image is centered and scaled to fill the canvas while preserving aspect ratio; excess edges are cropped. Limit: size <= 20MB and resolution <= 4K. If this parameter is used, ensure other bg_ parameters are empty.

Return Parameters

status number

HTTP response status code. 200 means success, and non-200 means failure. See Status Code Definitions.

message string

API response message. Usually success for a successful request.

data.task_id string

Async background removal task ID returned after the task is created. Use it to query the result later.

status number

HTTP response status code. 200 means success, and non-200 means failure. See Status Code Definitions.

message string

API response message. Usually success for a successful request.

data.task_id string

Background removal task ID.

data.created_at string

Task creation time as a Unix timestamp string.

data.processed_at string

Task processing start time as a Unix timestamp string.

data.completed_at string

Task completion time as a Unix timestamp string.

data.image string

Background removal result image URL. Whether it is returned depends on return_type, output_type, format, and related parameters. The URL is valid for 1 hour.

data.mask string

Mask image URL. Returned only when the selected output option includes a mask. The URL is valid for 1 hour.

data.progress number

Task progress. 100 means processing is complete.

data.state number

Task status code. 1 means succeeded, greater than 1 means processing, and less than 0 means failed. See Status Code Definitions.

Query background removal result

GET /api/tasks/visual/segmentation/{task_id}

Path Parameters

task_id string required

Background removal task ID returned after creating an async task. Use it to query the processing result.

Return Parameters

status number

HTTP response status code. 200 means success, and non-200 means failure. See Status Code Definitions.

message string

API response message. Usually success for a successful request.

data.task_id string

Background removal task ID.

data.created_at string

Task creation time as a Unix timestamp string.

data.processed_at string

Task processing start time as a Unix timestamp string.

data.completed_at string

Task completion time as a Unix timestamp string.

data.image string

Background removal result image URL. Whether it is returned depends on return_type, output_type, format, and related parameters. The URL is valid for 1 hour.

data.mask string

Mask image URL. Returned only when the selected output option includes a mask. The URL is valid for 1 hour.

data.progress number

Task progress. 100 means processing is complete.

data.state number

Task status code. 1 means succeeded, greater than 1 means processing, and less than 0 means failed. See Status Code Definitions.

Guidelines and Limits

  1. The result image URL is valid for 1 hour. Please download and store it promptly.

  2. Uploaded images must meet the following format, resolution, and file size limits.

    FormatResolutionSize
    jpg, jpeg, bmp, png, webp, tiff, tif, bitmap, raw, rgb, jfif, lzwUp to 4096 x 4096Up to 20MB