Skip to main content

Wan-Image Generation and Editing 2.6 API Reference

The Wan image generation model supports image editing and image-text mixed output, meeting diverse generation and integration needs.

Model Overview

Model

Model Description

Output Image Specifications

wan2.6-image

Wan2.6 image

Supports image editing and image-text mixed output

For pure text-based image generation (text-to-image), we recommend using the wan2.6-t2i model (Wan-Text-to-Image V2).

Image Format: PNG.

For image resolution and dimensions, see the size parameter.

Before making calls, check the model list and prices supported in each region.

Prerequisites

You must have obtained and configured an API Key and configured the API Key in environment variables. Replace DASHSCOPE_API_HOST in the sample code with your obtained API Host.
The Singapore, United States (Virginia), and North China 2 (Beijing) regions each have their own API Key and request address, which cannot be mixed. Cross-region calls will result in authentication failure or service errors. For details, see Select a region, service deployment scope, and endpoint.
Alibaba Cloud Model Studio has launched workspace-dedicated domains for the North China 2 (Beijing) and Singapore regions, which deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
  • North China 2 (Beijing) region: migrate from https://dashscope.aliyuncs.com to https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com
  • Singapore region: migrate from https://dashscope-intl.aliyuncs.com to https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
{WorkspaceId} is your workspace ID, which you can view on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domains remain available.

HTTP Synchronous Call

A single request returns the result, making the workflow simple. Recommended for most scenarios.
  • Singapore
  • United States (Virginia)
  • North China 2 (Beijing)
  • dashscope CLI
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generationWhen calling, replace {WorkspaceId} with your actual Workspace ID.
The global deployment scope (Frankfurt region) only supports asynchronous calls.

Request Parameters

Request Headers
Content-Typestring(Required)The request content type. This parameter must be set to application/json.Authorizationstring(Required)Request authentication. The interface uses the Alibaba Cloud Model Studio API Key for authentication. Example value: Bearer sk-xxxx.X-DashScope-Ssestring(Optional)Used to enable streaming output.
  • Only when parameters.enable_interleave=true, you must set this field to enable.
  • In other cases, it can be omitted or ignored.
Request Body
model string (Required)The model name. Set it to wan2.6-image.input object (Required)The basic information of the input.

Property

messages array (Required)The request content array. Currently only single-turn conversations are supported, that is, pass in one set of role and content parameters; multi-turn conversations are not supported.

Property

rolestring (Required)The role of the message. This parameter is fixed to user.contentarray (Required)The message content array.

Property

textstring(Required)The positive prompt describes the image content, style, and composition you expect to generate.Both Chinese and English are supported, with a length of no more than 2000 characters. Each Chinese character, letter, digit, or symbol counts as one character, and any excess is automatically truncated.Example value: Refer to images in this style and generate tomato scrambled eggs.Note: The content array must contain exactly one object with the text field.imagestring(Optional)The URL or Base64-encoded string of the input image.Image limits:
  • Image format: JPEG, JPG, PNG (transparent channels are not supported), BMP, WEBP.
  • Image resolution: The width and height of the image are both within the range [240, 8000] pixels.
  • File size: No more than 10MB.
Image quantity limits:
  • The number of input images is related to the parameters.enable_interleave parameter.
    • When enable_interleave=true (interleaved text-and-image output), you can input 0~1 images.
    • When enable_interleave=false (image editing), you must input 1~4 images.
  • When inputting multiple images, pass multiple image objects in the content array and define the image order according to the array order.
Supported input formats:
  1. Use a publicly accessible URL
    • Supports HTTP or HTTPS protocols.
    • Example value: http://wanx.alicdn.com/material/xxx.jpeg.
  2. Pass a Base64-encoded image string
    • Format: data:{MIME_type};base64,{base64_data}
    • Example: data:image/jpeg;base64,GDU7MtCZzEbTbmRZ... (for illustration only; the complete string must be passed in actual use)
    • For Base64 encoding specifications, see Image input methods.
parameters object (optional)Image processing parameters.

Property

