Blur the background of an image while keeping the subject sharp.
Result links are generally valid for 1 hour. 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 a Background Blur Task
/api/tasks/visual/background-blur Body Parameters
image_url string optional Image download URL. Supports HTTP and OSS, up to 512 characters, with a 20-second download timeout.
image_file file optional Image file uploaded as multipart/form-data. The file takes priority if a URL is also supplied.
For image upload requirements, see Guidelines and Limits #2.
sync integer optional Request mode.
0returnsdata.task_idfor polling.1waits for processing and returns the result directly.
bg_blur integer optional Blur strength from 0 to 20, where 0 is the weakest and 20 is the strongest. Defaults to 5.
output_type integer optional Select which images to return.
1returns the blurredimageand the foregroundmask.2returns onlyimage(default).3returns onlymask.
type string optional Foreground type. Omit this field for automatic detection.
personselects people.objectselects objects.stampselects stamps.
Return Parameters
status integer HTTP response status code. 200 indicates a successful request. See Status Code Definitions.
message string Response message, when present.
data.task_id string Task ID used to retrieve async results or troubleshoot a failure.
status integer HTTP response status code. 200 indicates a successful request. See Status Code Definitions.
message string Response message, when present.
data.task_id string Task ID used to retrieve async results or troubleshoot a failure.
data.state integer Task state. 1 indicates success, negative values indicate failure, and 0, 2, 3, or 4 indicate a pending task. See Status Code Definitions.
data.state_detail string Task state details, such as Complete.
data.progress integer Processing progress as a percentage from 0 to 100.
data.image string Download URL or Base64 data for the blurred image. Returned when output_type is 1 or 2.
data.mask string Download URL for the foreground mask. Returned when output_type is 1 or 3.
data.created_at integer Unix timestamp in seconds when the task was created.
data.processed_at integer Unix timestamp in seconds when processing started.
data.completed_at integer Unix timestamp in seconds when processing completed.
Query a Background Blur Result
For asynchronous requests, poll the result once every 1 second. The maximum polling duration for this API is 300 seconds; if the total polling time exceeds this without a result, treat it as a timeout failure. Stop polling when the task succeeds (state = 1) or fails (state < 0).
/api/tasks/visual/background-blur/{task_id} Path Parameters
task_id string required The task ID returned by the async create request.
Return Parameters
status integer HTTP response status code. 200 indicates a successful request. See Status Code Definitions.
message string Response message, when present.
data.task_id string Task ID used to retrieve async results or troubleshoot a failure.
data.state integer Task state. 1 indicates success, negative values indicate failure, and 0, 2, 3, or 4 indicate a pending task. See Status Code Definitions.
data.state_detail string Task state details, such as Complete.
data.progress integer Processing progress as a percentage from 0 to 100.
data.image string Download URL or Base64 data for the blurred image. Returned when output_type is 1 or 2.
data.mask string Download URL for the foreground mask. Returned when output_type is 1 or 3.
data.created_at integer Unix timestamp in seconds when the task was created.
data.processed_at integer Unix timestamp in seconds when processing started.
data.completed_at integer Unix timestamp in seconds when processing completed.
data.time_elapsed string Processing duration.
Guidelines and Limits
-
Each successful call consumes 1 credit.
-
Uploaded images must meet the following format, resolution, and file size limits.
Format Resolution File size JPG, PNG, BMP 20–10,000 px per side Up to 50 MB
# Background Blur API
Blur the background of an image while keeping the subject sharp.
> Result links are generally valid for 1 hour. Download and store them promptly.
## Base URL
`https://techhk.aoscdn.com`
## Authentication
Every request must include your API key in the 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
- `0` returns `data.task_id` for polling.
- `1` waits for processing and returns the result directly.
## Source image
Provide at least one of image_url and image_file. If both are supplied, image_file takes priority.
| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `image_url` | string | one required | Image download URL. Supports HTTP and OSS, up to 512 characters, with a 20-second download timeout. |
| `image_file` | file | one required | Image file uploaded as multipart/form-data. The file takes priority if a URL is also supplied. |
## Endpoints
| Operation | Method | Path |
| --- | --- | --- |
| Create a Background Blur Task | POST | `/api/tasks/visual/background-blur` |
| Query a Background Blur Result | GET | `/api/tasks/visual/background-blur/{task_id}` |
## Create a Background Blur Task
`POST /api/tasks/visual/background-blur`
Content-Type: `multipart/form-data`
### Body Parameters
| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `image_url` | string | one required | Image download URL. Supports HTTP and OSS, up to 512 characters, with a 20-second download timeout. |
| `image_file` | file | one required | Image file uploaded as multipart/form-data. The file takes priority if a URL is also supplied. |
| `sync` | integer | optional | Request mode.<br>`0` returns `data.task_id` for polling.<br>`1` waits for processing and returns the result directly. |
| `bg_blur` | integer | optional | Blur strength from 0 to 20, where 0 is the weakest and 20 is the strongest. Defaults to 5. |
| `output_type` | integer | optional | Select which images to return.<br>`1` returns the blurred `image` and the foreground `mask`.<br>`2` returns only `image` (default).<br>`3` returns only `mask`. |
| `type` | string | optional | Foreground type. Omit this field for automatic detection.<br>`person` selects people.<br>`object` selects objects.<br>`stamp` selects stamps. |
### Return Parameters · Async (sync=0)
| Name | Type | Description |
| --- | --- | --- |
| `status` | integer | HTTP response status code. 200 indicates a successful request. See [Status Code Definitions](https://picwish.com/states). |
| `message` | string | Response message, when present. |
| `data.task_id` | string | Task ID used to retrieve async results or troubleshoot a failure. |
```json
{
"status": 200,
"message": "ok",
"data": {
"task_id": "94806a3f-1173-4afb-9bcc-3ff19c0981f4"
}
}
```
### Return Parameters · Sync (sync=1)
| Name | Type | Description |
| --- | --- | --- |
| `status` | integer | HTTP response status code. 200 indicates a successful request. See [Status Code Definitions](https://picwish.com/states). |
| `message` | string | Response message, when present. |
| `data.task_id` | string | Task ID used to retrieve async results or troubleshoot a failure. |
| `data.state` | integer | Task state. 1 indicates success, negative values indicate failure, and 0, 2, 3, or 4 indicate a pending task. See [Status Code Definitions](https://picwish.com/states). |
| `data.state_detail` | string | Task state details, such as Complete. |
| `data.progress` | integer | Processing progress as a percentage from 0 to 100. |
| `data.image` | string | Download URL or Base64 data for the blurred image. Returned when output_type is 1 or 2. |
| `data.mask` | string | Download URL for the foreground mask. Returned when output_type is 1 or 3. |
| `data.created_at` | integer | Unix timestamp in seconds when the task was created. |
| `data.processed_at` | integer | Unix timestamp in seconds when processing started. |
| `data.completed_at` | integer | Unix timestamp in seconds when processing completed. |
```json
{
"status": 200,
"data": {
"task_id": "94806a3f-1173-4afb-9bcc-3ff19c0981f4",
"created_at": 1736910855,
"processed_at": 1736910856,
"completed_at": 1736910857,
"image": "https://example.com/blurred-image.jpg",
"progress": 100,
"state": 1,
"state_detail": "Complete"
}
}
```
### Request examples
Async · Image URL
```bash
curl -X POST 'https://techhk.aoscdn.com/api/tasks/visual/background-blur' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'sync=0' \
-F 'image_url=YOUR_IMAGE_URL'
```
Async · Local file
```bash
curl -X POST 'https://techhk.aoscdn.com/api/tasks/visual/background-blur' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'sync=0' \
-F 'image_file=@/path/to/image.jpg'
```
Sync · Image URL
```bash
curl -X POST 'https://techhk.aoscdn.com/api/tasks/visual/background-blur' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'sync=1' \
-F 'image_url=YOUR_IMAGE_URL'
```
## Query a Background Blur Result
`GET /api/tasks/visual/background-blur/{task_id}`
### Path Parameters
| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `task_id` | string | required | The task ID returned by the async create request. |
### Return Parameters
| Name | Type | Description |
| --- | --- | --- |
| `status` | integer | HTTP response status code. 200 indicates a successful request. See [Status Code Definitions](https://picwish.com/states). |
| `message` | string | Response message, when present. |
| `data.task_id` | string | Task ID used to retrieve async results or troubleshoot a failure. |
| `data.state` | integer | Task state. 1 indicates success, negative values indicate failure, and 0, 2, 3, or 4 indicate a pending task. See [Status Code Definitions](https://picwish.com/states). |
| `data.state_detail` | string | Task state details, such as Complete. |
| `data.progress` | integer | Processing progress as a percentage from 0 to 100. |
| `data.image` | string | Download URL or Base64 data for the blurred image. Returned when output_type is 1 or 2. |
| `data.mask` | string | Download URL for the foreground mask. Returned when output_type is 1 or 3. |
| `data.created_at` | integer | Unix timestamp in seconds when the task was created. |
| `data.processed_at` | integer | Unix timestamp in seconds when processing started. |
| `data.completed_at` | integer | Unix timestamp in seconds when processing completed. |
| `data.time_elapsed` | string | Processing duration. |
While the task is in progress, its data may contain only progress and state.
```json
{
"status": 200,
"message": "success",
"data": {
"progress": 21,
"state": 4
}
}
```
### Query example
```bash
curl 'https://techhk.aoscdn.com/api/tasks/visual/background-blur/{task_id}' \
-H 'X-API-KEY: YOUR_API_KEY'
```
## Recommended asynchronous flow
1. Create a task with `sync=0` and save `data.task_id` from the response.
2. Query the task by ID and check `data.state` after each request.
3. Download the returned images when the task succeeds.
For asynchronous requests, poll the result once every **1 second**. The maximum polling duration for this API is **300 seconds**; if the total polling time exceeds this without a result, treat it as a timeout failure.
Stop polling when the task succeeds (state = 1) or fails (state < 0).
## Guidelines and Limits
- Each successful call consumes 1 credit.
- Uploaded images must meet the following format, resolution, and file size limits.
| Format | Resolution | File size |
| --- | --- | --- |
| JPG, PNG, BMP | 20–10,000 px per side | Up to 50 MB |
## 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 30 seconds. |
| -7 | Invalid image file (e.g. corrupted image or incorrect format). |
| -5 | The image_url image exceeds the size limit (50MB). |
| -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. |