This topic describes the input and output parameters for the image outpainting model. Image outpainting supports multiple expansion methods, such as expanding by aspect ratio, expanding by scale, or adding pixels to the top, bottom, left, or right. You can also combine these methods with a rotation angle.
Related guide: Image outpainting
This document applies only to the China (Beijing) region. Use an API key from this region.
Alibaba Cloud Model Studio has released a workspace-specific domain for the China (Beijing) region: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com. The new dedicated domain delivers superior performance and higher stability for inference requests. We recommend migrating from https://dashscope.aliyuncs.com to the new domain.
{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domain remains fully functional.
Model overview
Model name | Unit price | Rate limit (shared between Alibaba Cloud accounts and RAM users) | Free quota(View) | |
QPS limit for task submission API | Number of concurrent tasks | |||
image-out-painting | CNY 0.18/image | 2 | 5 | 500 images |
Prerequisites
Obtain an API key and export the API key as an environment variable. If you use an SDK to make calls, install the DashScope SDK.
HTTP call
To reduce wait times and prevent request timeouts, this service is asynchronous. You must make two requests:
Step 1: Create a task to obtain a task ID: Send a request to create an outpainting task. The response returns a task ID.
Step 2: Query the result based on the task ID: Use the task ID from the previous step to query the result generated by the model.
Step 1: Create a task to obtain a task ID
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image2image/out-painting
Replace {WorkspaceId} with your actual workspace ID.
Request headers | Rotate imageExpand image by scaleExpand image in a specified directionExpand image by aspect ratio |
Content-Type The content type of the request. Must be | |
Authorization Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx. | |
X-DashScope-Async Enables asynchronous processing. HTTP requests support only asynchronous calls. Must be Important If this request header is missing, the error "current user api does not support synchronous calls" is returned. | |
Request body | |
model The model name. For example: | |
input The basic information of the input image, such as the image URL. | |
parameters The processing parameters for the output image, such as the counter-clockwise rotation angle, aspect ratio, expansion scale, and pixel padding for the four sides. | |
Response | Successful responseSave the Error responseTask creation failed. See Error codes. |
output object The task output information. | |
request_id Unique request identifier for tracing and troubleshooting. | |
code Error code. Returned only for failed requests. See Error codes. | |
message Detailed error message. Returned only for failed requests. See Error codes. |
Step 2: Query the result based on the task ID
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
Replace {WorkspaceId} with your actual workspace ID.
Request headers | Query task resultReplace If you use a model in the Singapore region, replace |
Authorization Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx. | |
URL path parameters | |
task_id The ID of the task. |
Response | Task successfulTask runningTask failed |
output object The task output information. | |
usage object The image statistics information. | |
request_id Unique request identifier for tracing and troubleshooting. |
Image processing parameter usage
The image processing parameters include two parameter types: rotation and expansion. The expansion parameters are divided into three independent categories based on their functions.
Parameter type | Priority | Parameter |
Rotation parameter | Rotate first, then expand |
|
Expansion parameters | Expansion priority 1: Expand by aspect ratio |
|
Expansion priority 2: Expand by scale |
| |
Expansion priority 3: Expand by adding pixels in a specified direction |
|
Parameter setting recommendations
To expand only by aspect ratio: Set
output_ratioto an aspect ratio, such as "4:3" or "16:9".To expand only by scale: Set the
x_scaleparameter, they_scaleparameter, or both. At least one parameter must have a value greater than 1.0.To expand by adding pixels in a specific direction: Set one or more of the
left_offset,right_offset,top_offset, orbottom_offsetparameters to a value greater than 0.To rotate the image only: Set the
angleparameter to a value in the range of 1 to 359, excluding 90, 180, and 270.To rotate and then expand the image: You can set the
angleparameter to a value in the range of [1, 359]. You must also use this parameter with one of the following three groups of expansion parameters. If you set multiple groups of expansion parameters, they take effect according to parameter priority.output_ratio: Cannot be empty.x_scale, y_scale: At least one of the values must be greater than 1.0.top_offset, bottom_offset, left_offset, right_offset: The value of at least one parameter must be greater than 0.
Note: When you rotate and expand an image, the model first rotates the image by the specified angle and then performs the expansion operation on the rotated image. The actual expansion effect is determined by the model output.
Parameter priority
If
angle > 0and expansion parameters are also set, the processing order is: First rotate, then expand.If
angle = 0or if the image is rotated, the expansion parameters are applied in the following priority order:Priority 1: Expand by aspect ratio (output_ratio)
If `output_ratio` is not empty, the image is generated based on this aspect ratio, and all other expansion parameters are ignored.
Priority 2: Expand by scale (x_scale, y_scale)
If `output_ratio` is not set and at least one of `x_scale` or `y_scale` is greater than 1, the image is expanded by the specified scale. In this case, the pixel offset parameters are ignored.
Priority 3: Expand by adding pixels in a specified direction (left_offset, right_offset, top_offset, bottom_offset)
If `output_ratio`, `x_scale`, and `y_scale` are not set, and at least one of `left_offset`, `right_offset`, `top_offset`, or `bottom_offset` is greater than 0, the image is expanded by adding pixels in the specified direction.
Parameter combination examples
Configuration combination | Actual effective mode |
| Expand by 4:3 aspect ratio (only |
| Expand by scale (only |
| Rotate 90° counter-clockwise, then expand the width of the rotated image to 2.0 times its original size (both |
| Rotate 90° counter-clockwise, then expand the rotated image to a 4:3 aspect ratio (only |
Error codes
If the model call fails and returns an error message, see Error codes for resolution.
This API also has specific status codes, which are described in the following table.
HTTP status code | API error code (code) | API error message (message) | Description |
400 | InvalidParameter.JsonPhrase | input json error | Input JSON error. |
400 | InvalidParameter.FileDownload | oss download error | Failed to download the input image. |
400 | InvalidParameter.ImageFormat | read image error | Failed to read the image. |
400 | InvalidParameter.ImageContent | The image content does not comply with green network verification | The image content is not compliant. |
400 | InvalidParameter | the parameters must conform to the specification: xxx | The input parameter value is out of range. |
400 | InvalidParameter.DataInspection | The image size is not supported for the data inspection. | The output image size exceeds the limit (larger than 10 MB). |
500 | InternalError.Algo | algorithm process error | Algorithm error. |
500 | InternalError.FileUpload | oss upload error | File upload failed. |
FAQ
Q: The create task API call returns a successful response, but no image URL is returned. Why?
A: For image model processing, you must make two HTTP requests to retrieve the result: first, create a task, and then query the result based on the task ID. The create task API call only submits the task and does not return the image result. You must call the GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id} operation to obtain the URL of the image generated by the model.
Q: After I set the output_ratio, why doesn't the model automatically calculate the scale for the other dimension based on x_scale or y_scale?
A: The image outpainting API supports three expansion methods: by aspect ratio, by scale, and by adding pixels in a specific direction. The parameters for these methods are independent. To prevent conflicts, the system uses the following priority order: output_ratio > x_scale / y_scale > *offset.
When you set `output_ratio` to a non-empty value, the system expands the image only based on that aspect ratio and ignores all other expansion parameters. Therefore, if you set both `output_ratio` and `x_scale`, only `output_ratio` takes effect. The `x_scale` parameter is ignored, and `y_scale` is not automatically inferred or calculated based on `x_scale`.