Skip to main content
Wan

Wan text-to-image V2 API reference

The Wan text-to-image model generates images from text prompts, supporting artistic styles and realistic photographic effects.

Quick links: Try online (Singapore | Virginia | Beijing) | Wan official website
Wan website features may differ from API capabilities. This document covers the API and is updated as changes occur.

Prerequisites

Before making a call, get an API key and export the API key as an environment variable. To make calls using the SDK, install the DashScope SDK.
The Singapore, US (Virginia), and China (Beijing) regions have separate API keys and request endpoints. They cannot be used interchangeably. Cross-region calls lead to authentication failures or service errors. For more information, see Select a region and service deployment scope.

HTTP synchronous (wan2.6)

The API in this section uses the new protocol and supports only the wan2.6 model.
Retrieve the result in a single request. Recommended for most use cases.
  • Singapore
  • US (Virginia)
  • China (Beijing)
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) supports only asynchronous calls .

Request parameters

  • Text-to-image
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-t2i",
        "input": {
            "messages": [
                {
                    "role": "user",
                    "content": [
                        {
                            "text": "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display"
                        }
                    ]
                }
            ]
        },
        "parameters": {
            "prompt_extend": true,
            "watermark": false,
            "n": 1,
            "negative_prompt": "",
            "size": "1280*1280"
        }
    }'
Request headers
Content-Type string (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.
Request body
model string (Required)The model name. Example: wan2.6-t2i.
For wan2.5 and earlier models, see HTTP asynchronous call for HTTP calls.
input object (Required)The input object.

Properties

messages array (Required)The request messages. Currently, only single-turn conversations are supported: pass one set of role and content parameters.

Properties

role string (Required)The message role. Must be set to user.content array (Required)The message content array.

Properties

text string(Required)The positive prompt describing the desired content, style, and composition of the generated image.Supports Chinese and English, with a maximum length of 2,100 characters. Each Chinese character, letter, number, or symbol counts as one character. Excess characters are automatically truncated.Example: A sitting orange cat, happy, lively, and cute, realistic and accurate.Note: Only one text input is supported. An error will occur if you do not provide a text input or if you provide multiple text inputs.
parameters object (Optional)Image generation parameters.

Properties

negative_prompt string (optional)A negative prompt describing what you do not want in the image.Supports Chinese and English. Maximum length is 500 characters. Excess characters are truncated automatically.Example: Low resolution, low quality, distorted limbs, malformed fingers, oversaturated colors, wax-like appearance, no facial details, overly smooth surfaces, AI-generated look. Chaotic composition. Blurry or distorted text.size string (Optional)The resolution of the output image, in the format width*height.
  • The default value is 1280*1280.
  • The total pixels must be between 1280×1280 and 1440×1440, with an aspect ratio between 1:4 and 4:1. For example, 768×2700 is a valid resolution.
Example: 1280*1280.

Recommended resolutions for common aspect ratios

n integer (Optional)
The value of n directly affects the cost. Cost = Unit Price × Number of Images. Before you call the API, confirm the model pricing.
The number of images to generate. The value must be an integer from 1 to 4. The default is 4.Billing is based on the number of images generated. Set to 1 for testing.prompt_extend bool (Optional)Enables prompt rewriting. An LLM optimizes the positive prompt to improve results, especially for shorter prompts. Adds 3-4 seconds to processing time.
  • true (default)
  • false
When prompt rewriting is enabled, the rewritten prompt may introduce copyrighted content and trigger content moderation, which returns an IPInfringementSuspect or DataInspectionFailed error. If you receive either error, set prompt_extend to false and try again. If the prompt itself explicitly names a copyrighted character or work, disabling prompt rewriting does not resolve the issue and you must revise the prompt.
watermark bool (Optional)Adds an "AI Generated" watermark to the lower-right corner of the image.
  • false (default)
  • true
seed integer (optional)Random number seed. Valid range: [0,2147483647].Using the same seed yields similar outputs. If omitted, the algorithm uses a random seed.Note: Image generation is probabilistic. Even with the same seed, results may vary.

Response parameters

  • Successful task execution
  • Task execution failed
Task data (task status and image URLs) is retained for only 24 hours and then automatically purged. Save generated images promptly.
{
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxx.png?Expires=xxx",
                            "type": "image"
                        }
                    ],
                    "role": "assistant"
                }
            }
        ],
        "finished": true
    },
    "usage": {
        "image_count": 1,
        "input_tokens": 0,
        "output_tokens": 0,
        "size": "1280*1280",
        "total_tokens": 0
    },
    "request_id": "815505c6-7c3d-49d7-b197-xxxxx"
}
output objectThe output object.

