Qwen Image API Integration Guide & Examples
qwen-image-3.0-pro and qwen-image-3.0 both serve text to image and image to image / editing: no reference image means text to image, 1–3 reference images mean image to image. The OpenAI-compatible lane and the Bailian native synchronous call return the image directly — no polling; you can also use the Bailian native async call on Bailian's official protocol (create a task, then poll). These models are not served on the generic async task lane /v1/content_generation/tasks.
Availability and pricing differ by region. Check the model list for this endpoint before integrating — see the API catalog.
Two inbound lanes
| Lane | Path | Who it is for |
|---|---|---|
| OpenAI-compatible | POST /v1/images/generations | Apps already written against the OpenAI Images protocol or SDK |
| Bailian native | Sync: POST /api/v1/services/aigc/multimodal-generation/generation; async: POST /api/v1/services/aigc/image-generation/generation (with X-DashScope-Async: enable) + GET /api/v1/tasks/{task_id} | Apps already using the Bailian DashScope SDK |
The two lanes spell
sizedifferently and neither accepts the other's spelling: the OpenAI-compatible lane usesx(1024x1024), the Bailian native lane (async call included) uses*(1024*1024). The wrong one returns400naming the separator it expects; it is not silently rewritten.
1. OpenAI-compatible lane
curl https://api.modelgo.ai/v1/images/generations \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-image-3.0-pro",
"prompt": "Keep her facial features; change the outfit to a champagne silk shirt and a dark grey blazer",
"image": ["https://example-cdn.com/portrait.png"],
"size": "1024x1024"
}'- Omit
imagefor text to image; image to image does not use multipart — put the reference images in the top-levelimagefield. - The response is
{"created": ..., "data": [{"url": "..."}], "usage": {...}}: PNG images, links valid for 24 hours — download them promptly.response_format: "b64_json"is ignored; the response still carries a URL. usagecarries image counts and tiers, not token counts (see "Metering").
With the OpenAI SDK, pass the non-OpenAI parameters — image / negative_prompt / seed / prompt_extend / prompt_extend_mode / enable_thinking / watermark — through extra_body:
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["MODELGO_API_KEY"], base_url="https://api.modelgo.ai/v1",
timeout=600.0) # image generation takes a while; raise the timeout
resp = client.images.generate(model="qwen-image-3.0-pro", prompt="A ginger cat on a windowsill, film grain",
size="1024x1024", extra_body={"prompt_extend": True})
print(resp.data[0].url)2. Bailian native lane
Request and response are both the Bailian shape, unchanged. With the official Bailian SDK (dashscope), point dashscope.base_http_api_url at https://api.modelgo.ai/api/v1 and use your ModelGo API key as api_key.
curl https://api.modelgo.ai/api/v1/services/aigc/multimodal-generation/generation \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-image-3.0-pro",
"input": {"messages": [{"role": "user", "content": [
{"image": "https://example-cdn.com/portrait.png"},
{"text": "Change the outfit to a champagne silk shirt"}
]}]},
"parameters": {"size": "1024*1024", "n": 1}
}'input.messagesholds exactly onerole: "user"object; itscontentholds exactly one{"text": ...}and 0–3{"image": ...}entries.- Generation parameters go under
parameters, not at the top level. - The image URL is at
output.choices[0].message.content[0].image.
Bailian native async call
This follows Bailian's official async protocol. The body is identical to the synchronous call above (model, input.messages, parameters); only two things differ — the path is image-generation/generation (not multimodal-generation), and the X-DashScope-Async: enable header is required.
curl https://api.modelgo.ai/api/v1/services/aigc/image-generation/generation \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-H "X-DashScope-Async: enable" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-image-3.0-pro",
"input": {"messages": [{"role": "user", "content": [
{"image": "https://example-cdn.com/portrait.png"},
{"text": "Change the outfit to a champagne silk shirt"}
]}]},
"parameters": {"size": "1024*1024", "n": 1}
}'A successful create returns {"output": {"task_id": "...", "task_status": "PENDING"}, "request_id": "..."}; poll with output.task_id:
curl https://api.modelgo.ai/api/v1/tasks/{task_id} \
-H "Authorization: Bearer $MODELGO_API_KEY"output.task_status:PENDING→RUNNING→SUCCEEDED/FAILED.- On success the image URL is again at
output.choices[0].message.content[0].image, andusageis included. - Metered the same as the synchronous call.
3. Parameters
| Field | Description |
|---|---|
model | qwen-image-3.0-pro / qwen-image-3.0 |
prompt (compatible lane) / content[].text (native lane) | Required, non-empty |
image (compatible lane) / content[].image (native lane) | Reference images, 1–3, as public direct links or data:{MIME_type};base64,{data}. Must not be null or an empty array |
size | WIDTHxHEIGHT on the compatible lane, WIDTH*HEIGHT on the native lane; omit to let the model pick from the prompt |
n | Number of images, default 1, must be an integer |
negative_prompt | Negative prompt |
seed | Random seed, integer |
prompt_extend | Prompt rewriting, default true |
prompt_extend_mode | direct (default) / agent (text to image only) |
enable_thinking | Thinking mode, default true; only with prompt_extend=true |
watermark | Whether to watermark, default false |
The gateway validates request structure only (field types, size format and separator, non-empty image, and on the native lane the number of messages / text); a malformed request returns 400 and is not billed. Value ranges (image count, size, number of reference images, seed range and so on) are validated by the upstream: an out-of-range value may return 400 or be silently ignored while the request still succeeds, so use the values listed on this page. The whole request body, Base64 images included, is capped at 10 MiB; use public URLs for several large images.
4. Metering
This family is metered per image, not per token. Input (reference) and output (generated) images are metered separately, each in a 1k and a 2k tier. The tier is decided by the output pixel area: ≤ 1500×1500 is 1k, larger is 2k. output_image_count / output_image_type and input_image_count / input_image_type in usage give the counts and tiers. Requesting n images meters n.