negative_prompt string (optional)The negative prompt, used to describe the content you do not want to appear in the image, constraining the image.Supports both Chinese and English, with a length of no more than 500 characters; the excess part will be automatically truncated.Example value: low resolution, low quality, deformed limbs, deformed fingers, oversaturated image, waxy look, faces without detail, overly smooth, AI-looking image. Chaotic composition. Blurred, distorted text.size string (optional)Output image resolution parameter, which supports two methods: referencing the input image aspect ratio and directly specifying values.When enable_interleave=false (that is, image editing mode):
  • Method 1: Reference the input image aspect ratio (recommended) Available output resolution tiers: 1K (default), 2K.
    • 1K: The total output pixels are close to 1280*1280, and the aspect ratio is the same as that of the last input image.
    • 2K: The total output pixels are close to 2048*2048, and the aspect ratio is the same as that of the last input image.
  • Method 2: Specify the width and height pixel values of the generated image The total pixels are within [768768, 20482048], and the aspect ratio range is [1:4, 4:1].
    The pixel values of the actual output image are multiples of 16 close to the specified values.
When enable_interleave=true (that is, interleaved text-and-image output mode):
  • Method 1: Reference the input image aspect ratio (default method)
    • If the total input image pixels are ≤ 1280*1280, the total output pixels and aspect ratio are the same as those of the input image.
    • If the total input image pixels are > 12801280, the total output pixels are close to 12801280, and the aspect ratio is the same as that of the input image.
    • If there is no input image, the output is 1280*1280.
  • Method 2: Specify the width and height pixel values of the generated image The total pixels are within [768768, 12801280], and the aspect ratio range is [1:4, 4:1].
    The pixel values of the actual output image are multiples of 16 close to the specified values.

Recommended resolutions for common aspect ratios

enable_interleave bool (optional)Controls the image generation mode:
  • false: Default value. Indicates the image editing mode (supports multi-image input and subject-consistent generation).
    • Purpose: Edit, perform style transfer, or generate with subject consistency based on 1 to 4 input images.
    • Input: You must provide at least 1 reference image.
    • Output: Can generate 1 to 4 result images.
  • true: Indicates that the interleaved text-image output mode is enabled (only supports passing in one image or no image).
    • Purpose: Generate richly illustrated content based on text descriptions, or perform pure text-to-image generation. For pure text-to-image scenarios, we recommend using the wan2.6-t2i model (Wan-text-to-image V2) first.
    • Input: You can provide no image (text-to-image) or up to 1 reference image.
    • Output: Generates mixed content containing text and images.
n integer (Optional)
n directly affects the fee. Fee = Unit price × number of successfully generated images. Confirm the Model Price before calling.
Specifies the number of images to generate. The value range and meaning of this parameter depend on the state of enable_interleave (mode switch):
  • When enable_interleave=false (image editing mode):
    • Effect: Directly controls the number of generated images.
    • Value range: 1 to 4. Default value is 4.
    • We recommend setting this value to 1 during testing to verify results at a low cost.
  • When enable_interleave=true (interleaved text-image mode):
    • Limit: This parameter defaults to 1 and must be fixed to 1. Setting it to any other value will cause an API error.
    • Note: In this mode, use the max_images parameter to control the maximum number of generated images.
max_images integer (Optional)
max_images affects the fee. Fee = Unit price × number of successfully generated images. Confirm the Model Price before calling.
Only takes effect in the interleaved text-image mode (that is, enable_interleave=true).
  • Effect: Specifies the maximum number of images the model generates in a single response.
  • Value range: 1 to 5. Default value is 5.
  • Note: This parameter only represents the quantity limit. The actual number of generated images is determined by model inference and may be less than the set value (for example, if set to 5, the model may generate only 3 images based on the content).
prompt_extend bool (Optional)Only takes effect in the image editing mode (that is, enable_interleave = false).Whether to enable the intelligent Prompt rewriting feature. This feature only optimizes and polishes positive prompts and does not change negative prompts.
  • true: Default value. Enables intelligent rewriting.
  • false: Disables intelligent rewriting and uses the original prompt.
stream bool (Optional)Controls whether the returned result is streaming output. In the interleaved image mode (that is, enable_interleave = true), it must be set to true.
  • false: Default value. Non-stream output.
  • true: Streaming output.
watermark bool (Optional)Whether to add a watermark. The watermark is placed at the bottom-right corner of the image, with the fixed text "AI-generated".
  • false: Default value. No watermark is added.
  • true: Adds a watermark.
seed integer (Optional)Random number seed. Value range: [0,2147483647].Using the same seed parameter value keeps the generated content relatively stable. If not provided, the algorithm automatically uses a random seed.Note: The model generation process is probabilistic. Even with the same seed, identical generation results cannot be guaranteed each time.
  • Image editing
  • Interleaved text and images (streaming only)
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "wan2.6-image",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "text": "参考图1的风格和图2的背景,生成番茄炒蛋"
                    },
                    {
                        "image": "https://cdn.wanx.aliyuncs.com/tmp/pressure/umbrella1.png"
                    },
                    {
                        "image": "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"
                    }
                ]
            }
        ]
    },
    "parameters": {
        "prompt_extend": true,
        "watermark": false,
        "n": 1,
        "enable_interleave": false,
        "size": "1K"
    }
}'