Properties

choices arrayThe output content generated by the model.

Properties

finish_reason stringThe reason the task stopped. stop indicates normal completion.message objectThe message returned by the model.

Properties

role stringThe message role, fixed as assistant.content array

Properties

image stringThe URL of the generated image in PNG format. Valid for 24 hours. Download and save the image promptly.type stringThe output type, fixed as image.
finished booleanWhether the task has finished.
  • true
  • false
usage objectUsage statistics for the request. Only successful results are counted.

Properties

image_count integerThe number of generated images.size stringThe resolution of the generated image. Example: 1280*1280.input_tokens integerThe number of input tokens. For text-to-image, billing is based on the number of images, so this value is fixed at 0.output_tokens integerThe number of output tokens. For text-to-image, billing is based on the number of images, so this value is fixed at 0.total_tokens integerThe total number of tokens. For text-to-image, billing is based on the number of images, so this value is fixed at 0.
request_id 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.

HTTP asynchronous (wan2.6)

The API in this section uses the new protocol and supports only the wan2.6 model.
The task flow includes two core steps: Create task -> Poll for result. The process is as follows:

Step 1: Create a task and get the task ID

  • Singapore
  • US (Virginia)
  • China (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, use the returned task_id to query the result. The task_id is valid for 24 hours. Do not create duplicate tasks. Instead, use polling to retrieve the result.
  • For guidance for beginners, see Call APIs with Postman or cURL.

Request parameters

  • Text-to-image
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-t2i",
        "input": {
            "messages": [
                {
                    "role": "user",
                    "content": [
                        {
                            "text": "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display"
                        }
                    ]
                }
            ]
        },
        "parameters": {
            "prompt_extend": true,
            "watermark": false,
            "n": 1,
            "negative_prompt": "",
            "size": "1280*1280"
        }
    }'
