Skip to main content

AILabTools API - Human background removal - API

Request

  • URL: https://www.ailabapi.com/api/cutout/portrait/portrait-background-removal
  • Method: POST
  • Content-Type: multipart/form-data

Image requirements

  • Image format: JPEG JPG BMP WEBP PNG(8-bit, 16-bit, 64-bit PNG not supported)
  • Image size: No more than 3 MB.
  • Image resolution: Less than 2000x2000px.

Headers

FieldRequiredTypeDescription
ailabapi-api-keyYESstringApplication API KEY. Get API KEY

Body

FieldRequiredTypeScopeDescription
imageYESfile
return_formNOstring
  • mask
  • whiteBK
  • crop
  • Specifies the form of the returned image.
  • If not set, the four-channel PNG map is returned.
  • mask: Returns a single channel mask.
  • whiteBK: Return to white background image.
  • crop: Returns the four-channel PNG image after cropping (cropping out the blank areas around the edges).
  • Response

    Response Field Handling Flow
    1. Handle Public Response Fields

      Parse and validate the Public Response Fields, checking the status code or response message to ensure the request is successful and error-free.

    2. Handle Business Response Fields

      If the Public Response Fields are valid and error-free, proceed with processing the business logic in the Business Response Fields.

    Public Response Fields

    Viewing Public Response Fields and Error Codes

    Business Response Fields

    FieldTypeDescription
    dataobjectThe content of the result data returned.
    +image_urlstringResulting image URL address.
    tip

    The URL address is a temporary address, valid for 24 hours, and will not be accessible after it expires. If you need to save the file for a long time or permanently, please visit the URL address within 24 hours and download the file to your own storage space.

    Response Example

    {
    "request_id": "",
    "log_id": "",
    "error_code": 0,
    "error_code_str": "",
    "error_msg": "",
    "error_detail": {
    "status_code": 200,
    "code": "",
    "code_message": "",
    "message": ""
    },
    "data": {
    "image_url": ""
    }
    }

    Sample Code

    If you'd like to see the actual effects, please visit the experience page for a trial.