Response parameters

output objectTask output information.

Property

choices array of objectOutput content generated by the model.

Property

finish_reason stringReason the task stopped.Non-streaming output scenario: stop when the task stops naturally.Streaming output scenario: When streaming output is enabled, this parameter indicates whether the data stream has finished transmission.
  • During transmission: preceding data packets keep returning "finish_reason": "null", indicating that content is still being generated; continue receiving.
  • When transmission ends: "finish_reason":"stop" is returned only in the last JSON structure, indicating that the streaming request has fully ended and you should stop receiving.
message objectMessage returned by the model.

Property

rolestringRole of the message, fixed as assistant.contentarray

Property

type stringType of the output. Enumerated values: text, image.text stringGenerated text.image stringURL of the generated image. The image format is PNG.The link is valid for 24 hours. Download and save the image in a timely manner.
finished boolRequest end flag.
  • true: indicates the request has ended.
  • false: indicates the request has not ended.
usage objectOutput information statistics. Only successful results are counted.

Property

image_count integerNumber of generated images.size stringResolution of the generated image. Example value: 1376*768.input_tokens integerBilled by the number of images.
  • In image editing mode, fixed to 0.
  • In interleaved text and image mode, this field counts the number of tokens in the input text (not billed).
output_tokens integerBilled by the number of images.
  • In image editing mode, fixed to 0.
  • In interleaved text and image mode, this field counts the number of tokens in the output text (not billed).
total_tokensintegerBilled by the number of images.
  • In image editing mode, fixed to 0.
  • In interleaved text and image mode, this field counts the total number of tokens (not billed).
request_idstringUnique request identifier. It can be used for request detail tracing and troubleshooting.codestringError code returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error code.messagestringDetailed information about the request failure. This parameter is not returned when the request succeeds. For details, see Error code.
  • Task executed successfully
  • Task executed successfully (streaming output)
  • Task execution exception
Task data (such as task status and image URLs) is retained for only 24 hours and is automatically cleared after expiration. Be sure to save the generated images in a timely manner.
{
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.png?Expires=xxx",
                            "type": "image"
                        }
                    ],
                    "role": "assistant"
                }
            }
        ],
        "finished": true
    },
    "usage": {
        "image_count": 1,
        "input_tokens": 0,
        "output_tokens": 0,
        "size": "1376*768",
        "total_tokens": 0
    },
    "request_id": "a3f4befe-cacd-49c9-8298-xxxxxx"
}

HTTP asynchronous call

The workflow consists of two core steps, “Create task -> Poll for results”, as detailed below:

Step 1: Create a task to obtain the task ID

  • Singapore
  • United States (Virginia)
  • North China 2 (Beijing)
  • Germany (Frankfurt)
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generationWhen calling, replace {WorkspaceId} with your actual Workspace ID.
  • After the task is created successfully, use the task_id returned by the API to query the result. The task_id is valid for 24 hours. Do not create the task repeatedly; poll to obtain the result instead.
  • For beginner guidance, see Postman.

Request parameters

Request headers
Content-Typestring(Required)The request content type. This parameter must be set to application/json.Authorizationstring(Required)Request authentication. The interface uses the Alibaba Cloud Model Studio API Key for authentication. Example value: Bearer sk-xxxx.X-DashScope-Asyncstring(Required)The asynchronous processing configuration parameter, which must be set toenable.
If this request header is missing, the following error occurs: “current user api does not support synchronous calls”.
Request body
model string (Required)The model name.Example value: wan2.6-imageinput object (Required)The basic information of the input.

Property

messages array (Required)The request content array. Currently only single-turn conversations are supported, that is, pass in one set of role and content parameters; multi-turn conversations are not supported.

Property

rolestring (Required)The role of the message. This parameter is fixed to user.contentarray (Required)The message content array.

Property

textstring(Required)The positive prompt describes the image content, style, and composition you expect to generate.Both Chinese and English are supported, with a length of no more than 2000 characters. Each Chinese character, letter, digit, or symbol counts as one character, and any excess is automatically truncated.Example value: Refer to images in this style and generate tomato scrambled eggs.Note: The content array must contain exactly one object with the text field.imagestring(Optional)The URL or Base64-encoded string of the input image.Image limits:
  • Image format: JPEG, JPG, PNG (transparent channels are not supported), BMP, WEBP.
  • Image resolution: The width and height of the image are both within the range [240, 8000] pixels.
  • File size: No more than 10MB.
