QwenCloudBRASIL
Tradução de apoio para consulta. Código e identificadores técnicos preservados. Consultar referência original ↗

Wan v2 – Recuperar resultado da imagem

Verifique Wan estado da imagem

Verifique o status da tarefa e recupere as imagens geradas.

Estratégia de votação

  1. Envie uma tarefa através de Criar tarefa para receber um task_id.
  2. Faça pesquisas a cada 5 segundos até task_status é SUCCEEDED ou FAILED.
  3. Em caso de sucesso, recupere a imagem da resposta.

Diferenças no formato de resposta

O formato da resposta varia de acordo com o modelo:

Notas importantes

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:
  /tasks/{task_id}:
    get:
      operationId: getWanTextToImageTaskStatus
      summary: Query task result
      description: Query the status and result of an async task.
      parameters:
        - name: task_id
          in: path
          required: true
          description: Task identifier returned by the text-to-image creation endpoint.
          schema:
            type: string
      responses:
        "200":
          description: Task status retrieved successfully.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TaskStatusResponse"
              examples:
                SUCCEEDED (wan2.6):
                  summary: Task succeeded (wan2.6-t2i format)
                  value:
                    request_id: 815505c6-7c3d-49d7-b197-xxxxxx
                    output:
                      task_id: f470bbfd-d955-4165-935b-d35b8exxxxxx
                      task_status: SUCCEEDED
                      choices:
                        - finish_reason: stop
                          message:
                            role: assistant
                            content:
                              - image: https://dashscope-463f.oss-accelerate.aliyuncs.com/xxxxxx.png?Expires=xxxxxx
                                type: image
                      finished: true
                      submit_time: 2026-01-09 17:18:17.901
                      scheduled_time: 2026-01-09 17:18:17.941
                      end_time: 2026-01-09 17:18:45.544
                    usage:
                      image_count: 1
                      input_tokens: 0
                      output_tokens: 0
                      size: 1280*1280
                      total_tokens: 0
                SUCCEEDED (wan2.5 and earlier):
                  summary: Task succeeded (wan2.5 and earlier format)
                  value:
                    request_id: 9d634fda-5fe9-9968-a908-xxxxxx
                    output:
                      task_id: d35658e4-483f-453b-b8dc-xxxxxx
                      task_status: SUCCEEDED
                      results:
                        - url: https://dashscope-result-sgp.oss-ap-southeast-1.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 windows decorated with elegant carvings and a beautiful wooden door with a brass handle. Inside, various colorful flowers such as roses, tulips, and lilies are on display.
                      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
                FAILED:
                  summary: Task failed
                  value:
                    request_id: 7438d53d-6eb8-4596-8835-xxxxxx
                    output:
                      task_id: 966cebcd-dedc-4962-af88-xxxxxx
                      task_status: FAILED
                      code: InvalidParameter
                      message: The specified parameter is not valid.
                      task_metrics:
                        TOTAL: 1
                        SUCCEEDED: 0
                        FAILED: 1
                RUNNING:
                  summary: Task running
                  value:
                    request_id: c1209113-8437-424f-a386-xxxxxx
                    output:
                      task_id: 966cebcd-dedc-4962-af88-xxxxxx
                      task_status: RUNNING
                      task_metrics:
                        TOTAL: 1
                        SUCCEEDED: 0
                        FAILED: 0
                PENDING:
                  summary: Task pending
                  value:
                    request_id: c4f11410-ea42-4996-957d-9c82f9xxxxxx
                    output:
                      task_id: f470bbfd-d955-4165-935b-d35b8eexxxxxx
                      task_status: PENDING
        "400":
          description: Invalid request parameters.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DashScopeErrorResponse"
      x-codeSamples:
        - lang: curl
          label: cURL - Query task result
          source: |-
            # Replace {task_id} with the actual task ID from the submit response
            curl -X GET 'https://maas.qwencloudapi.com/api/v1/tasks/{task_id}' \
              -H "Authorization: Bearer $DASHSCOPE_API_KEY"
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.