Image and text composition API reference

更新时间:
复制 MD 格式
Important

This model is scheduled to be deprecated. To avoid service disruptions, switch to another model.

You can use this model to generate a complete poster from a background image and text. The model automatically arranges the text on the image.

Related guide: Image and text composition

Model overview

Model name

Description

Price

Rate limiting

QPS limit

Concurrent tasks

wanx-ast

Input a background image and text to generate a complete poster. The model ensures a balanced text layout and harmonious color scheme, supports background images of any aspect ratio, and offers a variety of font pairings.

Free for a limited time

2

1

Prerequisites

Create an API key and export the API key as an environment variable.

HTTP call

Create task

POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis

Headers

Image and text composition

curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis' \
--header 'X-DashScope-Async: enable' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "model": "wanx-ast",
    "input": {
        "title": ["Lorem Ipsum"],
        "subtitle": ["Duis aute irure dolor in reprehenderit"],
        "text": ["VIEW NOW"],
        "image_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20240929/vbxgxc/2.png",
        "underlay": 1,
        "logo": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20240927/abtbdg/logo.png"
    },
    "parameters": {
        "n": 1,
        "temperature": 0.7
    }
}'

Content-Type string Required

The content type of the request. The value is fixed to application/json.

Authorization string Required

A Model Studio API key is recommended, but you can also use a DashScope API key. For example: Bearer d1xxx2a.

X-DashScope-Async string Required

Enables asynchronous processing. You must set this parameter to enable.

Request body

model string Required

The model to call.

input object Required

The background image, text elements, and other assets for the poster.

Properties

title array Required

The title text to add.

Constraints:

  • Number of strings: One or more. For example, ["Title 1"] or ["Title 1", "Title 2"].

  • Text length: No limit.

  • For best results, we recommend using no more than three titles, with each title containing no more than 30 characters.

subtitle array Optional

The subtitle text to add.

Constraints:

  • Number of strings: One or more. For example, ["Subtitle 1"] or ["Subtitle 1", "Subtitle 2"].

  • Text length: No limit.

  • For best results, we recommend using no more than three subtitles, with each subtitle containing no more than 30 characters.

text array Optional

Other text to add.

Constraints:

  • Number of strings: One or more. For example, ["Text 1"] or ["Text 1", "Text 2"].

  • Text length: No limit.

  • For best results, we recommend using no more than three text elements, with each element containing no more than 30 characters.

image_url string Required

The URL of the background image.

Image constraints:

  • Format: PNG and JPG are supported.

  • Resolution: Up to 3840 x 2160 pixels.

  • Aspect ratio: No limit.

  • Size: Up to 50 MB.

underlay integer Optional

The number of underlays. An underlay is a vector element displayed behind the text to improve readability and enrich the overall style.

The value must be an integer from 0 to 2. The default value is 0. For best results, we recommend setting this to 0 or 1.

logo string Optional

The URL of the logo image.

Image constraints:

  • Format: PNG is supported.

  • Resolution: Up to 1280 x 1280 pixels.

  • Size: Up to 5 MB.

  • Aspect ratio: No limit.

parameters object Required

Parameters that control image generation.

Properties

temperature float Optional

The sampling temperature, which controls the randomness and diversity of the generated images.

A higher temperature value results in more diverse images, while a lower value produces more deterministic images.

The value must be a float from 0 to 1.0. The default value is 0.7.

Since both temperature and top_p control image diversity, set only one of them.

top_p float Optional

The probability threshold for nucleus sampling, which controls the diversity of generated images. For example, a value of 0.8 means that only tokens from the cumulative probability distribution of 0.8 or higher are considered for sampling.

A higher top_p value increases randomness, while a lower value decreases it.

The value must be a float from 0 to 1.0. The default value is 0.7.

n Integer Required

The number of images to generate. The default value is 1. You can generate a maximum of 4 images per request.

Response

Successful response

{
    "output": {
        "task_id": "xxxxxxxx",
        "task_status": "PENDING"
    },
    "request_id": "xxxxxxxx"
}

Error response

{
    "code":"InvalidApiKey",
    "message":"Invalid API key provided.",
    "request_id":"xxxxxxxx"
}

output object

Task output information.

Properties

task_id string

The task ID.

task_status string

The task status.

  • PENDING: The task is in the queue.

  • RUNNING: The task is in progress.

  • SUSPENDED: The task is suspended.

  • SUCCEEDED: The task was successful.

  • FAILED: The task failed.

  • UNKNOWN: The task does not exist or its status is unknown.

code string

The error code. This field is returned only when a request fails.

message string

The error message. This field is returned only when a request fails.

request_id string