Image quantity limits:
  • The number of input images is related to the parameters.enable_interleave parameter.
    • When enable_interleave=true (interleaved text-and-image output), you can input 0~1 images.
    • When enable_interleave=false (image editing), you must input 1~4 images.
  • When inputting multiple images, pass multiple image objects in the content array and define the image order according to the array order.
Supported input formats:
  1. Use a publicly accessible URL
    • Supports HTTP or HTTPS protocols.
    • Example value: http://wanx.alicdn.com/material/xxx.jpeg.
  2. Pass a Base64-encoded image string
    • Format: data:{MIME_type};base64,{base64_data}
    • Example: data:image/jpeg;base64,GDU7MtCZzEbTbmRZ... (for illustration only; the complete string must be passed in actual use)
    • For Base64 encoding specifications, see Image input methods.
parameters object (optional)Image processing parameters.

Property

negative_prompt string (optional)The negative prompt, used to describe the content you do not want to appear in the image, constraining the image.Supports both Chinese and English, with a length of no more than 500 characters; the excess part will be automatically truncated.Example value: low resolution, low quality, deformed limbs, deformed fingers, oversaturated image, waxy look, faces without detail, overly smooth, AI-looking image. Chaotic composition. Blurred, distorted text.size string (optional)Output image resolution parameter, which supports two methods: referencing the input image aspect ratio and directly specifying values.When enable_interleave=false (that is, image editing mode):
  • Method 1: Reference the input image aspect ratio (recommended) Available output resolution tiers: 1K (default), 2K.
    • 1K: The total output pixels are close to 1280*1280, and the aspect ratio is the same as that of the last input image.
    • 2K: The total output pixels are close to 2048*2048, and the aspect ratio is the same as that of the last input image.
  • Method 2: Specify the width and height pixel values of the generated image The total pixels are within [768768, 20482048], and the aspect ratio range is [1:4, 4:1].
    The pixel values of the actual output image are multiples of 16 close to the specified values.
When enable_interleave=true (that is, interleaved text-and-image output mode):
  • Method 1: Reference the input image aspect ratio (default method)
    • If the total input image pixels are ≤ 1280*1280, the total output pixels and aspect ratio are the same as those of the input image.
    • If the total input image pixels are > 12801280, the total output pixels are close to 12801280, and the aspect ratio is the same as that of the input image.
    • If there is no input image, the output is 1280*1280.
  • Method 2: Specify the width and height pixel values of the generated image The total pixels are within [768768, 12801280], and the aspect ratio range is [1:4, 4:1].
    The pixel values of the actual output image are multiples of 16 close to the specified values.

Recommended resolutions for common aspect ratios

enable_interleave bool (optional)Controls the image generation mode:
  • false: Default value. Indicates the image editing mode (supports multi-image input and subject-consistent generation).
    • Purpose: Edit, perform style transfer, or generate with subject consistency based on 1 to 4 input images.
    • Input: You must provide at least 1 reference image.
    • Output: Can generate 1 to 4 result images.
  • true: Indicates that the interleaved text-image output mode is enabled (only supports passing in one image or no image).
    • Purpose: Generate richly illustrated content based on text descriptions, or perform pure text-to-image generation. For pure text-to-image scenarios, we recommend using the wan2.6-t2i model (Wan-text-to-image V2) first.
    • Input: You can provide no image (text-to-image) or up to 1 reference image.
    • Output: Generates mixed content containing text and images.
n integer (Optional)
n directly affects the fee. Fee = Unit price × number of successfully generated images. Confirm the Model Price before calling.
Specifies the number of images to generate. The value range and meaning of this parameter depend on the state of enable_interleave (mode switch):
  • When enable_interleave=false (image editing mode):
    • Effect: Directly controls the number of generated images.
    • Value range: 1 to 4. Default value is 4.
    • We recommend setting this value to 1 during testing to verify results at a low cost.
  • When enable_interleave=true (interleaved text-image mode):
    • Limit: This parameter defaults to 1 and must be fixed to 1. Setting it to any other value will cause an API error.
    • Note: In this mode, use the max_images parameter to control the maximum number of generated images.
