Qwen Image Generation and Editing API Integration Guide
The Qwen Image Generation and Editing API supports generating images from text descriptions and editing images based on 1–3 reference images. Through the same endpoint, you can create product images, posters, illustrations, and other images, and choose to wait synchronously for results or query results asynchronously.
This guide covers the complete process from obtaining an API Token and submitting your first image to receiving asynchronous results. The endpoint is POST https://api.acedata.cloud/qwen-image/images.
¶ Application and Usage
- Open the Ace Data Cloud console. If you have not logged in or registered, you will return to the console after logging in.
- Open General Application and click the copy button to the right of the API KEY field. Users who already have a platform API Token can use it directly without applying separately for Qwen Image; please confirm that the credential has permission to call the corresponding endpoint.
- Confirm that your account has available credits. If your credits are insufficient, click the “Recharge” button.

Replace YOUR_API_TOKEN below with your own API Token. Store the Token on the server side; do not put it in frontend web code or public repositories.
Complete parameters and online testing: Qwen Image Generation and Editing API.
¶ Choose a Model
| Model | Suitable scenarios |
|---|---|
qwen-image-3.0 |
Everyday image generation, batch creation, and rapid iteration |
qwen-image-3.0-pro |
Scenarios with higher requirements for detail, text layout, and final image quality |
Both models use the endpoint in this guide. The cost of a request depends on the model, number of reference images, actual number of output images, and output specifications. For current pricing, see the Qwen Image pricing page.
¶ Request Headers and Parameters
All requests use a JSON request body and include the following headers:
| Header | Value | Description |
|---|---|---|
Authorization |
Bearer YOUR_API_TOKEN |
Use the API Token obtained from the console; retain the space after Bearer |
Content-Type |
application/json |
Use JSON format for the request body |
Accept |
application/json |
Accept responses in JSON format |
Common request parameters are listed below. Refer to the API documentation for complete definitions.
| Parameter | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | qwen-image-3.0 or qwen-image-3.0-pro |
prompt |
string | Yes | Describes the image to generate or editing requirements; cannot be empty; maximum 18000 characters |
image_urls |
string[] | No | Provide 1–3 publicly accessible reference image URLs for editing; omit this field for text-to-image generation |
n |
integer | No | Number of images to generate, ranging from 1–6; default 1 |
size |
string | No | Output dimensions, in the format width*height, for example 1024*1024; use an asterisk * as the separator |
prompt_extend |
boolean | No | Whether to expand the prompt; default true |
prompt_extend_mode |
string | No | direct or agent; default direct; agent is only used for text-to-image generation |
enable_thinking |
boolean | No | Whether to enable enhanced reasoning; default true |
negative_prompt |
string | No | Describes content you do not want to appear in the image |
seed |
integer | No | Random seed, ranging from 0–2147483647 |
watermark |
boolean | No | Whether to add a watermark; default false |
async |
boolean | No | When set to true, returns a task_id first; default false |
callback_url |
string | No | HTTP(S) address for receiving asynchronous completion notifications; when provided, the request is executed asynchronously |
The pixel area of the dimensions must be between 512 × 512 and 2048 × 2048, and the aspect ratio must be between 1:8 and 8:1. For example, 1024*1024 represents a square image, and 1536*1024 represents a landscape image.
¶ Generate Images Synchronously
For your first request, synchronous mode is recommended: omit image_urls and provide the model and prompt to generate an image from text. The endpoint waits for generation to complete before returning the image URL.
¶ cURL
curl -X POST 'https://api.acedata.cloud/qwen-image/images' \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"model": "qwen-image-3.0",
"prompt": "A simple red circle centered on a clean white background.",
"size": "1024*1024",
"n": 1,
"watermark": false
}'
¶ Python
First, run pip install requests to install the dependency, and set ACEDATACLOUD_API_TOKEN in your runtime environment to the Token obtained from the console.
import os
import requests
response = requests.post(
"https://api.acedata.cloud/qwen-image/images",
headers={
"Authorization": f"Bearer {os.environ['ACEDATACLOUD_API_TOKEN']}",
"Content-Type": "application/json",
"Accept": "application/json",
},
json={
"model": "qwen-image-3.0",
"prompt": "A simple red circle centered on a clean white background.",
"size": "1024*1024",
"n": 1,
"watermark": False,
},
timeout=300,
)
response.raise_for_status()
result = response.json()
if not result.get("success"):
raise RuntimeError(result)
for image in result["data"]:
print(image["image_url"])
¶ Example Response
The following is an excerpt of the main fields in a successful response; the example cost does not represent current pricing:
{
"success": true,
"task_id": "565a7f55-72c6-43ed-b274-268ff046e5b4",
"trace_id": "bb923cec-1550-43b4-8df2-288ac0977b4b",
"data": [
{
"image_url": "https://cdn.acedata.cloud/assets/examples/qwen-image/40d5c76b-2f84-4b04-9ea0-b706417ae622-bac6a9e9de22.png"
}
],
"usage": {
"input_image_count": 0,
"output_image_count": 1,
"output_width": 1024,
"output_height": 1024
},
"cost": {
"amount": 0.322,
"currency": "credit",
"list_amount": 0.35
}
}
| Field | Description |
|---|---|
success |
Whether this generation was successful |
task_id |
Task ID, which can be used for subsequent queries; save the value returned by your own request |
trace_id |
Request trace ID, provided to technical support when troubleshooting |
data |
List of generated images; view or download images using each item's image_url |
usage.input_image_count |
Actual number of input reference images; typically 0 for text-to-image generation |
usage.output_image_count |
Actual number of output images |
usage.output_width / usage.output_height |
Width and height of output images, in pixels |
cost.amount |
Actual cost after discounts are applied |
cost.list_amount |
List price before discounts are applied |
cost.currency |
Cost unit; credit means Credits |
The values in cost are measured in Credits. When conversion to US dollars is needed, use the price and allowance of the current plan: USD amount = Credits × (plan price / plan allowance).
¶ Editing Based on Reference Images
Add image_urls to the generation request to switch to reference image editing. The following uses a public example image and requests that the subject be preserved and the background modified:
curl -X POST 'https://api.acedata.cloud/qwen-image/images' \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"model": "qwen-image-3.0-pro",
"prompt": "保留参考图中的红色圆形主体,将白色背景改成暖色电影海报风格。",
"image_urls": [
"https://cdn.acedata.cloud/assets/examples/qwen-image/40d5c76b-2f84-4b04-9ea0-b706417ae622-bac6a9e9de22.png"
],
"size": "2048*2048",
"n": 1,
"watermark": false
}'
Reference images must be publicly accessible via URL; local file paths or addresses that require login cannot be used. When passing multiple reference images, you can explain the purpose of each image in the prompt, for example, “Preserve the subject of the first image and use the color scheme of the second image.” Edit mode does not support prompt_extend_mode: "agent"; omit this parameter or use direct.
The response structure for a successful edit is the same as for synchronous text-to-image generation; obtain the result from data[].image_url. Reference images are metered according to the actual number of inputs, and charges are determined by the current pricing page and the usage and cost returned for this request.
¶ Asynchronous Generation and Task Queries
If you do not want to keep the connection open while waiting for generation to complete, you can set async: true. The API first returns a task_id, and the final images must be obtained through the task query API.
curl -X POST 'https://api.acedata.cloud/qwen-image/images' \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"model": "qwen-image-3.0",
"prompt": "A simple red circle centered on a clean white background.",
"size": "1024*1024",
"n": 1,
"async": true
}'
Save the task_id in the response and use it as the id in the query request. Replace YOUR_TASK_ID below with your own task ID:
curl -X POST 'https://api.acedata.cloud/qwen-image/tasks' \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"action": "retrieve", "id": "YOUR_TASK_ID"}'
The query returns a task record, with the generation result located in response. After the task is complete, check response.success; on success, read response.data[].image_url; on failure, read response.error. It is recommended to query every 5 seconds and set a total waiting time limit.
For the complete task fields, Python polling code, and batch query examples, see the Qwen Image Task Query API Integration Guide. Generation is billed according to actual results, and task queries incur no additional API charges.
¶ Receiving Completion Callbacks
If you want to proactively receive a notification after a task is complete, you can add your own callback_url to the generation request. For example, the request body can be written as:
{
"model": "qwen-image-3.0",
"prompt": "A simple red circle centered on a clean white background.",
"size": "1024*1024",
"n": 1,
"async": true,
"callback_url": "https://your-domain.example/webhooks/qwen-image"
}
Replace the example address with your own accessible HTTP(S) service. After callback_url is provided, the request is executed asynchronously, and a task ID is returned first even if async: true is not explicitly set.
After the task is complete, the platform sends a POST request to that address. The JSON request body contains the final generation result, with the same structure as the result of a synchronous call, including fields such as success and task_id; on success, it contains the image results, and on failure, it contains error information. The callback receiver should promptly return a 2xx status code and handle requests idempotently by task_id. If no notification is received, you can use the saved task ID to query the result without submitting the generation request again.
¶ Error Handling and Common Issues
| Situation | Handling |
|---|---|
400 bad_request or parameter validation failure |
Check model, non-empty prompt, n, size format, and reference image count; agent mode cannot be used when editing |
401 invalid_token / token_expired |
Check whether the Token is correct or expired, and whether the request header includes the Bearer prefix |
403 |
Check access permissions, available allowance, or content requirements based on the error message; resubmit after making changes |
429 too_many_requests |
Reduce concurrency and retry after a delay |
500 api_error |
Save the trace_id and error information; if a task ID is available, query the original task first |
| Synchronous connection timeout | A timeout does not necessarily mean the task failed; if a task ID has been obtained, query the task first to avoid duplicate submissions |
When processing responses, check both the HTTP status code and the error information in the JSON. An asynchronous request returning a task ID only means it has been accepted; final success is determined by success in the query or callback.
Use the same Token and the same API for image generation and editing. Set n when batch output is needed; use the retrieve_batch operation of the Task Query API when querying multiple generation tasks in batches.
