AI expands an image beyond its original canvas, generating natural background and scene details for the extended area. It supports canvas mode and four-side mode for product photos, portraits, and design materials, with async and sync request modes.
The result image URL is valid for 1 hour. Please download and store it 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 image expansion task
/api/tasks/visual/advanced-image-expand Body Parameters
image_url string optional Source image download URL. One of image_url or image_file is required. Supports HTTP and OSS URLs, up to 512 characters, with a 10-second download timeout. If both image_file and image_url are provided, image_file takes priority.
image_file file optional Source image file as binary data. One of image_file or image_url is required. Only JPG, JPEG, and PNG are supported. The file must be up to 5MB and between 64x64 and 4096x4096. It takes priority over image_url.
For image upload requirements, see Guidelines and Limits #7.
mask_url string optional Mask image URL. Optional. If provided, canvas mode is used. Supports HTTP and OSS URLs, up to 512 characters, with a 10-second download timeout. If both mask_file and mask_url are provided, mask_file takes priority.
mask_file file optional Mask image file as binary data. Optional. If provided, canvas mode is used. It takes priority over mask_url.
The mask must match the image dimensions; see Guidelines and Limits #5.
return_type integer optional Result return type. 1 returns the image download URL (default); 2 returns the image as a Base64 string.
top number optional Top expansion ratio. Default is 0.1. Range: (0, 1].
bottom number optional Bottom expansion ratio. Default is 0.1. Range: (0, 1].
left number optional Left expansion ratio. Default is 0.1. Range: (0, 1].
right number optional Right expansion ratio. Default is 0.1. Range: (0, 1].
strength number optional Source image similarity. Recommended range: [0.1, 1.0]. Smaller values stay closer to the source image, while larger values follow the text prompt more strongly. When set to 0, the result remains almost identical to the source image.
scale number optional Prompt guidance scale. Default is 7.0. Range: [1, 20].
steps integer optional Sampling steps. Default is 30. Higher values may produce finer results, but they also increase processing time significantly.
seed integer optional Random seed. Default is -1. -1 means a random seed is used. If the same positive seed and all other parameters are identical, the generated result is highly likely to be the same.
prompt string optional Prompt used to guide image generation. Chinese and English are both supported. Keep it concise and accurate, ideally within 100 Chinese characters or English words. This field is subject to content review.
sync integer optional Whether to return the result synchronously. Use 0 to return task_id first and poll the query endpoint later; use 1 to return the result directly. We recommend keeping the total polling duration within 180 seconds and polling once every 1 second.
Return Parameters
status number HTTP response status code. 200 means the HTTP request succeeded, not necessarily that image expansion succeeded. See Status Code Definitions.
message string API response message. If the task fails, refer to this field or contact support.
data.task_id string Async image expansion task ID returned after the task is created. Use it to query the result later.
status number HTTP response status code. 200 means the HTTP request succeeded, not necessarily that image expansion succeeded. See Status Code Definitions.
message string API response message. If the task fails, refer to this field or contact support.
data.task_id string Image expansion task ID.
data.created_at string Timestamp of task creation.
data.processed_at string Timestamp when the task started to be processed.
data.completed_at string Timestamp of task completion.
data.download_time number Image download time.
data.image string Result image URL or Base64 data. The URL is valid for 1 hour.
data.image1 string Alternative result image field used in some responses.
data.image_1 string First result image field returned in some responses.
data.image_2 string Second result image field returned in some responses.
data.image_3 string Third result image field returned in some responses.
data.image_4 string Fourth result image field returned in some responses.
data.return_type number Result return type.
data.progress number Task progress percentage, ranging from 0 to 100.
data.state number Task status code. 1 means completed, greater than 1 means processing, and less than 0 means failed. See Status Code Definitions.
data.state_detail string Detailed task state.
data.time_elapsed string Total processing time.
Query image expansion result
/api/tasks/visual/advanced-image-expand/{task_id} Path Parameters
task_id string required Image expansion task ID returned after creating an async task. Use it to query the processing result.
Return Parameters
status number HTTP response status code. 200 means the HTTP request succeeded, not necessarily that image expansion succeeded. See Status Code Definitions.
message string API response message. If the task fails, refer to this field or contact support.
data.task_id string Image expansion task ID.
data.created_at string Timestamp of task creation.
data.processed_at string Timestamp when the task started to be processed.
data.completed_at string Timestamp of task completion.
data.download_time number Image download time.
data.image string Result image URL or Base64 data. The URL is valid for 1 hour.
data.image1 string Alternative result image field used in some responses.
data.image_1 string First result image field returned in some async responses.
data.image_2 string Second result image field returned in some async responses.
data.image_3 string Third result image field returned in some async responses.
data.image_4 string Fourth result image field returned in some async responses.
data.return_type number Result return type.
data.progress number Task progress percentage, ranging from 0 to 100.
data.state number Task status code. 1 means completed, greater than 1 means processing, and less than 0 means failed. See Status Code Definitions.
data.state_detail string Detailed task state.
data.time_elapsed string Total processing time.
Guidelines and Limits
-
The result image URL is valid for 1 hour. Please download and store it promptly.
-
HTTP status 200 indicates that the HTTP request succeeded, not that image expansion succeeded. Determine the task result with data.state. See Status Code Definitions.
-
When passing URLs as parameters, follow URL encoding standards to prevent parameter parsing confusion.
-
If a mask parameter is provided, canvas mode is used. Otherwise, use top, bottom, left, and right to control four-side expansion ratios.
-
The mask image must have the same dimensions as the image.
-
In canvas mode, the image inside the red box is the image input, including the original image and the area to be expanded.
Canvas mode diagram
-
Uploaded images must meet the following format, resolution, and file size limits.
Format Resolution Size jpg, jpeg, png Min 64x64, max 4096 x 4096 Up to 5MB
# Image Expansion API
AI expands an image beyond its original canvas, generating natural background and scene details for the extended area. It supports canvas mode and four-side mode for product photos, portraits, and design materials, with async and sync request modes.
> Note: The result image URL is valid for 1 hour. Please download and store it promptly.
## Base URL
```
https://techhk.aoscdn.com
```
## Authentication
Every request must include your API key in the `X-API-KEY` request header:
```http
X-API-KEY: YOUR_API_KEY
```
Get or manage your API key from [API Key](https://picwish.com/my-account?subRoute=api-key).
Requests without a valid key are rejected.
## Request modes
The mode is controlled by the `sync` body parameter on the create request:
- Asynchronous (`sync=0`, recommended): the create request returns immediately with `data.task_id`. Poll the query endpoint with that task ID until processing finishes.
- Synchronous (`sync=1`): the create request waits for processing to finish and returns the result directly in the same response.
## Source image and expansion modes
- `image_url` or `image_file` is required. If both are provided, `image_file` takes priority.
- `mask_url` or `mask_file` is optional. If both are provided, `mask_file` takes priority.
- If a mask parameter is provided, canvas mode is used. Otherwise, use `top`, `bottom`, `left`, and `right` to control four-side expansion ratios.
- In canvas mode, the source image and mask must have the same dimensions.
## Endpoints
| Purpose | Method | Path |
| --- | --- | --- |
| Create an image expansion task | POST | /api/tasks/visual/advanced-image-expand |
| Query a task result (async) | GET | /api/tasks/visual/advanced-image-expand/{task_id} |
## Create an image expansion task
`POST /api/tasks/visual/advanced-image-expand`
Content-Type: `multipart/form-data`
### Body parameters
| Name | Type | Required | Description |
| --- | --- | --- | --- |
| image_url | string | one of image_url / image_file | Source image download URL. Supports HTTP and OSS URLs, up to 512 characters, with a 10-second download timeout. If both image_file and image_url are provided, image_file takes priority. |
| image_file | file | one of image_url / image_file | Source image file. Only JPG, JPEG, and PNG are supported. The file must be up to 5MB and between 64x64 and 4096x4096. It takes priority over image_url. |
| mask_url | string | optional | Mask image URL. If provided, canvas mode is used. Supports HTTP and OSS URLs, up to 512 characters, with a 10-second download timeout. The image and mask must have the same dimensions. If both mask_file and mask_url are provided, mask_file takes priority. |
| mask_file | file | optional | Mask image file. If provided, canvas mode is used. It takes priority over mask_url. The image and mask must have the same dimensions. |
| return_type | integer | optional | Result return type. 1 returns the image download URL (default); 2 returns the image as a Base64 string. |
| top | number | optional | Top expansion ratio. Default is 0.1. Range: (0, 1]. |
| bottom | number | optional | Bottom expansion ratio. Default is 0.1. Range: (0, 1]. |
| left | number | optional | Left expansion ratio. Default is 0.1. Range: (0, 1]. |
| right | number | optional | Right expansion ratio. Default is 0.1. Range: (0, 1]. |
| strength | number | optional | Source image similarity. Recommended range: [0.1, 1.0]. Smaller values stay closer to the source image; larger values follow the text prompt more strongly. When set to 0, the result remains almost identical to the source image. |
| scale | number | optional | Prompt guidance scale. Default is 7.0. Range: [1, 20]. |
| steps | integer | optional | Sampling steps. Default is 30. Higher values may produce finer results but increase processing time. |
| seed | integer | optional | Random seed. Default is -1. -1 means a random seed is used. The same positive seed with identical parameters is highly likely to produce the same result. |
| prompt | string | optional | Prompt used to guide image generation. Chinese and English are supported. Keep it concise, ideally within 100 Chinese characters or English words. This field is subject to content review. |
| sync | integer | optional | 0 = asynchronous, return task_id first and poll later; 1 = synchronous, return the result directly. We recommend polling async results once every second for up to 180 seconds. |
### Return parameters - asynchronous (sync=0)
| Name | Type | Description |
| --- | --- | --- |
| status | number | HTTP response status code. 200 means the HTTP request succeeded, not necessarily that image expansion succeeded. See /states. |
| message | string | API response message. If the task fails, refer to this field or contact support. |
| data.task_id | string | Task ID. Use it to query the result later. |
### Return parameters - synchronous (sync=1)
| Name | Type | Description |
| --- | --- | --- |
| status | number | HTTP response status code. 200 means the HTTP request succeeded, not necessarily that image expansion succeeded. See /states. |
| message | string | API response message. If the task fails, refer to this field or contact support. |
| data.task_id | string | Task ID. If the task fails, contact support with this task_id. |
| data.created_at | string | Timestamp of task creation. |
| data.processed_at | string | Timestamp when the task started to be processed. |
| data.completed_at | string | Timestamp of task completion. |
| data.download_time | number | Image download time. |
| data.image | string | Result image URL or Base64 data. The URL is valid for 1 hour. |
| data.image1 | string | Alternative result image field used in some responses. |
| data.image_1 | string | First result image field returned in some async responses. |
| data.image_2 | string | Second result image field returned in some async responses. |
| data.image_3 | string | Third result image field returned in some async responses. |
| data.image_4 | string | Fourth result image field returned in some async responses. |
| data.return_type | number | Result return type. |
| data.progress | number | Task progress percentage, ranging from 0 to 100. |
| data.state | number | Task status code. 1 means completed, greater than 1 means processing, and less than 0 means failed. See /states. |
| data.state_detail | string | Detailed task state. |
| data.time_elapsed | string | Total processing time. |
### Examples
Asynchronous, image URL and mask URL:
```bash
curl -k 'https://techhk.aoscdn.com/api/tasks/visual/advanced-image-expand' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'sync=0' \
-F 'image_url=YOUR_IMAGE_URL' \
-F 'mask_url=YOUR_MASK_IMAGE_URL'
```
Asynchronous, image file and mask file upload:
```bash
curl -k 'https://techhk.aoscdn.com/api/tasks/visual/advanced-image-expand' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'sync=0' \
-F 'image_file=@/path/to/image.jpg' \
-F 'mask_file=@/path/to/mask.png'
```
Synchronous (result returned directly):
```bash
curl -k 'https://techhk.aoscdn.com/api/tasks/visual/advanced-image-expand' \
-H 'X-API-KEY: YOUR_API_KEY' \
-F 'sync=1' \
-F 'image_url=YOUR_IMAGE_URL' \
-F 'mask_url=YOUR_MASK_IMAGE_URL'
```
## Query image expansion result
`GET /api/tasks/visual/advanced-image-expand/{task_id}`
Use this endpoint in asynchronous mode to poll for the result. We recommend polling once every second and keeping the total polling duration within 180 seconds. Stop polling when `data.state=1` or `data.state<0`.
### Path parameters
| Name | Type | Required | Description |
| --- | --- | --- | --- |
| task_id | string | required | The task ID returned by the create request. |
### Return parameters
| Name | Type | Description |
| --- | --- | --- |
| status | number | HTTP response status code. 200 means the HTTP request succeeded, not necessarily that image expansion succeeded. See /states. |
| message | string | API response message. If the task fails, refer to this field or contact support. |
| data.task_id | string | Task ID. If the task fails, contact support with this task_id. |
| data.created_at | string | Timestamp of task creation. |
| data.processed_at | string | Timestamp when the task started to be processed. |
| data.completed_at | string | Timestamp of task completion. |
| data.download_time | number | Image download time. |
| data.image | string | Result image URL or Base64 data. The URL is valid for 1 hour. |
| data.image1 | string | Alternative result image field used in some responses. |
| data.image_1 | string | First result image field returned in some async responses. |
| data.image_2 | string | Second result image field returned in some async responses. |
| data.image_3 | string | Third result image field returned in some async responses. |
| data.image_4 | string | Fourth result image field returned in some async responses. |
| data.return_type | number | Result return type. |
| data.progress | number | Task progress percentage, ranging from 0 to 100. |
| data.state | number | Task status code. 1 means completed, greater than 1 means processing, and less than 0 means failed. See /states. |
| data.state_detail | string | Detailed task state. |
| data.time_elapsed | string | Total processing time. |
### Example
```bash
curl -k 'https://techhk.aoscdn.com/api/tasks/visual/advanced-image-expand/{task_id}' \
-H 'X-API-KEY: YOUR_API_KEY'
```
## Recommended asynchronous flow
1. POST to /api/tasks/visual/advanced-image-expand with `sync=0` and one source image.
2. Optionally provide a mask for canvas mode. Without a mask, use `top`, `bottom`, `left`, and `right` for four-side expansion.
3. Read `data.task_id` from the create response.
4. GET /api/tasks/visual/advanced-image-expand/{task_id} every 1 second. Keep total polling within 180 seconds.
5. Stop polling when `data.state=1` or `data.state<0`.
6. Download the result image URL within 1 hour after processing succeeds.
## Guidelines and Limits
- The result image URL is valid for **1 hour**. Please download and store it promptly.
- HTTP status 200 indicates that the HTTP request succeeded, not that image expansion succeeded. Determine the task result with data.state. See /states for details.
- When passing URLs as parameters, follow URL encoding standards to prevent parameter parsing confusion.
- If a mask parameter is provided, canvas mode is used. Otherwise, use top, bottom, left, and right to control four-side expansion ratios.
- The mask image must have the same dimensions as the source image.
- In canvas mode, the image inside the red box is the image input, including the original image and the area to be expanded.
| Canvas mode diagram |
| --- |
| [](https://picwish.comhttps://cfcdn.apowersoft.info/astro/picwish/_astro/extend-api-img.DhHtJTsk.png) |
- Uploaded images must meet the following format, resolution, and file size limits.
| Format | Resolution | Size |
| --- | --- | --- |
| jpg, jpeg, png | Min 64x64, max 4096 x 4096 | Up to 5MB |
## 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 180 seconds. |
| -7 | Invalid image file (e.g. corrupted image or incorrect format). |
| -5 | The image_url image exceeds the size limit (30MB). |
| -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. |