max_images integer (Optional)
max_images affects the fee. Fee = Unit price × number of successfully generated images. Confirm the Model Price before calling.
Only takes effect in the interleaved text-image mode (that is, enable_interleave=true).
  • Effect: Specifies the maximum number of images the model generates in a single response.
  • Value range: 1 to 5. Default value is 5.
  • Note: This parameter only represents the quantity limit. The actual number of generated images is determined by model inference and may be less than the set value (for example, if set to 5, the model may generate only 3 images based on the content).
prompt_extend bool (Optional)Only takes effect in the image editing mode (that is, enable_interleave = false).Whether to enable the intelligent Prompt rewriting feature. This feature only optimizes and polishes positive prompts and does not change negative prompts.
  • true: Default value. Enables intelligent rewriting.
  • false: Disables intelligent rewriting and uses the original prompt.
watermark bool (Optional)Whether to add a watermark. The watermark is placed at the bottom-right corner of the image, with the fixed text "AI-generated".
  • false: Default value. No watermark is added.
  • true: Adds a watermark.
seed integer (Optional)Random number seed. Value range: [0,2147483647].Using the same seed parameter value keeps the generated content relatively stable. If not provided, the algorithm automatically uses a random seed.Note: The model generation process is probabilistic. Even with the same seed, identical generation results cannot be guaranteed each time.
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'X-DashScope-Async: enable' \
--data '{
    "model": "wan2.6-image",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "text": "参考图1的风格和图2的背景,生成番茄炒蛋"
                    },
                    {
                        "image": "https://cdn.wanx.aliyuncs.com/tmp/pressure/umbrella1.png"
                    },
                    {
                        "image": "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"
                    }
                ]
            }
        ]
    },
    "parameters": {
        "prompt_extend": true,
        "watermark": false,
        "n": 1,
        "enable_interleave": false,
        "size": "1K"
    }
}'

Response parameters

output objectTask output information.

Property

task_id stringThe task ID. It is valid for queries for 24 hours.task_status stringThe task status.

Enumeration values

  • PENDING: Task queuing
  • RUNNING: Task processing
  • SUCCEEDED: Task executed successfully
  • FAILED: Task execution failed
  • CANCELED: Task canceled
  • UNKNOWN: Task does not exist or the status is unknown
request_idstringUnique request identifier. It can be used for request detail tracing and troubleshooting.codestringError code returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error code.messagestringDetailed information about the request failure. This parameter is not returned when the request succeeds. For details, see Error code.
  • Successful response
  • Error response
Save the task_id, which is used to query the task status and results.
{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

Step 2: Query the result based on the task ID

  • Singapore
  • United States (Virginia)
  • North China 2 (Beijing)
  • Germany (Frankfurt)
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}When calling, replace {WorkspaceId} with your actual Workspace ID.
  • Polling recommendations: Image generation is time-consuming. We recommend using a polling mechanism and setting a reasonable query interval (for example, 10 seconds) to obtain the results.
  • Task status transitions: PENDING (Queuing) → RUNNING (Processing) → SUCCEEDED (Success) / FAILED (Failed).
  • Result links: After the task succeeds, an image URL is returned and remains valid for 24 hours. We recommend that you download the image immediately after obtaining the URL and transfer it to permanent storage (such as Alibaba Cloud OSS).

Request parameters

Request headers
Authorizationstring(Required)Request authentication. The interface uses the Alibaba Cloud Model Studio API Key for authentication. Example value: Bearer sk-xxxx.
URL path parameters
task_id string(Required)Task ID.
  • Query task results
Replace {task_id} entirely with the value of task_id returned by the API in the previous step. The task_id can be queried within 24 hours. Also replace {WorkspaceId} with your actual Workspace ID.
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

Response parameters

output objectTask output information.

Property

task_id stringThe task ID. It is valid for queries for 24 hours.task_status stringThe task status.

Enumeration values

  • PENDING: Task queuing
  • RUNNING: Task processing
  • SUCCEEDED: Task executed successfully
  • FAILED: Task execution failed
  • CANCELED: Task canceled
  • UNKNOWN: Task does not exist or the status is unknown
Status transitions during polling:
  • PENDING (Queuing) → RUNNING (Processing) → SUCCEEDED (Success)/ FAILED (failed).
  • The status on the first query is usually PENDING (Queuing) or RUNNING (Processing).
  • When the status changes to SUCCEEDED, the response will contain the URL of the generated image.
  • If the status is FAILED, check the error message and retry.
submit_time stringTask submission time. The time zone is UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.scheduled_time stringTask execution time. The time zone is UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.end_time stringTask completion time. The time zone is UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.finished boolRequest end flag.
  • true: indicates the request has ended.
  • false: indicates the request has not ended.
