cURL
先获取 API Key 并配置环境变量。如果使用 SDK,还需安装 SDK。
鉴权
string
header
必填
千问云 API Key。详见获取 API Key。
同步图像生成
curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"model": "qwen-image-2.0-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass. The main title Come Play Ball! is prominently displayed at the top in bold, blue cartoon font."
}
]
}
]
},
"parameters": {
"negative_prompt": "",
"prompt_extend": true,
"watermark": false,
"size": "2048*2048"
}
}'{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": [
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"
}
],
"role": "assistant"
}
}
]
},
"usage": {
"height": 928,
"image_count": 1,
"width": 1664
},
"request_id": "d0250a3d-b07f-49e1-bdc8-6793f4929xxx"
}千问云 API Key。详见获取 API Key。
模型名称。
包含消息数组的输入数据。
显示子属性
仅支持单轮对话。必须包含且只包含一条角色为 user 的消息。
图像生成参数。
显示子属性
描述不希望在图像中出现的内容。最多 500 个字符,超出部分自动截断。
输出分辨率,格式为 宽*高。qwen-image-2.0 系列:总像素在 512*512 到 2048*2048 之间,默认 2048*2048。qwen-image-max:支持自定义分辨率(总像素在 512*512 到 2048*2048 之间)和固定尺寸。qwen-image-plus/image:仅支持固定尺寸。qwen-image-max/plus/image 的固定尺寸:1664*928(16:9,默认)、1472*1104(4:3)、1328*1328(1:1)、1104*1472(3:4)、928*1664(9:16)。
生成图像数量。默认值:1。qwen-image-2.0 系列:1-6 张。qwen-image-max/plus 系列:固定为 1 张。
启用提示词改写。true(默认):模型优化提示词后再生成。false:直接使用原始提示词。
在图像右下角添加 "Qwen-Image" 水印。默认值:false。
随机数种子。范围:[0, 2147483647]。相同种子可产生更一致(但不完全相同)的结果。若不指定,则使用随机种子。
唯一请求标识符,用于追踪和排查问题。
curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"model": "qwen-image-2.0-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass. The main title Come Play Ball! is prominently displayed at the top in bold, blue cartoon font."
}
]
}
]
},
"parameters": {
"negative_prompt": "",
"prompt_extend": true,
"watermark": false,
"size": "2048*2048"
}
}'{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": [
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"
}
],
"role": "assistant"
}
}
]
},
"usage": {
"height": 928,
"image_count": 1,
"width": 1664
},
"request_id": "d0250a3d-b07f-49e1-bdc8-6793f4929xxx"
}