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

LanePathWho it is for
OpenAI-compatiblePOST /v1/images/generationsApps already written against the OpenAI Images protocol or SDK
Bailian nativeSync: 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 size differently and neither accepts the other's spelling: the OpenAI-compatible lane uses x (1024x1024), the Bailian native lane (async call included) uses * (1024*1024). The wrong one returns 400 naming the separator it expects; it is not silently rewritten.

1. OpenAI-compatible lane

bash
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 image for text to image; image to image does not use multipart — put the reference images in the top-level image field.
  • 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.
  • usage carries 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:

python
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.

bash
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.messages holds exactly one role: "user" object; its content holds 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.

bash
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:

bash
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, and usage is included.
  • Metered the same as the synchronous call.

3. Parameters

FieldDescription
modelqwen-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
sizeWIDTHxHEIGHT on the compatible lane, WIDTH*HEIGHT on the native lane; omit to let the model pick from the prompt
nNumber of images, default 1, must be an integer
negative_promptNegative prompt
seedRandom seed, integer
prompt_extendPrompt rewriting, default true
prompt_extend_modedirect (default) / agent (text to image only)
enable_thinkingThinking mode, default true; only with prompt_extend=true
watermarkWhether 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.