choices array of objectOutput content generated by the model.

Property

finish_reason stringThe reason why the task stopped. It is stop when the task stops naturally.message objectMessage returned by the model.

Property

rolestringRole of the message, fixed as assistant.contentarray

Property

type stringType of the output. Enumerated values: text, image.text stringGenerated text.image stringURL of the generated image. The image format is PNG.The link is valid for 24 hours. Download and save the image in a timely manner.
usage objectOutput information statistics. Only successful results are counted.

Property

image_count integerNumber of generated images.size stringResolution of the generated image. Example value: 1376*768.input_tokens integerThe number of input tokens. Billing is based on the number of images, and it is currently fixed at 0.output_tokens integerThe number of output tokens. Billing is based on the number of images, and it is currently fixed at 0.total_tokensintegerThe total number of tokens. Billing is based on the number of images, and it is currently fixed at 0.
request_idstringUnique request identifier. It can be used for request detail tracing and troubleshooting.codestringError code returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error code.messagestringDetailed information about the request failure. This parameter is not returned when the request succeeds. For details, see Error code.
  • Task executed successfully
  • Task execution exception
Task data (such as task status and image URLs) is retained for only 24 hours and is automatically cleared after expiration. Be sure to save the generated images in a timely manner.
{
    "request_id": "43d9e959-25bc-4dc7-9888-xxxxxx",
    "output": {
        "task_id": "858cad55-4bdc-4ba3-ae6c-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-12-16 04:21:02.275",
        "scheduled_time": "2025-12-16 04:21:02.304",
        "end_time": "2025-12-16 04:24:46.658",
        "finished": true,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1xxx.png?Expires=xxx",
                            "type": "image"
                        }
                    ]
                }
            },
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1xxx.png?Expires=xxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "size": "1376*768",
        "total_tokens": 0,
        "image_count": 2,
        "output_tokens": 0,
        "input_tokens": 0
    }
}

Call the DashScope Python SDK

The SDK parameter naming is basically the same as that of the HTTP API, and the parameter structure is encapsulated based on language characteristics. Since tasks take a long time to complete, the SDK encapsulates the HTTP asynchronous call process at the underlying layer and supports both synchronous and asynchronous call methods.
The actual time required depends on the number of queuing tasks and service execution conditions. Please wait patiently when obtaining the results.
Make sure that the DashScope Python SDK version is no earlier than 2.1.0 before running the following code. For updates, see Install the SDK.
The base_url and API Key of each region are not universal. The following example uses the Singapore region as an example to make the call:
  • Singapore
  • United States (Virginia)
  • North China 2 (Beijing)
  • Germany (Frankfurt)
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1When calling, replace {WorkspaceId} with your actual Workspace ID.
The global deployment (Frankfurt region) only supports asynchronous calls.

Image editing

  • Synchronous call
  • Asynchronous call
Request example
import os
import dashscope

# This configuration is for the Singapore region. Replace {WorkspaceId} with your actual workspace ID. The region value varies by region.
client = dashscope.Client(
    # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # API keys differ by region. Get an API key: https://www.alibabacloud.com/help/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="ap-southeast-1",
)

print("----sync call, please wait a moment----")
job = client.images.generate(
    model='wan2.6-image',
    prompt="参考图1的风格和图2的背景,生成番茄炒蛋",
    # Reference image list; local files are supported, such as "file://umbrella1.png"
    image_urls=[
        "https://cdn.wanx.aliyuncs.com/tmp/pressure/umbrella1.png",
        "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"
    ],
    negative_prompt="",
    prompt_extend=True,
    watermark=False,
    n=1,
    parameters={"enable_interleave": False},
    size="1K"
)

print(job)
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{
    "status_code": 200,
    "request_id": "b6a4c68d-3a91-4018-ae96-3cf373xxxxxx",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "audio": null,
        "finished": true
    },
    "usage": {
        "input_tokens": 0,
        "output_tokens": 0,
        "characters": 0,
        "image_count": 1,
        "size": "1376*768",
        "total_tokens": 0
    }
}

Image and text mixed output

  • Synchronous call (streaming only)
  • Asynchronous call
Request example
import os
import dashscope

# This configuration is for the Singapore region. Replace {WorkspaceId} with your actual workspace ID. The region value varies by region.
client = dashscope.Client(
    # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # API keys differ by region. Get an API key: https://www.alibabacloud.com/help/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="ap-southeast-1",
)