Request headers
Content-Type string (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.
If this request header is missing, the error "current user api does not support synchronous calls" is returned.
Request body
model string (Required)The model name. Example: wan2.6-t2i.
For wan2.5 and earlier models, see HTTP asynchronous call.
input object (Required)The input object.

Properties

messages array (Required)The request messages. Currently, only single-turn conversations are supported: pass one set of role and content parameters.

Properties

role string (Required)The message role. Must be set to user.content array (Required)The message content array.

Properties

text string(Required)The positive prompt describing the desired content, style, and composition of the generated image.Supports Chinese and English, with a maximum length of 2,100 characters. Each Chinese character, letter, number, or symbol counts as one character. Excess characters are automatically truncated.Example: A flower shop with exquisite windows, a beautiful wooden door, and flowers on display.Note: Only one text input is supported. An error will occur if you do not provide a text input or if you provide multiple text inputs.
parameters object (Optional)Image generation parameters.

Properties

negative_prompt string (optional)A negative prompt describing what you do not want in the image.Supports Chinese and English. Maximum length is 500 characters. Excess characters are truncated automatically.Example: Low resolution, low quality, distorted limbs, malformed fingers, oversaturated colors, wax-like appearance, no facial details, overly smooth surfaces, AI-generated look. Chaotic composition. Blurry or distorted text.size string (Optional)The resolution of the output image, in the format width*height.
  • The default value is 1280*1280.
  • The total pixels must be between 1280×1280 and 1440×1440, with an aspect ratio between 1:4 and 4:1. For example, 768×2700 is a valid resolution.
Example: 1280*1280.

Recommended resolutions for common aspect ratios

n integer (Optional)
The value of n directly affects the cost. Cost = Unit Price × Number of Images. Before you call the API, confirm the model pricing.
The number of images to generate. The value must be an integer from 1 to 4. The default is 4.Billing is based on the number of images generated. Set to 1 for testing.prompt_extend bool (Optional)Enables prompt rewriting. An LLM optimizes the positive prompt to improve results, especially for shorter prompts. Adds 3-4 seconds to processing time.
  • true (default)
  • false
When prompt rewriting is enabled, the rewritten prompt may introduce copyrighted content and trigger content moderation, which returns an IPInfringementSuspect or DataInspectionFailed error. If you receive either error, set prompt_extend to false and try again. If the prompt itself explicitly names a copyrighted character or work, disabling prompt rewriting does not resolve the issue and you must revise the prompt.
watermark bool (Optional)Adds an "AI Generated" watermark to the lower-right corner of the image.
  • false (default)
  • true
seed integer (optional)Random number seed. Valid range: [0,2147483647].Using the same seed yields similar outputs. If omitted, the algorithm uses a random seed.Note: Image generation is probabilistic. Even with the same seed, results may vary.

Response parameters

  • Successful response
  • Error response
Save the task_id to query the task status and result.
{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}
output objectThe output object.

Properties

task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.

Enumeration values

  • PENDING
  • RUNNING
  • SUCCEEDED
  • FAILED
  • CANCELED
  • UNKNOWN: The task does not exist or its status is unknown.
request_id 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.

Step 2: Query the result by task ID

  • Singapore
  • US (Virginia)
  • China (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 recommendation: Image generation is time-consuming. Use a polling mechanism with a reasonable interval, such as 10 seconds.
  • Task state transition: PENDING → RUNNING → SUCCEEDED or FAILED.
  • Result link: After a task succeeds, an image URL valid for 24 hours is returned. Download and save the image to permanent storage, such as OSS.

Request parameters

  • Query task result
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.
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Request headers
Authorization string (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.
URL path parameters
task_id string (Required)The ID of the task.

Response parameters

  • Successful task execution
  • Task execution failed
Task data (task status and image URLs) is retained for only 24 hours and then automatically purged. Save generated images promptly.
{
    "request_id": "2ddf53fa-699a-4267-9446-xxxxxx",
    "output": {
        "task_id": "3cd3fa4e-53ee-4136-9cab-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-12-18 20:03:01.802",
        "scheduled_time": "2025-12-18 20:03:01.834",
        "end_time": "2025-12-18 20:03:29.260",
        "finished": true,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx.png?Expires=xxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "size": "1280*1280",
        "total_tokens": 0,
        "image_count": 1,
        "output_tokens": 0,
        "input_tokens": 0
    }
}
output objectThe task output information.

Properties

task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.

Enumeration values

  • PENDING
  • RUNNING
  • SUCCEEDED
  • FAILED
  • CANCELED
  • UNKNOWN: The task does not exist or its status is unknown.
State transitions during polling:
  • PENDING → RUNNING → SUCCEEDED or FAILED.
  • The initial query status is usually PENDING or RUNNING.
  • When the status changes to SUCCEEDED, the response contains the generated image URL.
  • If the status is FAILED, check the error message and retry the task.
submit_time stringThe time when the task was submitted. The time is in UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.scheduled_time stringThe time when the task was executed. The time is in UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.end_time stringThe time when the task was completed. The time is in UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.finished booleanIndicates whether the task is finished.
  • true
  • false
choices arrayThe output content generated by the model.

Properties

finish_reason stringThe reason the task stopped. stop indicates normal completion.message objectThe message returned by the model.

Properties

role stringThe role of the message, which is fixed as assistant.content array

Properties

image stringThe URL of the generated image in PNG format.The link is valid for 24 hours. You must download and save the image promptly.type stringThe type of output, which is fixed as image.
usage objectUsage statistics for the request. Only successful results are counted.

Properties

image_count integerThe number of generated images.size stringThe resolution of the generated image. Example: 1280*1280.input_tokens integerThe number of input tokens. This value is currently fixed at 0.output_tokens integerThe number of output tokens. This value is currently fixed at 0.total_tokens integerThe total number of tokens. This value is currently fixed at 0.
request_id 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.

HTTP asynchronous (wan2.5 and earlier models)

This API uses the old protocol and supports only wan2.5 and earlier models.
Because text-to-image tasks can take significant time (typically 1 to 2 minutes), the API uses an asynchronous call. The flow includes two core steps: Create task -> Poll for result. The process is as follows:
Processing time depends on the task queue and service status.

Step 1: Create a task and get the task ID

  • Singapore
  • Beijing
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis
  • After the task is created, use the returned task_id to query the result. The task_id is valid for 24 hours. Do not create duplicate tasks. Instead, use polling to retrieve the result.
  • For guidance for beginners, see Call APIs with Postman or cURL.

Request parameters

  • Text-to-image
  • Text-to-image (with negative prompt)
The API keys for the Singapore and Beijing regions are different. Obtain an API key
The following is the URL for the Singapore region. If you are using a model in the Beijing region, replace the URL with: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis
Replace {WorkspaceId} with your actual workspace ID.
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.5-t2i-preview",
    "input": {
        "prompt": "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display"
    },
    "parameters": {
        "size": "1280*1280",
        "n": 1
    }
}'
Request headers
Content-Type string (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.
If this request header is missing, the error "current user api does not support synchronous calls" is returned.
Request body
model string (Required)The model name. For text-to-image models, see Model List.Example: wan2.5-t2i-preview.
For HTTP calls to the wan2.6 model, see HTTP synchronous call and HTTP asynchronous call.
input object (Required)The input object containing the prompt.

Properties

prompt string (Required)The positive prompt describing the desired content and style of the generated image.This parameter supports Chinese and English. Each Chinese character, letter, or punctuation mark counts as one character. Excess characters are automatically truncated. The length limit varies by model version:
  • wan2.5-t2i-preview: Maximum length of 2000 characters.
  • wan2.2 and wan2.1 series models: Maximum length of 500 characters.
  • wanx2.0-t2i-turbo: Maximum length of 800 characters.
Example: A sitting orange cat, happy, lively, and cute, realistic and accurate.For tips on using prompts, see Text-to-image Prompt Guide.negative_prompt string (Optional)The negative prompt specifying content to exclude from the image. Use this to constrain the output.This parameter supports Chinese and English, with a maximum length of 500 characters. Excess characters are automatically truncated.Example: low resolution, error, worst quality, low quality, mutilated, extra fingers, bad proportions, etc.
parameters object (Optional)The image generation parameters.

Properties

size string (Optional)The resolution of the output image, in the format width*height. The default value and constraints vary by model version:
  • wan2.5-t2i-preview: The default value is 1280*1280. The total pixels must be between 1280×1280 and 1440×1440, with an aspect ratio between 1:4 and 4:1. For example, 768×2700 is a valid resolution.
  • wan2.2 and earlier models: The default value is 1024*1024. The image width and height must be between 512 and 1440, with a maximum resolution of 1440×1440. For example, 768×2700 exceeds the single-side limit and is not supported.
Example: 1280*1280.

Recommended resolutions for common aspect ratios

n integer (Optional)
The value of n directly affects the cost. Cost = Unit Price × Number of Images. Before you call the API, confirm the model pricing.
The number of images to generate. The value must be an integer from 1 to 4. The default is 4. Set to 1 for testing.prompt_extend boolean (Optional)Enables prompt rewriting. An LLM rewrites the input prompt to improve results, especially for shorter prompts. Increases processing time.
  • true (default)
  • false
When prompt rewriting is enabled, the rewritten prompt may introduce copyrighted content and trigger content moderation, which returns an IPInfringementSuspect or DataInspectionFailed error. If you receive either error, set prompt_extend to false and try again. If the prompt itself explicitly names a copyrighted character or work, disabling prompt rewriting does not resolve the issue and you must revise the prompt.
watermark boolean (Optional)Adds an "AI Generated" watermark to the lower-right corner of the image.
  • false (default)
  • true
seed integer (optional)Random number seed. Valid range: [0,2147483647].Using the same seed yields similar outputs. If omitted, the algorithm uses a random seed.Note: Image generation is probabilistic. Even with the same seed, results may vary.

Response parameters

  • Successful response
  • Error response
Save the task_id to query the task status and result.
{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}
output objectThe task output information.

Properties

task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.

Enumeration values

  • PENDING
  • RUNNING
  • SUCCEEDED
  • FAILED
  • CANCELED
  • UNKNOWN: The task does not exist or its status is unknown.
request_id 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.

Step 2: Query the result by task ID

  • Singapore
  • China (Beijing)
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}When calling, replace {WorkspaceId} with your actual workspace ID.
  • Polling recommendation: Image generation is time-consuming. Use a polling mechanism with a reasonable interval, such as 10 seconds.
  • Task state transition: PENDING → RUNNING → SUCCEEDED or FAILED.
  • Result link: After a task succeeds, an image URL valid for 24 hours is returned. Download and save the image to permanent storage, such as OSS.

Request parameters

  • Query task result
Replace 86ecf553-d340-4e21-xxxxxxxxx with your actual task_id.
API keys are different for each region. For more information, see Obtain an API key.
If you use a model in the China (Beijing) region, replace base_url with https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx, where {WorkspaceId} is your actual workspace ID.
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Request headers
Authorization string (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.
URL path parameters
task_id string (Required)The ID of the task.

Response parameters

  • Successful task execution
  • Task failed
  • Partial task failure
  • Task query expired
Image URLs are valid for only 24 hours and then automatically purged. Save generated images promptly.
{
    "request_id": "f767d108-7d50-908b-a6d9-xxxxxx",
    "output": {
        "task_id": "d492bffd-10b5-4169-b639-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-01-08 16:03:59.840",
        "scheduled_time": "2025-01-08 16:03:59.863",
        "end_time": "2025-01-08 16:04:10.660",
        "results": [
            {
                "orig_prompt": "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display",
                "actual_prompt": "A flower shop with exquisitely carved windows and a beautiful dark wooden door with a brass handle. Inside, various flowers are displayed, including roses, lilies, and sunflowers, which are colorful and vibrant. The background is a warm indoor scene, with light visible from the street through the window. High-definition realistic photography, medium shot composition.",
                "url": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/1.png"
            }
        ],
        "task_metrics": {
            "TOTAL": 1,
            "SUCCEEDED": 1,
            "FAILED": 0
        }
    },
    "usage": {
        "image_count": 1
    }
}
output objectThe task output information.

Properties

task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.

Enumeration values

  • PENDING
  • RUNNING
  • SUCCEEDED
  • FAILED
  • CANCELED
  • UNKNOWN: The task does not exist or its status is unknown.
State transitions during polling:
  • PENDING → RUNNING → SUCCEEDED or FAILED.
  • The initial query status is usually PENDING or RUNNING.
  • When the status changes to SUCCEEDED, the response contains the generated image URL.
  • If the status is FAILED, check the error message and retry the task.
submit_time stringThe time when the task was submitted. The time is in UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.scheduled_time stringThe time when the task was executed. The time is in UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.end_time stringThe time when the task was completed. The time is in UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.results array of objectA list of task results. This includes image URLs, prompts, and error messages for partially failed tasks.
{
    "results": [
        {
            "orig_prompt": "",
            "actual_prompt": "",
            "url": ""
        },
        {
            "code": "",
            "message": ""
        }
    ]
}

Properties

orig_prompt stringThe original input prompt, corresponding to the request parameter prompt.actual_prompt stringThe optimized prompt used when prompt rewriting is enabled. Not returned when disabled.url stringThe image URL. This is returned only when task_status is SUCCEEDED. The link is valid for 24 hours and can be used to download the image.code stringError code. Returned only for failed requests. See Error codes.message stringDetailed error message. Returned only for failed requests. See Error codes.
task_metrics objectStatistics for the task result.

Properties

TOTAL integerThe total number of tasks.SUCCEEDED integerThe number of successful tasks.FAILED integerThe number of failed tasks.
code stringError code. Returned only for failed requests. See Error codes.message stringDetailed error message. Returned only for failed requests. See Error codes.
usage objectUsage statistics for the request. Only successful results are counted.

Properties

image_count integerNumber of images successfully generated. Billing: Cost = Number of images × Unit price.
request_id stringUnique request identifier for tracing and troubleshooting.

DashScope Python SDK

The SDK parameter names align with the HTTP API, with structures adapted for Python. Because text-to-image tasks can take significant time, the SDK encapsulates the HTTP asynchronous call process and supports both synchronous and asynchronous calls.
Processing time depends on the task queue and service status.

wan2.6

  • The following code is only for the wan2.6 model.
  • Make sure your DashScope Python SDK version is at least 1.25.7 before you run the following code. To update, see Install the SDK.
The base_url and API key are region-specific. The following example shows a call in the Singapore region:
  • Singapore
  • US (Virginia)
  • China (Beijing)
  • Germany (Frankfurt)
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1When calling, replace {WorkspaceId} with your actual workspace ID.
The global deployment scope (Frankfurt region) supports only asynchronous calls.
  • Synchronous call
  • Asynchronous call
Request example
import os
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message

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

# If you have not configured an environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
# The API key is region-specific. To obtain an API key: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

message = Message(
    role="user",
    content=[
        {
            'text': 'A flower shop with exquisite windows, a beautiful wooden door, and flowers on display'
        }
    ]
)
print("----Sync call, please wait a moment----")
rsp = ImageGeneration.call(
    model="wan2.6-t2i",
    api_key=api_key,
    messages=[message],
    negative_prompt="",
    prompt_extend=True,
    watermark=False,
    n=1,
    size="1280*1280"
)
print(rsp)
Response example
The URL is valid for 24 hours. You must download the image promptly.
{
    "status_code": 200,
    "request_id": "820dd0db-eb42-4e05-8d6a-1ddb4axxxxxx",
    "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": "1280*1280",
        "total_tokens": 0
    }
}

wan2.5 and earlier models

  • The following code is only for wan2.5 and earlier models.
  • Make sure your DashScope Python SDK version is at least 1.25.2 before you run the following code. If the version is too low, errors such as "url error, please check url!" may occur. To update, see Install the SDK.
The base_url and API key are region-specific. The following example shows a call in the Singapore region:
  • Singapore
  • China (Beijing)
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1When calling, replace {WorkspaceId} with your actual workspace ID.
  • Synchronous call
  • Asynchronous call
Request example
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
import dashscope

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

# If you have not configured an environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
# The API keys for the Singapore and Beijing regions are different. To obtain an API key: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

print('----Sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=api_key,
                          model="wan2.5-t2i-preview",
                          prompt="A flower shop with exquisite windows, a beautiful wooden door, and flowers on display",
                          negative_prompt="",
                          n=1,
                          size='1280*1280',
                          prompt_extend=True,
                          watermark=False,
                          seed=12345)
print('response: %s' % rsp)
if rsp.status_code == HTTPStatus.OK:
    # Save the image in the current directory
    for result in rsp.output.results:
        file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
        with open('./%s' % file_name, 'wb+') as f:
            f.write(requests.get(result.url).content)
else:
    print('sync_call Failed, status_code: %s, code: %s, message: %s' %
          (rsp.status_code, rsp.code, rsp.message))
Response example
The URL is valid for 24 hours. You must download the image promptly.
{
    "status_code": 200,
    "request_id": "9d634fda-5fe9-9968-a908-xxxxxx",
    "code": null,
    "message": "",
    "output": {
        "task_id": "d35658e4-483f-453b-b8dc-xxxxxx",
        "task_status": "SUCCEEDED",
        "results": [{
            "url": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/1.png",
            "orig_prompt": "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display",
            "actual_prompt": "An exquisite flower shop, with elegant carvings on the windows and a beautiful wooden door with a brass handle. Inside, a variety of colorful flowers such as roses, tulips, and lilies are displayed. The background is a warm indoor scene with soft light, creating a peaceful and comfortable atmosphere. High-definition realistic photography, close-up center composition."
        }],
        "submit_time": "2025-01-08 19:36:01.521",
        "scheduled_time": "2025-01-08 19:36:01.542",
        "end_time": "2025-01-08 19:36:13.270",
        "task_metrics": {
            "TOTAL": 1,
            "SUCCEEDED": 1,
            "FAILED": 0
        }
    },
    "usage": {
        "image_count": 1
    }
}

DashScope Java SDK

The SDK parameter names align with the HTTP API, with structures adapted for Java. Text-to-image tasks can take significant time. The SDK encapsulates the HTTP asynchronous call flow and supports both synchronous and asynchronous calls.
Processing time depends on the task queue and service status.

wan2.6

  • The following code applies only to the wan2.6-t2i model.
  • Make sure that your DashScope Java SDK version is 2.22.6 or later before you run the following code.
The base_url and API key are specific to each region and cannot be used interchangeably. The following examples show how to make a call in the Singapore region:
  • Singapore
  • US (Virginia)
  • China (Beijing)
  • Germany (Frankfurt)
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1When calling, replace {WorkspaceId} with your actual workspace ID.
The global deployment scope (Frankfurt region) supports only asynchronous calls.
  • 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.Collections;

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"
    // The API key is different for each region. To get an API key: https://www.alibabacloud.com/help/en/model-studio/get-api-key
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void basicCall() throws ApiException, NoApiKeyException, UploadFileException {
        ImageGenerationMessage message = ImageGenerationMessage.builder()
                .role("user")
                .content(Collections.singletonList(
                        Collections.singletonMap("text", "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display")
                )).build();

        ImageGenerationParam param = ImageGenerationParam.builder()
                .apiKey(apiKey)
                .model("wan2.6-t2i")
                .n(1)
                .size("1280*1280")
                .negativePrompt("")
                .promptExtend(true)
                .watermark(false)
                .messages(Collections.singletonList(message))
                .build();

        ImageGeneration imageGeneration = new ImageGeneration();
        ImageGenerationResult result = null;
        try {
            System.out.println("---sync call, 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. You must download the image promptly.
{
    "status_code": 200,
    "request_id": "50b57166-eaaa-4f17-b1e0-35a5ca88672c",
    "code": "",
    "message": "",
    "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
    },
    "usage": {
        "input_tokens": 0,
        "output_tokens": 0,
        "image_count": 1,
        "size": "1280*1280",
        "total_tokens": 0
    }
}

wan2.5 and earlier models

  • The following code applies only to wan2.5 and earlier models.
  • Make sure that your DashScope Java SDK version is 2.22.2 or later before you run the following code. If your version is too old, errors such as "url error, please check url!" may occur. See Install the SDK to update.
The base_url and API key are specific to each region and cannot be used interchangeably. The following examples show how to make a call in the Singapore region:
  • Singapore
  • China (Beijing)
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1When calling, replace {WorkspaceId} with your actual workspace ID.
  • Synchronous call
  • Asynchronous call
Request example
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisListResult;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;

import java.util.HashMap;
import java.util.Map;

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"
  // The API keys for the Singapore and Beijing regions are different. To get an API key: https://www.alibabacloud.com/help/en/model-studio/get-api-key
  static String apiKey = System.getenv("DASHSCOPE_API_KEY");

  public static void basicCall() throws ApiException, NoApiKeyException {
        // Set the parameters
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("prompt_extend", true);
        parameters.put("watermark", false);
        parameters.put("seed", 12345);

        ImageSynthesisParam param =
                ImageSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.5-t2i-preview")
                        .prompt("A flower shop with exquisite windows, a beautiful wooden door, and flowers on display")
                        .n(1)
                        .size("1280*1280")
                        .negativePrompt("")
                        .parameters(parameters)
                        .build();

        ImageSynthesis imageSynthesis = new ImageSynthesis();
        ImageSynthesisResult result = null;
        try {
            System.out.println("---sync call, please wait a moment----");
            result = imageSynthesis.call(param);
        } catch (ApiException | NoApiKeyException e){
            throw new RuntimeException(e.getMessage());
        }
        System.out.println(JsonUtils.toJson(result));
    }

    public static void listTask() throws ApiException, NoApiKeyException {
        ImageSynthesis is = new ImageSynthesis();
        AsyncTaskListParam param = AsyncTaskListParam.builder().build();
        param.setApiKey(apiKey);
        ImageSynthesisListResult result = is.list(param);
        System.out.println(result);
    }

    public static void fetchTask(String taskId) throws ApiException, NoApiKeyException {
        ImageSynthesis is = new ImageSynthesis();
        // If the DASHSCOPE_API_KEY environment variable is set, you can set apiKey to null.
        ImageSynthesisResult result = is.fetch(taskId, apiKey);
        System.out.println(result.getOutput());
        System.out.println(result.getUsage());
    }

    public static void main(String[] args){
        try{
            basicCall();
            //listTask();
        }catch(ApiException|NoApiKeyException e){
            System.out.println(e.getMessage());
        }
    }
}
Response example
The URL is valid for 24 hours. You must download the image promptly.
{
    "request_id": "22f9c744-206c-9a78-899a-xxxxxx",
    "output": {
        "task_id": "4a0f8fc6-03fb-4c44-a13a-xxxxxx",
        "task_status": "SUCCEEDED",
        "results": [{
           "orig_prompt": "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display",
            "actual_prompt": "A flower shop with exquisitely carved windows and a beautiful dark wooden door slightly ajar. A variety of fresh flowers, including roses, lilies, and sunflowers, are on display inside, vibrant in color and fragrant. The background is a cozy indoor scene with soft light streaming through the windows onto the flowers. High-definition realistic photography, medium shot composition.",
            "url": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/1.png"
        }],
        "task_metrics": {
            "TOTAL": 1,
            "SUCCEEDED": 1,
            "FAILED": 0
        }
    },
    "usage": {
        "image_count": 1
    }
}

Limitations

  • Data validity: The task task_id and image url are retained for only 24 hours. After this period, they cannot be queried or downloaded.
  • Content moderation: Both the input prompt and output image undergo content moderation. Non-compliant content returns an IPInfringementSuspect or DataInspectionFailed error. See Error codes.

Billing and rate limiting

  • Check free quotas and pricing in the console.
  • For model rate limiting, see Wan series.
  • Billing is based on the number of images successfully generated. Failed calls do not incur fees and do not consume the new user free quota.

Error codes

If the model call fails and returns an error message, see Error codes for resolution.

FAQ

Q: How do I view a model's inference costs and call volume? A: See Bill inquiry and cost management.
Text Generation
Video Generation
Audio
Realtime API
Text Embedding
Model Production