Qwen Image API 文档
本文档说明如何通过 Mozia API 调用 Qwen 文生图和图片编辑模型。
接口总览
| 方法 | 路径 | 作用 |
|---|---|---|
POST | /v1/images/generations | 根据提示词生成图片 |
POST | /v1/images/edits | 根据提示词和参考图片编辑图片 |
基础地址:https://mzsjai.com
所有请求都需要 API Key:
Authorization: Bearer <YOUR_API_KEY>
请仅在服务端保存 API Key,不要将其写入浏览器代码、公开仓库或日志。
模型
| 模型 | 能力 | 接口 |
|---|---|---|
qwen/qwen-image | 文生图 | POST /v1/images/generations |
qwen/qwen-image-edit | 图片编辑 | POST /v1/images/edits |
实际扣费可能受账号分组或专属倍率影响。单次生成多张图片时,费用按生成数量计算。当前建议 n=1。
简单的文生图请求示例
curl --fail-with-body \
'https://mzsjai.com/v1/images/generations' \
-H "Authorization: Bearer ${MOZIA_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen/qwen-image",
"prompt": "A blue ceramic teapot on a white table, soft studio lighting",
"size": "1328x1328",
"n": 1
}'
支持的尺寸
两个模型支持以下标准尺寸:
1328x1328
1664x928
928x1664
1472x1104
1104x1472
1584x1056
1056x1584
文生图
请求
POST https://mzsjai.com/v1/images/generations
Content-Type: application/json
Authorization: Bearer <YOUR_API_KEY>
请求参数:
| 字段 | 类型 | 必填 | 默认/建议值 | 说明 |
|---|---|---|---|---|
model | string | 是 | qwen/qwen-image | 对外模型名 |
prompt | string | 是 | - | 图片描述 |
size | string | 否 | 1328x1328 | 输出尺寸 |
n | integer | 否 | 1 | 生成数量,必须大于 0 |
num_inference_steps | integer | 否 | 50 | 推理步数;越高通常质量越好、耗时越长 |
guidance_scale | number | 否 | 1.0 | 引导强度 |
true_cfg_scale | number | 否 | 4.0 | True CFG 强度 |
seed | integer | 否 | 随机 | 固定后便于复现 |
negative_prompt | string | 否 | 空 | 不希望出现的内容 |
response_format | string | 否 | b64_json | 当前平台统一返回 Base64 图片 |
cURL 示例
curl --fail-with-body \
'https://mzsjai.com/v1/images/generations' \
-H "Authorization: Bearer ${MOZIA_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen/qwen-image",
"prompt": "A blue ceramic teapot on a white table, soft studio lighting",
"size": "1328x1328",
"n": 1,
"num_inference_steps": 50,
"guidance_scale": 1.0,
"true_cfg_scale": 4.0,
"seed": 20260826,
"response_format": "b64_json"
}'
图片编辑
图片编辑使用 multipart/form-data。image 和 url 至少提供一种,最多可提供 8 张参考图片。
请求
POST https://mzsjai.com/v1/images/edits
Content-Type: multipart/form-data
Authorization: Bearer <YOUR_API_KEY>
请求参数:
| 字段 | 类型 | 必填 | 默认/建议值 | 说明 |
|---|---|---|---|---|
model | string | 是 | qwen/qwen-image-edit | 对外模型名 |
prompt | string | 是 | - | 编辑要求 |
image | file | 二选一 | - | PNG/JPEG 文件;可重复传递 |
url | string | 二选一 | - | HTTP(S) 图片地址;可重复传递 |
size | string | 否 | 1328x1328 | 输出尺寸 |
n | integer | 否 | 1 | 生成数量,必须大于 0 |
num_inference_steps | integer | 否 | 40 | 推理步数 |
guidance_scale | number | 否 | 1.0 | 引导强度 |
true_cfg_scale | number | 否 | 4.0 | True CFG 强度 |
seed | integer | 否 | 随机 | 固定后便于复现 |
negative_prompt | string | 否 | 空 | 不希望出现的内容 |
response_format | string | 否 | b64_json | 当前平台统一返回 Base64 图片 |
上传文件
curl --fail-with-body \
'https://mzsjai.com/v1/images/edits' \
-H "Authorization: Bearer ${MOZIA_API_KEY}" \
-F 'model=qwen/qwen-image-edit' \
-F 'prompt=Change the blue teapot to red while keeping the composition unchanged' \
-F 'image=@input.jpg;type=image/jpeg' \
-F 'size=1328x1328' \
-F 'n=1' \
-F 'num_inference_steps=40' \
-F 'guidance_scale=1.0' \
-F 'true_cfg_scale=4.0' \
-F 'seed=20260826' \
-F 'response_format=b64_json'
多图输入时重复传递 image:
curl --fail-with-body \
'https://mzsjai.com/v1/images/edits' \
-H "Authorization: Bearer ${MOZIA_API_KEY}" \
-F 'model=qwen/qwen-image-edit' \
-F 'prompt=Combine the subjects from both references into one scene' \
-F 'image=@reference-1.jpg;type=image/jpeg' \
-F 'image=@reference-2.png;type=image/png' \
-F 'size=1328x1328' \
-F 'n=1' \
-F 'response_format=b64_json'
使用远程 URL
curl --fail-with-body \
'https://mzsjai.com/v1/images/edits' \
-H "Authorization: Bearer ${MOZIA_API_KEY}" \
-F 'model=qwen/qwen-image-edit' \
-F 'prompt=Replace the background with snowy mountains' \
-F 'url=https://example.com/input.jpg' \
-F 'size=1328x1328' \
-F 'num_inference_steps=40' \
-F 'response_format=b64_json'
url 必须是绝对 HTTP(S) 地址。多图输入时可以重复传递 url。
响应格式
成功响应采用 OpenAI Images 兼容结构:
{
"created": 1787738693,
"data": [
{
"url": null,
"b64_json": "<BASE64_IMAGE_DATA>",
"revised_prompt": ""
}
]
}
当前渠道会强制使用 b64_json,即使请求中传入 response_format=url,也应从 data[0].b64_json 读取并解码图片。
错误处理
错误响应采用统一结构:
{
"error": {
"message": "Error description",
"type": "new_api_error",
"code": "error_code"
}
}
常见状态码:
| 状态码 | 含义 | 建议 |
|---|---|---|
400 | 参数、尺寸或图片无效 | 修正请求后重试 |
401 | API Key 缺失或无效 | 检查鉴权配置 |
422 | Multipart 字段校验失败 | 检查字段类型和必填参数 |
429 | 额度不足或触发限流 | 检查余额并降低请求频率 |
500 | 上游推理失败 | 保存请求 ID 后联系平台 |
502/503/504 | 服务暂不可用或超时 | 使用指数退避有限重试 |
建议将客户端超时设置为至少 20 分钟。生产请求的正式推理步数通常为文生图 50、图片编辑 40,耗时会明显高于低步数冒烟测试。