The portrait stylization model transforms portrait photos into various preset or custom artistic styles.
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://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation
Replace {WorkspaceId} with your actual workspace ID.
Request headersContent-Typestring (Required)The content type of the request. Must be application/json.Authorization string (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.X-DashScope-Async string (Required)Enables asynchronous processing. HTTP requests support only asynchronous calls. Must be enable.Request bodymodelstring (Required)The model name. For example, wanx-style-repaint-v1.input object (Required)The basic information about the input image, such as the image URL.
Properties image_url string (Required)The URL of the input image.
integer (Required)The index of a preset style used to generate a stylized portrait. For more information about style effects, see the User guide.
string (Optional)This parameter is required when style_index is set to -1. It is not required for other styles.The URL of the style reference image. For more information about style reference effects, see the User guide.
|
Set style_index. Do not set it to -1. |
ResponseoutputobjectThe task output information.
Properties task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.
Enumeration values
stringUnique request identifier for tracing and troubleshooting.code stringError code. Returned only for failed requests. See Error codes.message stringDetailed error message. Returned only for failed requests. See Error codes. |
Save the task_id to query the task status and result. |
Step 2: Query the result by task ID
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
Replace {WorkspaceId} with your actual workspace 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 headersAuthorizationstring (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.URL path parameterstask_idstring (Required)The ID of the task. |
Replace {task_id} with the task_id value returned by the previous API call. The task_id is valid for queries for 24 hours, Replace {WorkspaceId} with your actual workspace ID. |
ResponseoutputobjectThe task output information.
Properties task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.
Enumeration values
stringThe time when the task was submitted. format is YYYY-MM-DD HH:mm:ss.SSS.scheduled_time stringThe time when the task was executed. format is YYYY-MM-DD HH:mm:ss.SSS.end_time stringThe time when the task was completed. format is YYYY-MM-DD HH:mm:ss.SSS.start_time stringThe time the task started processing.error_message stringThe error message. This parameter is returned for normal requests and can be ignored.error_code integerThe error code. This parameter is returned for normal requests and can be ignored.style_index integerReturns the index of the specified style.results array objectA list of task results. The list includes the image URL, prompt, and error messages for any failed sub-tasks.
Data structure objectStatistics for the task result.
Properties TOTAL integerThe total number of tasks.SUCCEEDED integerThe number of successful tasks.FAILED integerThe number of failed tasks.stringError code. Returned only for failed requests. See Error codes.message stringDetailed error message. Returned only for failed requests. See Error codes.objectThe statistics for the output. Only successful results are counted.
Properties image_count integerNumber of images successfully generated. Billing: Cost = Number of images × Unit price.stringUnique request identifier for tracing and troubleshooting. |
Task data (task status and image URLs) is retained for only 24 hours and then automatically purged. Save generated images promptly. |
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.