Remove selected objects using a source image and a mask of the area to remove.
Result image URLs are generally valid for 1 hour. Please download and store them 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 an advanced objects removal task
/api/tasks/visual/external/image-inpainting Body Parameters
image_url string optional Source image URL. Provide at least one of image_url or image_file; image_file takes precedence when both are supplied.
image_file file optional Source image file as binary data. Provide at least one of image_file or image_url; image_file takes precedence when both are supplied.
For image upload requirements, see Guidelines and Limits #7.
mask_url string optional Mask image URL specifying the area to remove. Provide either mask_url or mask_file.
mask_file file optional Mask image file as binary data specifying the area to remove. Provide either mask_file or mask_url.
provider integer optional Processing route:
1: Route 1 (default)2: Route 2
Return Parameters
status integer HTTP response status code. 200 means the request succeeded, not that image processing succeeded. See Status Code Definitions.
message string Response message. Include the error message and task_id when contacting support about a failed task.
data.task_id string Task ID used to query the objects removal result.
Query advanced objects removal result
For asynchronous requests, poll the result once every 1 second. The maximum polling duration for this API is 600 seconds; if the total polling time exceeds this without a result, treat it as a timeout failure.
/api/tasks/visual/external/image-inpainting/{task_id} Path Parameters
task_id string required Task ID returned when the objects removal task was created.
Return Parameters
status integer HTTP response status code. 200 means the request succeeded, not that image processing succeeded. See Status Code Definitions.
message string Response message. Include the error message and task_id when contacting support about a failed task.
data.task_id string Task ID used to query the objects removal result.
data.image string Result image URL or base64 data. Result URLs are generally valid for 1 hour.
data.state integer Task state: 0 queued; 1 succeeded; 2 preparing; 3 waiting; 4 processing; < 0 failed. Stop polling on success or failure. See Status Code Definitions.
data.progress integer Task progress from 0 to 100. Check data.state to determine whether processing succeeded.
data.created_at integer Timestamp of task creation.
data.processed_at integer Timestamp when processing started.
data.completed_at integer Timestamp of task completion.
data.time_elapsed string Elapsed processing time.
data.state_detail string Detailed task status.
data.return_type integer Result return method.
data.cost number Cost value returned by the API.
data.use_point integer Credits consumed by this task. Each successful call consumes 6 credits.
Guidelines and Limits
-
Result image URLs are generally valid for 1 hour. Please download and store them promptly.
-
HTTP status 200 only means the request succeeded. data.state = 1 means processing succeeded; data.state < 0 means it failed. Stop polling on either success or failure.
-
Follow URL encoding standards when passing URLs. Preserve all signed URL parameters when downloading results; incorrectly escaping & can invalidate the URL.
-
Both the source and mask must meet the format, size and resolution limits below. Each URL supports HTTP and OSS, up to 512 characters, with a 20-second download timeout.
-
Processing usually takes 1–2 minutes, depending on image size, with a maximum processing time of 10 minutes.
-
The default QPS limit is 2. Contact sales for a higher limit. Each successful call consumes 6 credits.
-
Both source and mask images must meet the following requirements.
Format File size Resolution jpg, jpeg, png (JPEG recommended) Up to 4.7MB per image ≤ 4096 × 4096
# Objects Removal - Advanced API
Remove selected objects using a source image and a mask of the area to remove.
> Result image URLs are generally valid for 1 hour. Please download and store them promptly.
## Base URL
https://techhk.aoscdn.com
## Authentication
Every request must include the X-API-KEY request header.
```http
X-API-KEY: YOUR_API_KEY
```
[Get or manage your API key](https://picwish.com/my-account?subRoute=api-key)
## Request modes
Asynchronous only: create a task, read data.task_id, then poll the query endpoint.
## Source and mask images
Source image URL. Provide at least one of image_url or image_file; image_file takes precedence when both are supplied.
Source image file as binary data. Provide at least one of image_file or image_url; image_file takes precedence when both are supplied.
Mask image URL specifying the area to remove. Provide either mask_url or mask_file.
Mask image file as binary data specifying the area to remove. Provide either mask_file or mask_url.
## Endpoints
| Purpose | Method | Path |
| --- | --- | --- |
| Create an advanced objects removal task | POST | /api/tasks/visual/external/image-inpainting |
| Query advanced objects removal result | GET | /api/tasks/visual/external/image-inpainting/{task_id} |
## Create an advanced objects removal task
`POST /api/tasks/visual/external/image-inpainting`
Content-Type: `multipart/form-data`
### Body Parameters
| Name | Type | Required | Description |
| --- | --- | --- | --- |
| image_url | string | one required | Source image URL. Provide at least one of image_url or image_file; image_file takes precedence when both are supplied. |
| image_file | file | one required | Source image file as binary data. Provide at least one of image_file or image_url; image_file takes precedence when both are supplied. |
| mask_url | string | one required | Mask image URL specifying the area to remove. Provide either mask_url or mask_file. |
| mask_file | file | one required | Mask image file as binary data specifying the area to remove. Provide either mask_file or mask_url. |
| provider | integer | optional | Processing route: 1 = route 1 (default); 2 = route 2. |
### Return Parameters
| Name | Type | Description |
| --- | --- | --- |
| status | integer | HTTP response status code. 200 means the request succeeded, not that image processing succeeded. Non-200 means the request failed. See /states. |
| message | string | Response message. Include the error message and task_id when contacting support about a failed task. |
| data.task_id | string | Task ID used to query the objects removal result. |
### cURL
Using source and mask image URLs:
```bash
curl 'https://techhk.aoscdn.com/api/tasks/visual/external/image-inpainting' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'image_url=YOUR_IMAGE_URL' \
-F 'mask_url=YOUR_MASK_URL' \
-F 'provider=1'
```
Uploading source and mask image files:
```bash
curl 'https://techhk.aoscdn.com/api/tasks/visual/external/image-inpainting' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'image_file=@/path/to/image.jpg' \
-F 'mask_file=@/path/to/mask.png' \
-F 'provider=1'
```
Successful create response:
```json
{
"status": 200,
"message": "ok",
"data": {
"task_id": "94806a3f-1173-4afb-9bcc-3ff19c0981f4"
}
}
```
## Query advanced objects removal result
For asynchronous requests, poll the result once every **1 second**. The maximum polling duration for this API is **600 seconds**; if the total polling time exceeds this without a result, treat it as a timeout failure.
`GET /api/tasks/visual/external/image-inpainting/{task_id}`
### Path Parameters
| Name | Type | Required | Description |
| --- | --- | --- | --- |
| task_id | string | required | Task ID returned when the objects removal task was created. |
### Return Parameters
| Name | Type | Description |
| --- | --- | --- |
| status | integer | HTTP response status code. 200 means the request succeeded, not that image processing succeeded. Non-200 means the request failed. See /states. |
| message | string | Response message. Include the error message and task_id when contacting support about a failed task. |
| data.task_id | string | Task ID used to query the objects removal result. |
| data.image | string | Result image URL or base64 data. Result URLs are generally valid for 1 hour. |
| data.state | integer | Task state: 0 = queued; 1 = succeeded; 2 = preparing; 3 = waiting; 4 = processing; < 0 = failed. Stop polling on success or failure. See /states. |
| data.progress | integer | Task progress from 0 to 100. Check data.state to determine whether processing succeeded. |
| data.created_at | integer | Timestamp of task creation. |
| data.processed_at | integer | Timestamp when processing started. |
| data.completed_at | integer | Timestamp of task completion. |
| data.time_elapsed | string | Elapsed processing time. |
| data.state_detail | string | Detailed task status. |
| data.return_type | integer | Result return method. |
| data.cost | number | Cost value returned by the API. |
| data.use_point | integer | Credits consumed by this task. Each successful call consumes 6 credits. |
### cURL
```bash
curl 'https://techhk.aoscdn.com/api/tasks/visual/external/image-inpainting/{task_id}' \
-H 'X-API-KEY: YOUR_API_KEY'
```
Processing response:
```json
{
"status": 200,
"message": "success",
"data": {
"progress": 21,
"state": 4
}
}
```
Completed response (example):
```json
{
"status": 200,
"data": {
"task_id": "94806a3f-1173-4afb-9bcc-3ff19c0981f4",
"created_at": 1789541552,
"processed_at": 1789541552,
"completed_at": 1789541563,
"image": "YOUR_RESULT_IMAGE_URL",
"progress": 100,
"state": 1,
"state_detail": "Complete",
"return_type": 2,
"cost": 0,
"use_point": 6
}
}
```
Failed task response:
```json
{
"status": 200,
"message": "success",
"data": {
"task_id": "94806a3f-1173-4afb-9bcc-3ff19c0981f4",
"progress": 0,
"state": -1
}
}
```
Failed request response:
```json
{
"status": 401,
"message": "Invalid API key"
}
```
## Recommended asynchronous flow
1. POST a task with a source image (image_url or image_file) and a mask (mask_url or mask_file), then read data.task_id.
2. GET the task result every 1 second, for no more than 600 seconds in total.
3. When data.state = 1, read data.image. When data.state < 0, the task failed. Stop polling in either case; continue for other states.
4. Download and store the result promptly; result URLs are generally valid for 1 hour.
## Guidelines and Limits
- Result image URLs are generally valid for 1 hour. Please download and store them promptly.
- HTTP status 200 only means the request succeeded. data.state = 1 means processing succeeded; data.state < 0 means it failed. Stop polling on either success or failure.
- Follow URL encoding standards when passing URLs. Preserve all signed URL parameters when downloading results; incorrectly escaping & can invalidate the URL.
- Both the source and mask must meet the format, size and resolution limits below. Each URL supports HTTP and OSS, up to 512 characters, with a 20-second download timeout.
- Processing usually takes 1–2 minutes, depending on image size, with a maximum processing time of 10 minutes.
- The default QPS limit is 2. Contact sales for a higher limit. Each successful call consumes 6 credits.
- Both source and mask images must meet the following requirements.
| Format | File size | Resolution |
| --- | --- | --- |
| jpg, jpeg, png (JPEG recommended) | Up to 4.7MB per image | ≤ 4096 × 4096 |
## Status codes
Determine success by combining the HTTP response status code (`status`) with the task status code (`data.state`).
### HTTP response status codes
| Code | Meaning |
| --- | --- |
| 200 | The request is successful. |
| 400 | Wrong parameter passed by the client. Check whether a parameter is missing or has an incorrect value. |
| 401 | Unauthorized API key. Check that X-API-KEY is correct and the service is enabled. |
| 404 | The requested URL or resource does not exist. Check that the URL or task_id is correct. |
| 413 | The uploaded file exceeds the allowed size. Refer to the supported image size. |
| 429 | Request frequency exceeds the QPS limit (default QPS is 2). Slow down or contact us to raise your QPS. |
| 500 | Server-side exception. Please contact support. |
### Task status codes (data.state)
1 = succeeded; greater than 1 = still processing; less than 0 = failed.
| Code | Meaning |
| --- | --- |
| -17 | Processing failed because the prompt is invalid. |
| -16 | Processing failed because a third-party review detected prohibited content. |
| -15 | Processing failed due to insufficient resources. |
| -14 | Processing failed because the input image content does not meet the requirements. |
| -13 | Processing failed because the task was canceled due to an exception. |
| -11 | Processing failed because the result is empty. |
| -10 | Processing failed because internal review detected prohibited content. |
| -9 | Processing failed because the internal program failed during loop processing. |
| -8 | Processing timed out. The maximum processing time is 600 seconds. |
| -7 | Invalid image file (e.g. corrupted image or incorrect format). |
| -5 | The image_url image exceeds the size limit (4.7MB). |
| -3 | The server failed to download your file. Check that the source image URL is available. |
| -2 | Processing completed, but uploading the result to OSS failed. |
| -1 | Processing failed. |
| 0 | Queued. The task is waiting in the queue. |
| 1 | Completed. Processing succeeded. |
| 2 | Preparing. |
| 3 | Waiting. |
| 4 | Processing in progress. |
| 5 | Internally publishing the result. |
| 6 | Processing. Internal loop processing is in progress. |