The portrait stylization model transforms portrait photos into various preset or custom artistic styles.
This document applies only to the China (Beijing) region. Use an API key from this region.
|
Quick links: User guide | Beginner's guide to HTTP calls | Free quota for new users | Billing and throttling |
Model overview
|
Model name |
Billing price |
Throttling (shared by root accounts and RAM users) |
Free quota (View) |
|
|
QPS limit for task submission API |
Number of concurrent tasks |
|||
|
wanx-style-repaint-v1 |
CNY 0.12/image |
2 |
1 |
500 items |
Prerequisites
Obtain an API key and export the API key as an environment variable.
HTTP calls
This model provides only an HTTP API and does not have an SDK. Because image generation is time-consuming, the API operates in an asynchronous mode. The call process consists of two steps:
-
Create a task: Create a portrait stylization task to obtain a unique task ID (`task_id`).
-
Query the result: Use the
task_idto poll the task status until the task is complete. Then, retrieve the generated image URL. The image URL is valid for 24 hours.
-
After you create a task, the system immediately returns a
task_id. Use thistask_idin Step 2 to query the task result. The task ID is valid for 24 hours. -
To integrate this into an existing project, you must implement the HTTP call logic in your preferred language. For code examples, see Portrait Stylization.
-
For a beginner's guide to HTTP calls, see Postman.
Step 1: Create a task to get a task ID
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image-generation/generation
Request headers |
Use a preset styleSet `style_index`. Do not set it to -1.
Use a custom styleSet `style_ref_url` (style reference image) and set `style_index` to -1.
|
|
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, wanx-style-repaint-v1. |
|
|
input The basic information about the input image, such as the image URL. |
Response |
Successful responseSave the
Error responseTask creation failed. See Error codes.
|
|
output 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 by task ID
GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
-
The model takes about 15 seconds to run. You can use a polling mechanism with a reasonable query interval, such as 3 seconds, to retrieve the result.
-
The
task_idis valid for queries for 24 hours. After this period, you cannot query the result, and the system returns the task status asUNKNOWN. -
The
urlreturned for a successful task is valid for 24 hours. Download and save the image promptly. -
The default queries per second (QPS) for this query API is 20. For higher frequency queries or event notifications, you can configure an asynchronous task callback.
-
To query or cancel tasks in batches, see Manage asynchronous tasks.
Request headers |
Query the task resultReplace |
|
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 data (task status and image URLs) is retained for only 24 hours and then automatically purged. Save generated images promptly. Task failedWhen a task fails,
Task running
|
|
output The task output information. |
|
|
usage The statistics for the output. Only successful results are counted. |
|
|
request_id Unique request identifier for tracing and troubleshooting. |
Error codes
If the model call fails and returns an error message, see Error codes for resolution.
This API also has specific status codes, as described in the following table.
|
HTTP status code |
API error code (code) |
API error message (message) |
Description |
|
400 |
InvalidURL |
The request URL is invalid, make sure the url is correct and is an image |
The input URL is incorrect. Make sure the URL is correct. |
|
400 |
InvalidImageResolution |
The input image resolution is too large or small |
The input image resolution is too large or too small. |
|
400 |
InvalidImageFormat |
The input image is in invalid format |
The input image format is invalid. |
FAQ
Q: Why do I receive the error "code":"InvalidImageFormat","message":"The input image is in invalid format"} when I call the style stylization API?
A: The output image format is invalid. For information about supported formats, see the instructions for image parameters in this document.
Q: Is the size of the output image the same as the input image?
A: No. The output image maintains the aspect ratio of the input image. However, its shorter side is fixed at 1536 pixels, and the longer side is scaled proportionally.