Loading...
Loading...
Generate images with Model Studio DashScope SDK using Qwen Image generation models (qwen-image-max, qwen-image-plus-2026-01-09). Use when implementing or documenting image.generate requests/responses, mapping prompt/negative_prompt/size/seed/reference_image, or integrating image generation into the video-agent pipeline.
npx skill4agent add cinience/alicloud-skills alicloud-ai-image-qwen-imageimage.generatepython3 -m venv .venv
. .venv/bin/activate
python -m pip install dashscopeDASHSCOPE_API_KEYdashscope_api_key~/.alibabacloud/credentialsqwen-image-maxqwen-image-plus-2026-01-09promptnegative_promptsize1024*1024768*1024styleseedreference_imageimage_urlwidthheightseed{
"prompt": "a cinematic portrait of a cyclist at dusk, soft rim light, shallow depth of field",
"negative_prompt": "blurry, low quality, watermark",
"size": "1024*1024",
"seed": 1234
}curl -L -o output/ai-image-qwen-image/images/preview.png "<IMAGE_URL_FROM_RESPONSE>" && open output/ai-image-qwen-image/images/preview.pngpython skills/ai/image/alicloud-ai-image-qwen-image/scripts/generate_image.py \\
--request '{"prompt":"a studio product photo of headphones","size":"1024*1024"}' \\
--output output/ai-image-qwen-image/images/headphones.png \\
--print-response| Field | Required | Notes |
|---|---|---|
| yes | Describe a scene, not just keywords. |
| no | Best-effort, may be ignored by backend. |
| yes | |
| no | Optional stylistic hint. |
| no | Use for reproducibility when supported. |
| no | URL/file/bytes, SDK-specific mapping. |
qwen-image-maxImageGenerationImageSynthesisinputimport os
from dashscope.aigc.image_generation import ImageGeneration
# Prefer env var for auth: export DASHSCOPE_API_KEY=...
# Or use ~/.alibabacloud/credentials with dashscope_api_key under [default].
def generate_image(req: dict) -> dict:
messages = [
{
"role": "user",
"content": [{"text": req["prompt"]}],
}
]
if req.get("reference_image"):
# Some SDK versions accept {"image": <url|file|bytes>} in messages content.
messages[0]["content"].insert(0, {"image": req["reference_image"]})
response = ImageGeneration.call(
model=req.get("model", "qwen-image-max"),
messages=messages,
size=req.get("size", "1024*1024"),
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Pass through optional parameters if supported by the backend.
negative_prompt=req.get("negative_prompt"),
style=req.get("style"),
seed=req.get("seed"),
)
# Response is a generation-style envelope; extract the first image URL.
content = response.output["choices"][0]["message"]["content"]
image_url = None
for item in content:
if isinstance(item, dict) and item.get("image"):
image_url = item["image"]
break
return {
"image_url": image_url,
"width": response.usage.get("width"),
"height": response.usage.get("height"),
"seed": req.get("seed"),
}| Error | Likely cause | Action |
|---|---|---|
| 401/403 | Missing or invalid | Check env var or |
| 400 | Unsupported size or bad request shape | Use common |
| 429 | Rate limit or quota | Retry with backoff, or reduce concurrency. |
| 5xx | Transient backend errors | Retry with backoff once or twice. |
output/ai-image-qwen-image/images/OUTPUT_DIR(prompt, negative_prompt, size, seed, reference_image hash)negative_promptstyleseedWxH1024*1024768*1024references/api_reference.mdreferences/prompt-guide.mdskills/ai/image/alicloud-ai-image-qwen-image-edit/references/sources.md