Skip to main content

Portrait style repainting

The portrait style repainting 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.

Model overview

Model name

Billing price

Throttling (shared by Alibaba Cloud account and RAM users)

Free quota(View)

QPS limit for task submission API

Number of concurrent tasks

wanx-style-repaint-v1

CNY 0.12 per image

2

1

500 images

Model effects

The model supports two repainting methods:

1. Preset style repainting

You can upload a portrait photo and select a preset style ID to quickly generate various stylized portraits.
  • Built-in styles: Retro Comic, 3D Fairy Tale, Anime, Fresh, Future Tech, Traditional Chinese Painting, Battle-Hardened General, and more.
  • Examples:
image

2. Custom style repainting

You can upload a portrait photo and a style reference image. The model learns the style from the reference image and applies it to the portrait.
  • Scenarios: You can use this feature to transfer the artistic style from any image when preset styles do not meet your needs.
  • Examples:
image

Getting started

Prerequisites

Obtain an API key and configure it as an environment variable.

Sample code

This model provides only an HTTP API. Refer to the curl sample code.
  • curl
  • Python
For a beginner's guide to HTTP calls, see Postman.
Because image generation is time-consuming, the API uses an asynchronous mode. The call process consists of two steps:
Step 1: Create a task to get the task ID
This API returns a unique task ID (task_id).Sample request
  • Use a preset style
  • Use a custom style
Set style_index. Do not set it to -1.
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'X-DashScope-Async: enable' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "model": "wanx-style-repaint-v1",
    "input": {
        "image_url": "https://vigen-video.oss-cn-shanghai.aliyuncs.com/demo_image/image_demo_input.png",
        "style_index": 3
    }
}'
Sample responseThe task_id is valid for queries for 24 hours.
{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}
Step 2: Query the task result
Use the task_id to poll the task status until it is complete and you obtain the generated image URL.Sample requestReplace {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.
curl -X GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Sample response
The image URL is valid for 24 hours. Download the image promptly.
{
    "request_id": "f7fee4f1-1f68-9f17-85df-xxxxx",
    "output": {
        "task_id": "316c7af0-e91f-476f-99bd-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-08-12 10:55:43.768",
        "scheduled_time": "2025-08-12 10:55:43.799",
        "end_time": "2025-08-12 10:55:48",
        "error_message": "Success",
        "start_time": "2025-08-12 10:55:43",
        "style_index": 0,
        "error_code": 0,
        "results": [
            {
                "url": "http://oss.aliyuncs.com/xxx/abc.jpg"
            }
        ]
    },
    "usage": {
        "image_count": 1
    }
}

Input image limits

Portrait image

  • Image resolution: The resolution must be at least 256*256 pixels and no more than 5760*3240 pixels. The aspect ratio of the longer side to the shorter side cannot exceed 2:1.
  • Image quality: To ensure high-quality output, upload a clear photo of a face. The face should not be too small in the frame. Avoid exaggerated poses and expressions.
  • Image format: JPEG, PNG, JPG, BMP, WEBP.
  • Image size: No larger than 10 MB.
  • Image URL:
    • HTTP/HTTPS URLs accessible over the public network are supported. The URL cannot contain Chinese characters. Base64-encoded strings are also supported.
    • For local files, you can obtain a valid parameter value in one of two ways:

Style reference image

  • Image resolution: The resolution must be at least 256*256 pixels and no more than 5760*3240 pixels. For best results, the aspect ratio of the longer side to the shorter side should not exceed 2:1. Otherwise, generation may be affected or an error may occur.
  • Image format: JPEG, PNG, JPG, BMP, WEBP.
  • Image size: No larger than 10 MB.
  • Image URL:
    • HTTP/HTTPS URLs accessible over the public network are supported. The URL cannot contain Chinese characters. Base64-encoded strings are also supported.
    • For local files, you can obtain a valid parameter value in one of two ways:

Pass an image as a Base64-encoded string

You can convert a local image file to a Base64-formatted string and concatenate it in the following format: data:{MIME_type};base64,{base64_data}.
  • {MIME_type}: The media type of the image, which must correspond to the file format.
  • {base64_data}: The complete data string of the image file after Base64 encoding.
  • The mapping between image formats and Multipurpose Internet Mail Extensions (MIME) types is as follows:

    Image format

    MIME Type

    JPEG

    image/jpeg

    JPG

    image/jpeg

    PNG

    image/png

    BMP

    image/bmp

    WEBP

    image/webp

  • Example value: "image_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABDg......". Note: The Base64 string is truncated for display purposes. In practice, you must pass the complete encoded string.
  • Sample code: Obtain the Base64-encoded string of an image.
import base64
import mimetypes

# --- For Base64 encoding ---
# Format is data:{MIME_type};base64,{base64_data}
def encode_file(file_path):
    mime_type, _ = mimetypes.guess_type(file_path)
    if not mime_type or not mime_type.startswith("image/"):
        raise ValueError("Unsupported or unrecognized image format")
    with open(file_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
    return f"data:{mime_type};base64,{encoded_string}"

if __name__ == "__main__":
    print(encode_file("./image_demo_input.png"))

Billing and throttling

Billing rules
  • Billable item: You are billed for the number of successfully generated images on a pay-as-you-go basis.
  • Billing formula: Fee = Unit price × Number of images.
  • Consumption order: Free quotas are consumed first. After your free quota is used up, the pay-as-you-go billing method is used by default.
    • You can enable the "Free quota only" option to prevent charges after your free quota is exhausted. For more information, see Free quota for new users.
  • No charge for failures: Failed model calls or processing errors do not incur fees or consume free quotas.
Free quotas For more information about how to claim, query, and use free quotas, see Free quota for new users. Query usage Within a few minutes after a model call is complete, go to the Monitoring page to view metrics such as usage, number of calls, and success rate. Rate limiting For rate limiting rules and FAQ, see Rate limits.

API reference

For the API input and response parameters, see Portrait style repainting.

FAQ

Q: How do I process local images?
A: This API supports public URLs and Base64 encoding. To use a local file, you can obtain a valid parameter value in one of two ways:
  1. Obtain a URL: Upload the image to an object storage service, such as Alibaba Cloud OSS, or use the temporary storage provided by Alibaba Cloud Model Studio.
  2. Generate a Base64-encoded string: For more information, see Pass an image as a Base64-encoded string.
Q: How can I optimize the image generation quality?
A: The quality of the output depends on the quality of the input. You can try the following methods to optimize the results:
  • Improve portrait photo quality: Use a high-definition, well-lit, frontal photo with clear, unobstructed facial features.
  • Select a style reference image: Choose an image with a distinct style that matches the subject of the portrait.
Q: Can I use preset and custom styles at the same time?
A: No, you cannot. These modes are mutually exclusive. You must choose one of the two modes:
  • Use a preset style: Set style_index to a value other than -1. For a list of enumeration values, see Portrait style repainting.
  • Use a custom style: Provide a style reference image URL (style_ref_url) and set style_index to -1.
    If you pass both and do not set style_index to -1, the system may default to the preset style, causing the custom style to not take effect.
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.
Token Plan
Model Playground
Fine-tuning
Model Compression
Statistics and Monitoring
Support