Task: Image Cutout
Short description: Use the image cutout API to extract the foreground and return the processed image or mask.
Overview
- Method:
POST - Path:
/task/pic/segmentation - Content-Type:
multipart/form-data
Authentication
- Header:
Authorization: Bearer <token>
Request Example
Form Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| image_file | file | No | Source image file (binary), mutually exclusive with image_url |
| image_url | string | No | Source image URL, mutually exclusive with image_file |
| sync | integer | No | Whether to wait for the result: 0=async (default), 1=sync |
| type | string | No | Foreground type: person, object, stamp; leave blank for auto-detection |
| output_type | integer | No | Return type: 1=image+mask, 2=image only, 3=mask only; default 2 |
| crop | integer | No | Whether to crop to the target bounds: 0=original size, 1=crop |
| format | string | No | Image format: png=transparent, jpg=white background; default png |
| bg_color | string | No | JPG background color in hex, e.g. ffffff |
| callback_url | string | No | Callback URL for notifications |
curl Example
bash
curl -X POST "https://api.gpt.ge/task/pic/segmentation" \
-H "Authorization: Bearer sk-xxxx" \
-F "image_url=https://example.com/image.png" \
-F "sync=1" \
-F "output_type=2" \
-F "format=png"JavaScript (fetch) Example
javascript
const formData = new FormData();
formData.append('image_url', 'https://example.com/image.png');
formData.append('sync', '1');
formData.append('output_type', '2');
formData.append('format', 'png');
fetch('https://api.gpt.ge/task/pic/segmentation', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk-xxxx'
},
body: formData
}).then(r => r.json()).then(console.log);Python (requests) Example
python
import requests
url = 'https://api.gpt.ge/task/pic/segmentation'
headers = {
'Authorization': 'Bearer sk-xxxx'
}
files = {
'image_url': (None, 'https://example.com/image.png')
}
data = {
'sync': '1',
'output_type': '2',
'format': 'png'
}
response = requests.post(url, headers=headers, files=files, data=data)
print(response.json())Response Example (200)
json
{
"status": 200,
"data": {
"completed_at": 1742670627,
"created_at": 1742670626,
"download_time": 488,
"err_info": "",
"foreground_rect": {
"x": 133,
"y": 110,
"width": 604,
"height": 952
},
"image": "https://wxtechsz.oss-cn-shenzhen.aliyuncs.com/tasks/output/segmentation/3b950563-e53f-4036-a581-5ac04d0829b3-image.png",
"image_height": 1152,
"image_width": 864,
"output_type": 2,
"processed_at": 1742670626,
"progress": 100,
"result_type": "object",
"return_type": 1,
"state": 1,
"state_detail": "Complete",
"task_id": "3b950563-e53f-4036-a581-5ac04d0829b3",
"time_elapsed": 384.54998779296875,
"type": "auto"
}
}Note: This endpoint uses
multipart/form-datato upload the image. Submit eitherimage_urlorimage_file, not both.