Tradução de apoio para consulta. Código e identificadores técnicos preservados. Consultar referência original ↗
Wan T2I síncrono
Em tempo real Wan geração de texto para imagem
Obtenha uma chave de API e defini-lo como uma variável de ambiente. Se estiver usando o SDK, instale-o.
Este endpoint síncrono é para wan2.6-t2i apenas. Recupere imagens geradas diretamente em uma única solicitação, sem pesquisa.
Para wan2.5 e anteriores, ou processamento assíncrono, use o async submit ponto final.
Requisitos de versão do SDK
- DashScope Python SDK: Versão 1.25.7 ou posterior.
- DashScope Java SDK: Versão 2.22.6 ou posterior.
OpenAPI
openapi: 3.1.0
info:
title: Wan Text-to-Image V2 API
description: "Generate images from text prompts using the Wan text-to-image model family. Supports various artistic styles and realistic photographic effects to meet diverse creative needs. This API uses an asynchronous task pattern: submit a task with POST, then poll for results with GET."
version: 1.0.0
servers:
- url: https://maas.qwencloudapi.com/api/v1
description: Singapore
security:
- BearerAuth: []
paths:
/services/aigc/multimodal-generation/generation:
post:
operationId: createWanT2ISyncGeneration
summary: Generate images synchronously
description: Generate images synchronously using Wan2.6 model.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Wan26TextToImageRequest"
responses:
"200":
description: Image generated successfully.
content:
application/json:
schema:
$ref: "#/components/schemas/Wan26SyncResponse"
"400":
description: Invalid request parameters.
content:
application/json:
schema:
$ref: "#/components/schemas/DashScopeErrorResponse"
x-codeSamples:
- lang: curl
label: cURL - wan2.6-t2i (sync)
source: |-
curl --location 'https://maas.qwencloudapi.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"
}
}'
- lang: python
label: Python - wan2.6-t2i (sync, DashScope SDK)
source: |-
import os
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message
# SDK version 1.25.7 or later is required for wan2.6-t2i
dashscope.base_http_api_url = 'https://maas.qwencloudapi.com/api/v1'
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)
- lang: java
label: Java - wan2.6-t2i (sync, DashScope SDK)
source: |-
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 {
Constants.baseHttpApiUrl = "https://maas.qwencloudapi.com/api/v1";
}
// SDK version 2.22.6 or later is required for wan2.6-t2i
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());
}
}
}
components:
securitySchemes:
BearerAuth:
type: http
scheme: bearer
description: DashScope API Key. Create one in the [QwenCloud console](https://home.qwencloud.com/api-keys).
schemas:
Wan26TextToImageRequest:
type: object
description: Request body for wan2.6-t2i model. Uses the `messages` format in the `input` object.
required:
- model
- input
properties:
model:
type: string
description: The model name. For the wan2.6-t2i model, use `wan2.6-t2i`.
enum:
- wan2.6-t2i
example: wan2.6-t2i
input:
type: object
description: The input object containing the message array.
required:
- messages
properties:
messages:
type: array
description: An array for the request content. Only single-turn conversations are supported (one set of role and content).
items:
type: object
required:
- role
- content
properties:
role:
type: string
description: The role of the message. Must be `user`.
enum:
- user
content:
type: array
description: An array for the message content.
items:
type: object
required:
- text
properties:
text:
type: string
description: The positive prompt describing the content, style, and composition of the image to generate. Chinese and English are supported. Maximum 2,100 characters. Only one text is allowed per request.
example: A flower shop with exquisite windows, a beautiful wooden door, and flowers on display
parameters:
$ref: "#/components/schemas/Wan26Parameters"
WanLegacyTextToImageRequest:
type: object
description: "Request body for wan2.5 and earlier models. Uses the `prompt` format in the `input` object. **Note**: These models use the endpoint `POST /services/aigc/text2image/image-synthesis` instead of the main endpoint."
required:
- model
- input
properties:
model:
type: string
description: "The model name. Supported models: `wan2.5-t2i-preview`, `wan2.2-t2i-plus`, `wan2.2-t2i-flash`, `wan2.1-t2i-plus`, `wan2.1-t2i-turbo`."
enum:
- wan2.5-t2i-preview
- wan2.2-t2i-plus
- wan2.2-t2i-flash
- wan2.1-t2i-plus
- wan2.1-t2i-turbo
example: wan2.5-t2i-preview
input:
type: object
description: The input object containing the prompt string.
required:
- prompt
properties:
prompt:
type: string
description: "The positive prompt describing the desired image content. Chinese and English are supported. Maximum length varies by model: wan2.5-t2i-preview (2,000 chars), wan2.2, wan2.1 series (500 chars)."
example: A flower shop with exquisite windows, a beautiful wooden door, and flowers on display
negative_prompt:
type: string
description: Optional. Describes content you do not want in the image. Maximum 500 characters. Chinese and English supported.
example: low resolution, low quality, deformed limbs
parameters:
$ref: "#/components/schemas/WanLegacyParameters"
Wan26Parameters:
type: object
description: Parameters for wan2.6-t2i model.
properties:
negative_prompt:
type: string
description: "Optional. Describes content you do not want in the image. Maximum 500 characters. Chinese and English supported. Example: low resolution, low quality, deformed limbs, deformed fingers, oversaturated, waxy, no facial details, overly smooth, AI-like, chaotic composition, blurry text, distorted text."
size:
type: string
description: "The resolution of the output image in `width*height` format. Default: `1280*1280`. The total number of pixels must be between `1280*1280` and `1440*1440`, and the aspect ratio must be between 1:4 and 4:1. Recommended resolutions: 1:1 (`1280*1280`), 3:4 (`1104*1472`), 4:3 (`1472*1104`), 9:16 (`960*1696`), 16:9 (`1696*960`)."
default: 1280*1280
example: 1280*1280
n:
type: integer
description: "The number of images to generate. Value: 1 to 4. Default: `4`. Note: billing is per image (Cost = Unit price x Number of images). Set to 1 for testing."
minimum: 1
maximum: 4
default: 4
prompt_extend:
type: boolean
description: "Whether to enable prompt rewriting. When enabled, this feature uses an LLM to optimize the positive prompt, significantly improving results for shorter prompts but adding a few seconds to processing time. Default: `true`. 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."
default: true
watermark:
type: boolean
description: 'Whether to add a watermark in the lower-right corner of the image with the text "AI-generated". Default: `false`.'
default: false
seed:
type: integer
description: "Optional. Random number seed. Range: [0, 2147483647]. Using the same seed produces more consistent results, but identical results are not guaranteed. If not provided, the system uses a random number."
minimum: 0
maximum: 2147483647
WanLegacyParameters:
type: object
description: Parameters for wan2.5 and earlier models.
properties:
size:
type: string
description: "The resolution of the output image in `width*height` format. Model wan2.5-t2i-preview defaults to `1280*1280` (total pixels `1280*1280`–`1440*1440`, aspect ratio 1:4–4:1). Models wan2.2 and earlier default to `1024*1024` (dimensions 512–1440, max `1440*1440`). Recommended resolutions for wan2.5 include: 1:1 (`1280*1280`), 3:4 (`1104*1472`), 4:3 (`1472*1104`), 9:16 (`960*1696`), 16:9 (`1696*960`)."
example: 1280*1280
n:
type: integer
description: "The number of images to generate. Value: 1 to 4. Default: `4`. Billing is per image."
minimum: 1
maximum: 4
default: 4
prompt_extend:
type: boolean
description: "Whether to enable prompt rewriting. When enabled, this feature uses an LLM to optimize the positive prompt, significantly improving results for shorter prompts but adding a few seconds to processing time. Default: `true`. 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."
default: true
watermark:
type: boolean
description: 'Whether to add a watermark in the lower-right corner of the image with the text "AI-generated". Default: `false`.'
default: false
seed:
type: integer
description: "Optional. Random number seed. Range: [0, 2147483647]. Using the same seed produces more consistent results, but identical results are not guaranteed. If not provided, the system uses a random number."
minimum: 0
maximum: 2147483647
Wan26SyncResponse:
type: object
description: Synchronous response for wan2.6-t2i model.
example:
output:
choices:
- finish_reason: stop
message:
content:
- image: https://dashscope-463f.oss-accelerate.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-xxxxxx
properties:
output:
type: object
properties:
choices:
type: array
description: List of generated results.
items:
type: object
properties:
finish_reason:
type: string
description: "`stop` indicates normal completion."
example: stop
message:
type: object
properties:
role:
type: string
description: Always `assistant`.
enum:
- assistant
content:
type: array
description: Response content array containing generated image URLs.
items:
type: object
properties:
image:
type: string
description: URL of the generated image (PNG). **Valid for 24 hours.** Download promptly.
type:
type: string
description: Content type. Always `image`.
enum:
- image
finished:
type: boolean
description: Whether the generation has completed.
usage:
type: object
description: Usage statistics.
properties:
image_count:
type: integer
description: Number of images generated.
input_tokens:
type: integer
description: Number of input tokens. Currently fixed at 0.
output_tokens:
type: integer
description: Number of output tokens. Currently fixed at 0.
size:
type: string
description: Resolution of the generated image(s).
total_tokens:
type: integer
description: Total tokens consumed. Currently fixed at 0.
request_id:
type: string
description: Unique request identifier for tracing and troubleshooting.
AsyncTaskSubmitResponse:
type: object
description: Response returned when an asynchronous task is created successfully.
properties:
request_id:
type: string
description: Unique request identifier for troubleshooting.
output:
type: object
properties:
task_id:
type: string
description: The task identifier. Use this to query the task status via `GET /tasks/{task_id}`. Valid for 24 hours.
task_status:
type: string
description: The initial task status. Typically `PENDING`.
enum:
- PENDING
TaskStatusResponse:
type: object
description: Response returned when querying task status. The output format depends on the model used.
properties:
request_id:
type: string
description: Unique request identifier for troubleshooting.
output:
type: object
description: Task output information.
properties:
task_id:
type: string
description: The task identifier.
task_status:
type: string
description: The current task status.
enum:
- PENDING
- RUNNING
- SUCCEEDED
- FAILED
- CANCELLED
choices:
type: array
description: Output content (wan2.6-t2i format). Returned when task_status is SUCCEEDED.
items:
type: object
properties:
finish_reason:
type: string
description: The reason the task stopped. `stop` indicates normal completion.
message:
type: object
properties:
role:
type: string
description: The role. Always `assistant`.
content:
type: array
items:
type: object
properties:
image:
type: string
description: The generated image URL. Valid for 24 hours.
type:
type: string
description: Content type. Always `image`.
results:
type: array
description: Output content (wan2.5 and earlier format). Returned when task_status is SUCCEEDED.
items:
type: object
properties:
url:
type: string
description: The generated image URL. Valid for 24 hours.
orig_prompt:
type: string
description: The original input prompt.
actual_prompt:
type: string
description: The optimized prompt used for generation (returned only when prompt rewriting is enabled).
code:
type: string
description: Error code (returned only for failed individual results).
message:
type: string
description: Error message (returned only for failed individual results).
finished:
type: boolean
description: Whether the task has finished (wan2.6 format).
submit_time:
type: string
description: Task submission time.
scheduled_time:
type: string
description: Task scheduled time.
end_time:
type: string
description: Task completion time.
task_metrics:
type: object
description: Statistics for the task results.
properties:
TOTAL:
type: integer
description: The total number of tasks.
SUCCEEDED:
type: integer
description: The number of successful tasks.
FAILED:
type: integer
description: The number of failed tasks.
code:
type: string
description: Error code (returned only when the task fails).
message:
type: string
description: Error message (returned only when the task fails).
usage:
type: object
description: Usage statistics. Only successful results are counted.
properties:
image_count:
type: integer
description: "The number of images successfully generated. Billing formula: Fee = Number of images x Unit price."
size:
type: string
description: The resolution of the generated images.
input_tokens:
type: integer
description: Number of input tokens (wan2.6 format).
output_tokens:
type: integer
description: Number of output tokens (wan2.6 format).
total_tokens:
type: integer
description: Total number of tokens (wan2.6 format).
DashScopeErrorResponse:
type: object
description: Error response returned when a request fails.
properties:
code:
type: string
description: The error code.
message:
type: string
description: A detailed error message.
request_id:
type: string
description: The unique request ID for troubleshooting.