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. Results are kept for up to 1 hour.

  • 0: Returns a task_id asynchronously. Use the task_id to retrieve the result later.
  • 1: Waits for processing to complete and returns the result synchronously.
type string optional

Foreground type. If omitted, the foreground is detected automatically (default).

  • person: People;
  • object: Objects;
  • stamp: Stamps.
return_type number optional

Result return format.

  • 1: Image download URL;
  • 2: Base64-encoded string;
  • 3: Binary stream (available for synchronous requests only).
output_type number optional

Result image option.

  • 1: Image and mask;
  • 2: Image only (default);
  • 3: 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: Transparent-background image (default);
  • jpg: White-background image. Use with bg_color to set the background color.
bg_color string optional

Adds a solid color background using a hex color value, such as 81d4fa or ffffff. This parameter is effective only when format=jpg. If it is used, ensure the 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 its aspect ratio; excess edges are cropped. Limits: file size up to 20MB and resolution up to 4K. If this parameter is used, ensure the 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 its aspect ratio; excess edges are cropped. Limits: file size up to 20MB and resolution up to 4K. If this parameter is used, ensure the other bg_ parameters are empty.

Return Parameters

status number

HTTP response status code. See Status Code Definitions.

  • 200: Request succeeded;
  • non-200: Request failed.
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. See Status Code Definitions.

  • 200: Request succeeded;
  • non-200: Request failed.
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: Processing is complete.
data.state number

Task status code. See Status Code Definitions.

  • 1: Succeeded;
  • > 1: Processing;
  • < 0: Failed.

Query background removal result

For asynchronous requests, poll the result once every 1 second. The maximum polling duration for this API is 60 seconds; if the total polling time exceeds this without a result, treat it as a timeout failure.

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. See Status Code Definitions.

  • 200: Request succeeded;
  • non-200: Request failed.
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: Processing is complete.
data.state number

Task status code. See Status Code Definitions.

  • 1: Succeeded;
  • > 1: Processing;
  • < 0: Failed.

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