Background Removal API Documentation

Description

This cloud API uses intelligent salient object detection (SOD) for automated, high-precision background removal. Keep source images under 5 MB for optimal speed.

🥥 Important Notes

Data Retention: Output image URLs and alpha mattes (masks) are valid for 1 day only. Download and store them promptly.
Rate Limits: The default limit is 2 QPS. Contact sales or business development for higher concurrency.

Version History

4.0 | Release Date: 2025-03-20
4.0.1 | Release Date: 2026-07-01 (Added support for multi-result outputs)

Input Image Requirements

Image FormatResolutionFile Size
jpg, jpeg, bmp, png, webp, bitmap, avif, tiff, heic, heifInteger between [4096~4096]Up to 10MB (inclusive)

🥥 Important Notes

Output URLs expire after 24 hours.
Default rate limit is 2 QPS. Contact us to upgrade concurrency limits.

Request URL

🥥 https://coco-openapi.yezisheji.com/api/v1/segment/submit
https://coco-openapi.yezisheji.com/api/v1/segment/task_info

Request Methods & Examples

# Create Task
Plain Text|
curl -k 'https://coco-openapi.yezisheji.com/api/v1/segment/submit' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'sync=1' \
-F 'image_file=@/path/of/image.jpg'
# Fetch Task
Plain Text|
curl -k 'https://coco-openapi.yezisheji.com/api/v1/segment/task_info' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'task_id={YOUR_TASK_ID}'

Authentication & Permissions

Request an API Key before using these services. Contact business development or sales for details.
API Authentication: Pass your secret token via the HTTP Header and store your API Key securely.

Construct Request

1、Image Background Removal

POST /api/v1/segment/submit

Request Parameters:

Parameter NameTypeDefault ValueOptional ValuesDescription
image_urlStringNone-URL of the image to remove the background from (mutually exclusive with image_file).
image_fileString($binary)None-Local image file (mutually exclusive with image_url).
rsz_wintNoneInteger between [0~4096]If greater than 0, scale the returned image proportionally to rsz_w.
rsz_hintNoneInteger between [0~4096]If greater than 0, scale the returned image proportionally to rsz_h.
crop_objectintNone0、1Set to 1 to crop to the main subject area.
multi_resultintNone0、1Whether to return multiple matting results. Billing is based on returned result count, normally no more than 5.
syncint00、10 returns task_id immediately for later task_info polling; 1 waits for completion and returns the result.
output_typeint11、2、3Return image and mask results.
1 Image only.

2 Image and mask.

3 Mask only.
output_formatStringpngjpeg、pngReturned image format.
png: transparent background.

jpeg: white background by default; use bg_color for another color.
bg_colorStringNoneHexadecimal color string starting with "#"Solid background color, effective only when output_format is jpeg. Examples: "#FFFFFF", "#000000".
output_mask_formatStringjpegjpeg、pngReturned mask image format.
timeoutint101-60API processing wait timeout in seconds, effective only when sync=1.

Note: Setting both rsz_w and rsz_h scales to those dimensions without preserving aspect ratio. crop_object also does not preserve the original aspect ratio.

# Example Response for Async Mode (sync=0)
JSON|
{
    "data": {
        "task_id": "67fcadf7b3b99f4447f9ddce"
    },
    "status": 200,
    "timestamp": 1744512855,
    "trace_id": "ae173819-6fb5-4e88-a587-ff654f2de9bf",
    "message": "ok"
}
# Example Response for Sync Mode (sync=1)
JSON|
{
    "data": {
        "created_at": 1744513021,
        "completed_at": 1744513022,
        "image": "{image oss url}",
        "mask": "{mask oss url}"
    },
    "status": 200,
    "timestamp": 1744513022,
    "trace_id": "3a2a0b4a-8b4a-4034-865a-8a5ebcc7e93c",
    "message": "ok"
}

2、Image Background Removal

POST /api/v1/segment/submit

Request Parameters:

# Example Response for Async Mode (sync=0)
JSON|
{
    "data": {
        "task_id": "67fcaec66b4a4af9c824fcd2",
        "created_at": 1744513062,
        "completed_at": 1744513063,
        "status": 2,
        "mask": "{mask oss url}",
        "image": "{image oss url}",
        "result_cnt": 2,
        "results": [
            {
                "task_id": "{task_id_1}",
                "created_at": 1744513062,
                "completed_at": 1744513063,
                "status": 2,
                "mask": "{mask oss url}",
                "image": "{image oss url}"
            },
            {
                "task_id": "{task_id_2}",
                "created_at": 1744513062,
                "completed_at": 1744513063,
                "status": 2,
                "mask": "{mask oss url}",
                "image": "{image oss url}"
            }
        ]
    },
    "status": 200,
    "timestamp": 1744513180,
    "trace_id": "952a636e-3a9d-4e72-b470-681c61fcd763",
    "message": "ok"
}
Parameter NameTypeDescription
result_cntNumberNumber of results returned when multi_result=1
Parameter NameTypeDefault ValueOptional ValuesDescription
task_idStringNoneValid Task IDtask_id returned by the background removal API, for async mode with sync=0.

3、Usage Quota Inquiry

GET /api/v1/segment/quota

Request Parameters: None

# Example Response
Plain Text|
{
    "data": {
        "used_tasks": 888,
        "remaining_tasks": 88888
    },
    "status": 200,
    "timestamp": 1778555905,
    "trace_id": "b9d83cd6-f220-436f-ac30-52fcd8d5b30a",
    "message": "ok"
}

Response Parameters

Parameter NameTypeDescription
imageStringURL of the image after background removal
maskString($binary)URL of the mask image
resultsArrayResult array when multi_result=1
result_cntNumberNumber of results returned when multi_result=1
statusStringdata.status task status:
2 Completed

1 Processing

-1 Failed

-2 Timed out
used_tasksNumberNumber of matting tasks used
remaining_tasksNumberNumber of remaining available matting tasks

Status Codes

HTTP Response Status Codes

HTTP Response Status CodeDescription
200Request successful.
400Client parameter error. Check missing or invalid values.
401Authentication failed. Check X-API-KEY and service activation.
404Requested URL or resource does not exist.
412Uploaded image URL or file validation failed.
413Uploaded file exceeds the size limit.
429Request frequency exceeds the QPS limit. Slow down or contact business support.
500Server exception. Contact business or technical support.