The unique request ID, which you can use for troubleshooting.

Query task results

GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}

Headers

Get task result

curl -X GET \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
https://dashscope.aliyuncs.com/api/v1/tasks/{your-task-id}

Authorization string Required

A Model Studio API key is recommended, but you can also use a DashScope API key. For example: Bearer d1xxx2a.

Path parameters

task_id string Required

The unique ID of the task.

Response

Task succeeded

Task results, including image URLs, are available for 24 hours. You must save any generated images within this period, as the task and all associated data are deleted afterward.

{
    "request_id": "85eaba38-0185-99d7-8d16-4d9135238846",
    "output": {
        "task_id": "86ecf553-d340-4e21-af6e-a0c6a421c010",
        "task_status": "SUCCEEDED",
        "results": [
            {
                "url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/123/a1.png"
            },
            {
                "url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/123/b2.png"
            }
        ],
        "task_metrics": {
            "TOTAL": 2,
            "SUCCEEDED": 2,
            "FAILED": 0
        }
    },
    "usage": {
        "image_count": 2
    }
}

Partial success

This model can generate multiple images in a single request. The task is marked as SUCCEEDED as long as at least one image is generated successfully. When you query the task, the response includes the successful results. If an image fails to generate, the response includes the corresponding failure reason. You are only billed for successfully generated images.

{
  "request_id":"<your request id>",
  "output":{
    "task_id":"<your task id>",
    "task_status":"SUCCEEDED",
    "results":[
      {
        "url":"https://xxx.com/xxx/xxx.png"
      },
      {
        "code": "InternalError.Timeout",
        "message": "An internal timeout error has occured during execution, please try again later or contact service support."
      }
    ],
    "task_metrics":{
      "TOTAL":2,
      "SUCCEEDED":1,
      "FAILED":1
    }
  },
  "usage":{
    "image_count":1
  }
}

Task running

{
    "request_id":"<your request id>",
    "output":{
        "task_id":"<your task id>",
        "task_status":"RUNNING",
        "task_metrics":{
            "TOTAL":1,
            "SUCCEEDED":1,
            "FAILED":0
        }
    }
}

output dict

The result of the call, which includes the image with text overlays.

Properties

task_id string

The unique ID of the task.

task_status string

The task status.

  • PENDING: The task is in the queue.

  • RUNNING: The task is in progress.

  • SUSPENDED: The task is suspended.

  • SUCCEEDED: The task was successful.

  • FAILED: The task failed.

  • UNKNOWN: The task does not exist or its status is unknown.

task_metrics object

Task execution statistics.

Properties

TOTAL integer

The total number of images to generate.

SUCCEEDED integer

The number of successfully generated images.

FAILED integer

The number of images that failed to generate.

code string

The error code for the task. This field is returned only when the task fails.

message string

The error message for the task. This field is returned only when the task fails.

results list

A list of result objects generated by the model.

Properties

url string

The URL of the generated image with text overlays. The resolution of the output image matches that of the input image.

request_id string

The unique request ID.

usage dict

Statistics on the output.

Properties

image_count integer

The number of images successfully generated.

(Optional) Configure a domain name whitelist to allow access to image links

The query API response includes an image OSS link, such as https://dashscope-result-xx.oss-cn-xxxx.aliyuncs.com/xxx.png. This link is publicly accessible, and you can use it to view or download the image.

If your business has high security requirements and cannot access external links, you must configure a whitelist. Add the following domain names to your whitelist to access the image links.

  • dashscope-result-bj.oss-cn-beijing.aliyuncs.com

  • dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com

  • dashscope-result-sh.oss-cn-shanghai.aliyuncs.com

  • dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com

  • dashscope-result-zjk.oss-cn-zhangjiakou.aliyuncs.com

  • dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com

  • dashscope-result-hy.oss-cn-heyuan.aliyuncs.com

  • dashscope-result-cd.oss-cn-chengdu.aliyuncs.com

  • dashscope-result-gz.oss-cn-guangzhou.aliyuncs.com

Error codes

If a model call fails and returns an error message, see Error codes for troubleshooting.

This API can also return the following specific error codes.

HTTP status code

API error code

API error message

Description

200

Success

Success

The request was successful.

400

InvalidParameter

Title field missing.

The title field is missing.

Title is not [str].

The title field is not a list of strings.

Title list is empty.

The title list is empty.

Subtitle is not [str].

The subtitle field is not a list of strings.

Text is not [str].

The text field is not a list of strings.

Invalid URL 'https:xxx.png': No host supplied

The URL for an image or asset is invalid or inaccessible.

500

InternalError

Inference error

An internal error occurred in the algorithm.