def sync_call_with_stream():
    print("\n========== 同步调用 - 流式图文输出 ==========")

    stream = client.multimodal.chat.create(
        model="wan2.6-image",
        messages=[
            {
                "role": "user",
                "content": [
                    {"text": "给我一个3张图辣椒炒肉教程"}
                ],
            }
        ],
        stream=True,  # Streaming only
        # Note: Explicitly pass parameters.stream=True; stream=True is not automatically sent on the wire,
        # Otherwise, the server returns "stream=False is not supported"
        parameters={
            "stream": True,
            "negative_prompt": "",
            "enable_interleave": True,  # Enable mixed text and image output
            "max_images": 3,
            "size": "1280*1280",
        },
    )

    print("流式输出结果:")
    for chunk in stream:
        if not chunk.choices:
            continue
        delta = chunk.choices[0].delta
        # Incremental text output
        if delta.content:
            print(delta.content, end="")
        # Incremental image output: content_parts contains an image part with the image URL
        for part in delta.content_parts or []:
            if part.get("type") == "image":
                print(f"\n[图片] {part['image']}")

if __name__ == "__main__":
    sync_call_with_stream()
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "null", "message": {"role": "assistant", "content": [{"type": "text", "text": "辣椒"}]}}], "audio": null, "finished": false}, "usage": {"input_tokens": 28, "output_tokens": 0, "characters": 0, "total_tokens": 28, "image_count": 0, "size": "0*0"}}
{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "null", "message": {"role": "assistant", "content": [{"type": "text", "text": "炒"}]}}], "audio": null, "finished": false}, "usage": {"input_tokens": 28, "output_tokens": 1, "characters": 0, "total_tokens": 29, "image_count": 0, "size": "0*0"}}
{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "null", "message": {"role": "assistant", "content": [{"type": "text", "text": "肉"}]}}], "audio": null, "finished": false}, "usage": {"input_tokens": 28, "output_tokens": 2, "characters": 0, "total_tokens": 30, "image_count": 0, "size": "0*0"}}

......

{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "null", "message": {"role": "assistant", "content": [{"type": "text", "text": "。"}]}}], "audio": null, "finished": false}, "usage": {"input_tokens": 28, "output_tokens": 398, "characters": 0, "total_tokens": 426, "image_count": 2, "size": "1280*1280"}}
{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "stop", "message": {"role": "assistant", "content": [{"type": "image", "image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"}]}}], "audio": null, "finished": true}, "usage": {"input_tokens": 28, "output_tokens": 523, "characters": 0, "total_tokens": 551, "image_count": 3, "size": "1280*1280"}}

Call through the DashScope Java SDK

The SDK parameter naming is basically the same as that of the HTTP API, and the parameter structure is encapsulated based on language characteristics. Since tasks take a long time to complete, the SDK encapsulates the HTTP asynchronous call process at the underlying layer and supports both synchronous and asynchronous call methods.
The actual time required depends on the number of queuing tasks and service execution conditions. Please wait patiently when obtaining the results.
Before running the following code, make sure the DashScope Java SDK version is no earlier than 2.22.6.
The base_url and API Key of each region are not universal. The following example uses the Singapore region as an example to make the call:
  • Singapore
  • United States (Virginia)
  • North China 2 (Beijing)
  • Germany (Frankfurt)
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1When calling, replace {WorkspaceId} with your actual Workspace ID.
The global deployment (Frankfurt region) only supports asynchronous calls.

Image Editing

  • Synchronous call
  • Asynchronous call
Request example
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;

import java.util.Arrays;
import java.util.Collections;

/**
 * wan2.6-image Image editing - Synchronous call example
 */
public class Main {

