跳到主要内容

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>

请求参数:

字段类型必填默认/建议值说明
modelstringqwen/qwen-image对外模型名
promptstring-图片描述
sizestring1328x1328输出尺寸
ninteger1生成数量,必须大于 0
num_inference_stepsinteger50推理步数;越高通常质量越好、耗时越长
guidance_scalenumber1.0引导强度
true_cfg_scalenumber4.0True CFG 强度
seedinteger随机固定后便于复现
negative_promptstring不希望出现的内容
response_formatstringb64_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-dataimageurl 至少提供一种,最多可提供 8 张参考图片。

请求

POST https://mzsjai.com/v1/images/edits
Content-Type: multipart/form-data
Authorization: Bearer <YOUR_API_KEY>

请求参数:

字段类型必填默认/建议值说明
modelstringqwen/qwen-image-edit对外模型名
promptstring-编辑要求
imagefile二选一-PNG/JPEG 文件;可重复传递
urlstring二选一-HTTP(S) 图片地址;可重复传递
sizestring1328x1328输出尺寸
ninteger1生成数量,必须大于 0
num_inference_stepsinteger40推理步数
guidance_scalenumber1.0引导强度
true_cfg_scalenumber4.0True CFG 强度
seedinteger随机固定后便于复现
negative_promptstring不希望出现的内容
response_formatstringb64_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参数、尺寸或图片无效修正请求后重试
401API Key 缺失或无效检查鉴权配置
422Multipart 字段校验失败检查字段类型和必填参数
429额度不足或触发限流检查余额并降低请求频率
500上游推理失败保存请求 ID 后联系平台
502/503/504服务暂不可用或超时使用指数退避有限重试

建议将客户端超时设置为至少 20 分钟。生产请求的正式推理步数通常为文生图 50、图片编辑 40,耗时会明显高于低步数冒烟测试。