alicloud-ai-image-qwen-image by cinience/alicloud-skills
npx skills add https://github.com/cinience/alicloud-skills --skill alicloud-ai-image-qwen-imageCategory: provider
mkdir -p output/alicloud-ai-image-qwen-image
python -m py_compile skills/ai/image/alicloud-ai-image-qwen-image/scripts/generate_image.py && echo "py_compile_ok" > output/alicloud-ai-image-qwen-image/validate.txt
通过标准:命令以 0 状态退出,并生成 output/alicloud-ai-image-qwen-image/validate.txt 文件。
output/alicloud-ai-image-qwen-image/。通过标准化 image.generate 的输入/输出,并使用 DashScope SDK (Python) 和确切的模型名称,为视频代理流水线构建一致的图像生成行为。
安装 SDK(建议在虚拟环境中安装,以避免 PEP 668 限制):
python3 -m venv .venv . .venv/bin/activate python -m pip install dashscope
在环境变量中设置 DASHSCOPE_API_KEY,或将 添加到 文件中(环境变量优先)。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
dashscope_api_key~/.alibabacloud/credentials使用以下确切的模型字符串之一:
qwen-imageqwen-image-plusqwen-image-maxqwen-image-2.0qwen-image-2.0-proqwen-image-max-2025-12-30qwen-image-plus-2026-01-09prompt (字符串,必需)negative_prompt (字符串,可选)size (字符串,必需) 例如 1024*1024, 768*1024style (字符串,可选)seed (整数,可选)reference_image (字符串 | 字节,可选)image_url (字符串)width (整数)height (整数)seed (整数)最小化标准化请求体:
{
"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/alicloud-ai-image-qwen-image/images/preview.png "<IMAGE_URL_FROM_RESPONSE>" && open output/alicloud-ai-image-qwen-image/images/preview.png
本地辅助脚本(JSON 请求 -> 图像文件):
python 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/alicloud-ai-image-qwen-image/images/headphones.png \\
--print-response
| 字段 | 必需 | 说明 |
|---|---|---|
prompt | 是 | 描述场景,不仅仅是关键词。 |
negative_prompt | 否 | 尽力而为,后端可能忽略。 |
size | 是 | WxH 格式,例如 1024*1024, 768*1024。 |
style | 否 | 可选风格提示。 |
seed | 否 | 在支持时用于可复现性。 |
reference_image | 否 | URL/文件/字节,SDK 特定的映射。 |
使用 DashScope SDK 并将标准化请求映射到 SDK 调用。注意:对于 qwen-image-max,DashScope SDK 目前通过 ImageGeneration(基于消息)而非 ImageSynthesis 成功调用。如果您使用的 SDK 版本对参考图片期望不同的字段名,请相应调整 input 映射。
import os
from dashscope.aigc.image_generation import ImageGeneration
# 推荐使用环境变量进行认证:export DASHSCOPE_API_KEY=...
# 或者在 [default] 下使用 ~/.alibabacloud/credentials 文件中的 dashscope_api_key。
def generate_image(req: dict) -> dict:
messages = [
{
"role": "user",
"content": [{"text": req["prompt"]}],
}
]
if req.get("reference_image"):
# 某些 SDK 版本在消息内容中接受 {"image": <url|file|bytes>}。
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"),
# 如果后端支持,传递可选参数。
negative_prompt=req.get("negative_prompt"),
style=req.get("style"),
seed=req.get("seed"),
)
# 响应是一个生成风格的封装;提取第一个图片 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"),
}
| 错误 | 可能原因 | 操作 |
|---|---|---|
| 401/403 | 缺少或无效的 DASHSCOPE_API_KEY | 检查环境变量或 ~/.alibabacloud/credentials 文件,以及访问策略。 |
| 400 | 不支持的尺寸或错误的请求格式 | 使用常见的 WxH 并验证字段。 |
| 429 | 速率限制或配额 | 使用退避策略重试,或降低并发度。 |
| 5xx | 后端暂时性错误 | 使用退避策略重试一两次。 |
output/alicloud-ai-image-qwen-image/images/OUTPUT_DIR 覆盖基础目录。(prompt, negative_prompt, size, seed, reference_image hash) 缓存结果以避免重复成本。negative_prompt、style 或 seed;将它们视为尽力而为的输入。WxH 格式(例如 1024*1024, 768*1024)。有关更详细的 DashScope SDK 映射和响应解析技巧,请参阅 references/api_reference.md。
有关提示词模式和示例,请参阅 references/prompt-guide.md。
对于编辑工作流,请使用 skills/ai/image/alicloud-ai-image-qwen-image-edit/。
来源列表:references/sources.md
每周安装量
242
代码仓库
GitHub 星标数
345
首次出现
2026年2月7日
安全审计
安装于
gemini-cli240
github-copilot240
codex240
kimi-cli240
amp240
opencode240
Category: provider
mkdir -p output/alicloud-ai-image-qwen-image
python -m py_compile skills/ai/image/alicloud-ai-image-qwen-image/scripts/generate_image.py && echo "py_compile_ok" > output/alicloud-ai-image-qwen-image/validate.txt
Pass criteria: command exits 0 and output/alicloud-ai-image-qwen-image/validate.txt is generated.
output/alicloud-ai-image-qwen-image/.Build consistent image generation behavior for the video-agent pipeline by standardizing image.generate inputs/outputs and using DashScope SDK (Python) with the exact model name.
Install SDK (recommended in a venv to avoid PEP 668 limits):
python3 -m venv .venv . .venv/bin/activate python -m pip install dashscope
Set DASHSCOPE_API_KEY in your environment, or add dashscope_api_key to ~/.alibabacloud/credentials (env takes precedence).
Use one of these exact model strings:
qwen-imageqwen-image-plusqwen-image-maxqwen-image-2.0qwen-image-2.0-proqwen-image-max-2025-12-30qwen-image-plus-2026-01-09prompt (string, required)negative_prompt (string, optional)size (string, required) e.g. 1024*1024, 768*1024style (string, optional)seed (int, optional)reference_image (string | bytes, optional)image_url (string)width (int)height (int)seed (int)Minimal normalized request body:
{
"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
}
Preview workflow (download then open):
curl -L -o output/alicloud-ai-image-qwen-image/images/preview.png "<IMAGE_URL_FROM_RESPONSE>" && open output/alicloud-ai-image-qwen-image/images/preview.png
Local helper script (JSON request -> image file):
python 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/alicloud-ai-image-qwen-image/images/headphones.png \\
--print-response
| Field | Required | Notes |
|---|---|---|
prompt | yes | Describe a scene, not just keywords. |
negative_prompt | no | Best-effort, may be ignored by backend. |
size | yes | WxH format, e.g. 1024*1024, 768*1024. |
style |
Use the DashScope SDK and map the normalized request into the SDK call. Note: For qwen-image-max, the DashScope SDK currently succeeds via ImageGeneration (messages-based) rather than ImageSynthesis. If the SDK version you are using expects a different field name for reference images, adapt the input mapping accordingly.
import 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 DASHSCOPE_API_KEY | Check env var or ~/.alibabacloud/credentials, and access policy. |
| 400 | Unsupported size or bad request shape | Use common WxH and validate fields. |
| 429 | Rate limit or quota | Retry with backoff, or reduce concurrency. |
| 5xx | Transient backend errors | Retry with backoff once or twice. |
output/alicloud-ai-image-qwen-image/images/OUTPUT_DIR.(prompt, negative_prompt, size, seed, reference_image hash) to avoid duplicate costs.negative_prompt, style, or seed; treat them as best-effort inputs.WxH format (e.g. 1024*1024, 768*1024).See references/api_reference.md for a more detailed DashScope SDK mapping and response parsing tips.
See references/prompt-guide.md for prompt patterns and examples.
For edit workflows, use skills/ai/image/alicloud-ai-image-qwen-image-edit/.
Source list: references/sources.md
Weekly Installs
242
Repository
GitHub Stars
345
First Seen
Feb 7, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
gemini-cli240
github-copilot240
codex240
kimi-cli240
amp240
opencode240
Azure 配额管理指南:服务限制、容量验证与配额增加方法
79,700 周安装
| no |
| Optional stylistic hint. |
seed | no | Use for reproducibility when supported. |
reference_image | no | URL/file/bytes, SDK-specific mapping. |