    static {
        // The following URL is for the Singapore region. When calling, replace {WorkspaceId} with your actual workspace ID. URLs vary by region.
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // If you have not configured the environment variable, replace the following line with your Model Studio API key: apiKey="sk-xxx"
    // API keys differ by region. Get an API key: https://www.alibabacloud.com/help/model-studio/get-api-key
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void basicCall() throws ApiException, NoApiKeyException, UploadFileException {
        // Build a multi-image input message.
        ImageGenerationMessage message = ImageGenerationMessage.builder()
                .role("user")
                .content(Arrays.asList(
                        // Multi-image input is supported. You can provide multiple reference images.
                        Collections.singletonMap("text", "参考图1的风格和图2的背景,生成番茄炒蛋"),
                        Collections.singletonMap("image", "https://cdn.wanx.aliyuncs.com/tmp/pressure/umbrella1.png"),
                        Collections.singletonMap("image", "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp")
                )).build();

        // Image editing uses standard synchronous call; no need to set stream or enable_interleave
        ImageGenerationParam param = ImageGenerationParam.builder()
                .apiKey(apiKey)
                .model("wan2.6-image")
                .messages(Collections.singletonList(message))
                .n(1)
                .size("1K")
                .negativePrompt("")
                .promptExtend(true)
                .build();

        ImageGeneration imageGeneration = new ImageGeneration();
        ImageGenerationResult result = null;
        try {
            System.out.println("---sync call for image editing, please wait a moment----");
            result = imageGeneration.call(param);
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            throw new RuntimeException(e.getMessage());
        }
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            basicCall();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
    }
}
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{
    "requestId": "b148327e-830f-414c-a8df-724dec28exxx",
    "usage": {
        "input_tokens": 0,
        "output_tokens": 0,
        "total_tokens": 0,
        "image_count": 1,
        "size": "1376*768"
    },
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "finished": true
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

Image and text mixed output

  • Synchronous call (streaming only)
  • Asynchronous call
Request example
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import io.reactivex.Flowable;

import java.util.Collections;

/**
 * wan2.6-image Text-image output - Streaming call example
 */
public class Main {

    static {
        // The following URL is for the Singapore region. When calling, replace {WorkspaceId} with your actual workspace ID. URLs vary by region.
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // If you have not configured the environment variable, replace the following line with your Model Studio API key: apiKey="sk-xxx"
    // API keys differ by region. Get an API key: https://www.alibabacloud.com/help/model-studio/get-api-key
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void streamCall() throws ApiException, NoApiKeyException, UploadFileException {
        ImageGenerationMessage message = ImageGenerationMessage.builder()
                .role("user")
                .content(Collections.singletonList(
                        Collections.singletonMap("text", "给我一个3张图辣椒炒肉教程")
                )).build();

        // Text-image output requires streaming call
        ImageGenerationParam param = ImageGenerationParam.builder()
                .apiKey(apiKey)
                .model("wan2.6-image")
                .messages(Collections.singletonList(message))
                .stream(true) // Must enable streaming output
                .enableInterleave(true)
                .size("1280*1280")
                .negativePrompt("")
                .maxImages(3)
                .build();

        ImageGeneration imageGeneration = new ImageGeneration();
        try {
            System.out.println("---stream call for image interleave----");
            Flowable<ImageGenerationResult> resultFlowable = imageGeneration.streamCall(param);
            resultFlowable.blockingForEach(result -> {
                System.out.println(JsonUtils.toJson(result));
            });
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    public static void main(String[] args) {
        try {
            streamCall();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":0,"total_tokens":28,"image_count":0,"size":"0*0"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"辣椒"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":1,"total_tokens":29,"image_count":0,"size":"0*0"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"炒"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":2,"total_tokens":30,"image_count":0,"size":"0*0"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"肉"}]}}],"finished":false},"status_code":200,"code":"","message":""}

......

{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":73,"total_tokens":101,"image_count":0,"size":"0*0"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"。"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":198,"total_tokens":226,"image_count":1,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"image","image":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":199,"total_tokens":227,"image_count":1,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"接下来"}]}}],"finished":false},"status_code":200,"code":"","message":""}

......

{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":245,"total_tokens":273,"image_count":1,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"。"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":368,"total_tokens":396,"image_count":2,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"image","image":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":369,"total_tokens":397,"image_count":2,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"最后"}]}}],"finished":false},"status_code":200,"code":"","message":""}

......

{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":416,"total_tokens":444,"image_count":2,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"锅"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":417,"total_tokens":445,"image_count":2,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"。"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":541,"total_tokens":569,"image_count":3,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"stop","message":{"role":"assistant","content":[{"type":"image","image":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"}]}}],"finished":true},"status_code":200,"code":"","message":""}

Limits

  • Data validity: The task task_id and the image url are retained for only 24 hours and can no longer be queried or downloaded after expiration.
  • Content moderation: Both the input prompt and the output images go through content safety review; requests containing non-compliant content will return the "IPInfringementSuspect" or "DataInspectionFailed" error. For more information, see Error codes.

Billing and rate limiting

  • For the model free quota and billing unit price, see Model Price.
  • For model rate limits, see Wan.
  • Billing details: You are billed based on the number of images successfully generated. Failed model calls or processing errors incur no charges and do not consume the free quota for new users.

Error codes

If a model call fails and returns an error message, see Error codes to resolve the issue.

FAQ

Q: Why does the code example fail to run? A: Upgrade your SDK to the latest version. For update instructions, see Install the SDK.