文生图
POST v1/images/generations请求参数
Authorization
在 Header 添加参数 Authorization,其值为在 Bearer 之后拼接 Token。
Authorization: Bearer ******************Header 参数
| 参数 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| Content-Type | string | 可选 | 请求体的数据格式类型 | application/json |
| Accept | string | 可选 | 客户端期望接收的响应数据格式 | application/json |
Body 参数
Content-Type: application/json
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 必需 | 模型名称。指定使用的图像生成模型 ID(例如 doubao-seedream-4-5 等)。 |
| prompt | string | 必需 | 提示词。描述期望生成的图像内容、风格和构图。 |
| parameters | object | 必需 | 参数 |
| size | string | 必需 | 图片尺寸。支持两种格式: 1. 预设代号:如 2K, 3K。 2. 具体分辨率:如 2048x2048(需符合像素总数限制)。 |
| sequential_image_generation | string | 必需 | 组图生成模式。控制是否开启多图连续生成功能: • disabled:关闭(默认,单次生成一张)。 • auto:自动判断,根据提示词决定生成一组关联图片。 |
| stream | boolean | 必需 | 流式输出。是否以流式方式返回结果(通常用于实时展示生成进度)。 |
| response_format | string | 必需 | 响应格式。指定返回数据的格式,通常为 url(图片链接)或 b64_json(Base64编码)。 |
| watermark | boolean | 必需 | 水印设置。是否在生成的图片上添加平台水印(如“AI生成”标识)。 |
请求示例 (JSON)
{
"model": "Qwen/Qwen-Image",
"prompt": "a white siamese cat",
"n": 1,
"size": "1024x1024"
}返回响应
200 成功
Content-Type: application/json
响应参数
| 字段名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| images | array [object] | 必需 | 图片列表。包含生成图片信息的数组。 |
| └─ url | string | 可选 | 图片地址。生成图片的直接访问链接。 |
| timings | object | 必需 | 耗时统计。记录推理过程的时间消耗信息。 |
| └─ inference | number | 必需 | 推理时间。模型执行生成任务所花费的具体时间(通常以秒为单位)。 |
| seed | integer | 必需 | 随机种子。用于复现生成结果的种子数值。 |
| shared_id | string | 必需 | 共享 ID。用于关联同一批次或同一工作流的唯一标识符。 |
| data | array [object] | 必需 | 数据列表。包含预测或生成结果的数据数组。 |
| └─ url | string | 可选 | 结果地址。相关输出文件的链接。 |
| created | integer | 必需 | 创建时间戳。任务创建时的 Unix 时间戳。 |
响应示例
{
"images": [
{
"url": "https://bizyair-prod.oss-cn-shanghai.aliyuncs.com/outputs%2F7e024863-2d3e-48a5-aa51-2b3ff15991df_66865defbed334c93c160ad2f1f207e5_ComfyUI_83894ea7_00001_.png?OSSAccessKeyId=LTAI5tPza7RAEKed35dCML5U&Expires=1760489302&Signature=8oLTgq6%2BKP%2FQ5cTGY8HAQLLXsr4%3D"
}
],
"timings": {
"inference": 0.464
},
"seed": 1116635659,
"shared_id": "0",
"data": [
{
"url": "https://bizyair-prod.oss-cn-shanghai.aliyuncs.com/outputs%2F7e024863-2d3e-48a5-aa51-2b3ff15991df_66865defbed334c93c160ad2f1f207e5_ComfyUI_83894ea7_00001_.png?OSSAccessKeyId=LTAI5tPza7RAEKed35dCML5U&Expires=1760489302&Signature=8oLTgq6%2BKP%2FQ5cTGY8HAQLLXsr4%3D"
}
],
"created": 1760485702
}示例代码
python
import http.client
import json
conn = http.client.HTTPSConnection("nxaiapp.com")
payload = json.dumps({
"model": "Qwen/Qwen-Image",
"prompt": "a white siamese cat",
"n": 1,
"size": "1024x1024"
})
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
}
conn.request("POST", "/v1/images/generations", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))