Qwen 图片生成(DashScope 官方协议)
curl --request POST \
--globoff \
--url 'https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Authorization: <authorization>'import requests
url = "https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation"
headers = {"Authorization": "<authorization>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: '<authorization>'}};
fetch('https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body图像系列
Qwen 图片生成(DashScope 官方协议)
通义千问 Qwen-Image 官方协议入口:文生图与图片编辑,同步返回结果
POST
{llmApiOrigin}
/
qwen
/
api
/
v1
/
services
/
aigc
/
multimodal-generation
/
generation
Qwen 图片生成(DashScope 官方协议)
curl --request POST \
--globoff \
--url 'https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Authorization: <authorization>'import requests
url = "https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation"
headers = {"Authorization": "<authorization>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: '<authorization>'}};
fetch('https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/{{llmApiOrigin}}/qwen/api/v1/services/aigc/multimodal-generation/generation")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body简介
Qwen 图片入口以阿里云百炼 DashScope 多模态生成协议对外提供服务,支持 Qwen-Image 文生图与图片编辑,采用同步调用:一次 POST 直接返回生成结果,没有任务 ID,也不需要轮询。POST /qwen/api/v1/services/aigc/multimodal-generation/generation
/qwen)。使用官方 DashScope SDK 时,把 SDK 的 base_url 指向 https://api.shengmoai.com/qwen 即可。
本入口只支持同步调用。生成耗时通常在 10–60 秒,请把客户端超时设置为不少于 120 秒。若 SDK 自动附加X-DashScope-Async或X-DashScope-SSE请求头,请求会被拒绝(HTTP 400),请改用同步模式。
认证
Content-Type 必须为 application/json,不支持 multipart/form-data。
支持模型
| 模型 | 说明 |
|---|---|
qwen-image-2.0 | 标准版,生成 + 编辑一体,支持纯文生图与带参考图编辑 |
qwen-image-2.0-pro | 文生图 |
qwen-image-edit | 图片编辑(基础版) |
qwen-image-edit-max | 图片编辑(Max 版) |
qwen-image-edit-plus | 图片编辑(Plus 版) |
模型是否可用取决于服务端渠道配置与上游账号开通情况,未开通的模型会返回上游的模型不存在 / 未开通类错误。
请求结构
{
"model": "qwen-image-2.0-pro",
"input": {
"messages": [
{
"role": "user",
"content": [{ "text": "一只狐狸坐在雪地里,电影感光效" }]
}
]
},
"parameters": {
"size": "2048*2048",
"n": 1,
"prompt_extend": true
}
}
顶层字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,必须是支持模型之一 |
input | object | 是 | 仅包含 messages 数组 |
parameters | object | 否 | 生成参数,见下方参数表 |
input.messages 约束
所有模型一致:
- 必须恰好 1 条 message;
role可省略,填写时必须是user; - 每条 message 的
content必须恰好包含 1 个text项; - 每个内容项只能携带
text或image二选一,不能同时携带; image项为图片 URL 或 base64 字符串,最多 3 张(各模型实际可用数量见能力表)。
parameters 参数
| 字段 | 类型 | 说明 |
|---|---|---|
size | string | 输出尺寸,格式为 宽*高(星号分隔),如 1024*1024;支持时每边范围 512–2048 |
n | integer | 生成图片数量,范围 1–6(各模型上限不同),缺省为 1 |
negative_prompt | string | 反向提示词,不超过 500 字符 |
prompt_extend | boolean | 提示词改写开关;显式传 false 会被保留并发送 |
watermark | boolean | 水印开关;显式传 false 会被保留并发送 |
seed | integer | 随机种子,范围 0–2147483647 |
模型能力表
| 模型 | 输入图片 | n 上限 | size | prompt_extend / watermark |
|---|---|---|---|---|
qwen-image-2.0 | 0–3 张(生成/编辑一体) | 6 | 支持(512–2048) | 支持 |
qwen-image-2.0-pro | 不支持(仅 1 个 text) | 6 | 支持(512–2048) | 支持 |
qwen-image-edit | 1–3 张 | 仅 1 | 不支持(跟随输入图) | 不支持 |
qwen-image-edit-max | 1–3 张 | 6 | 支持(512–2048) | 支持 |
qwen-image-edit-plus | 1–3 张 | 6 | 支持(512–2048) | 支持 |
qwen-image-edit 传 size 或 n>1、对文生图模型传输入图片)会在请求阶段直接返回 HTTP 400,不会产生费用。
示例
文生图
curl -X POST "https://api.shengmoai.com/qwen/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-image-2.0-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{ "text": "一只狐狸坐在雪地里,电影感光效" }
]
}
]
},
"parameters": {
"size": "2048*2048",
"n": 1,
"prompt_extend": true
}
}'
图片编辑
curl -X POST "https://api.shengmoai.com/qwen/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-image-edit-max",
"input": {
"messages": [
{
"role": "user",
"content": [
{ "image": "https://example.com/input.png" },
{ "text": "把背景换成雪山" }
]
}
]
},
"parameters": {
"size": "1280*720",
"n": 1
}
}'
响应
响应为上游官方形状(原样透传):{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": [
{ "image": "https://example.com/generated-1.png" }
]
}
}
]
},
"usage": {
"image_count": 1,
"width": 2048,
"height": 2048
},
"request_id": "req_xxxxxxxx"
}
| 字段 | 说明 |
|---|---|
output.choices[].message.content[].image | 生成结果,URL 或 base64(与输入格式对应) |
usage.image_count | 本次计费图片数 |
request_id | 请求 ID,便于排查问题 |
计费说明
- 按生成图片张数计费,结算数量以响应中的
usage.image_count为准(缺失时按实际返回的图片数); - 提交时按请求的
n(或缺省 1)预扣,完成后按实际出图数多退少补; - 具体单价以平台模型价格配置为准。
错误处理
| 场景 | HTTP | 响应形状 |
|---|---|---|
| 本地参数校验失败 | 400 | { "code": "InvalidParameter...", "message": "具体原因" } |
| 传了异步 / 流式请求头 | 400 | { "code": "UnsupportedOperation.Async", "message": "..." } |
| 上游生成失败 | 上游状态码 | OpenAI 错误格式 { "error": { "message", "type", "code" } }(透传上游信息) |
| 令牌无效 / 额度不足 | 401 / 403 / 429 | 网关标准错误格式 |
相关页面
Seedream 图片生成
火山方舟 Seedream 官方协议入口
OpenAI 兼容图片接口
/v1/images/generations,兼容 OpenAI Images 协议
