/v1/images/generations

POST https://ai-api.mandao.com/v1/images/generations

图片生成接口,OpenAI Images API 兼容格式。

请求参数

Header 参数

参数名 类型 必需 说明
Authorization string 是 Bearer Token 认证
Content-Type string 是 application/json

Body 参数 (application/json)

参数名 类型 必需 默认值 说明
model string 是 - 模型 ID,如 gpt-image-1.5、dall-e-3 等
prompt string 是 - 图片生成提示词
n integer 否 1 生成图片数量
size string 否 1024x1024 图片尺寸。可选:256x256、512x512、1024x1024、1024x1792、1792x1024
quality string 否 standard 生成质量。standard 或 hd(仅 dall-e-3 支持)
response_format string 否 url 响应格式。url(返回 URL)或 b64_json(返回 Base64)
style string 否 - 图片风格
user string 否 - 用户标识
output_format string 否 - 输出图片格式:png、jpeg、webp
output_compression integer 否 - 图片压缩率(JPEG)
background string 否 - 背景设置(如 opaque)
moderation string 否 - 内容审核级别

请求示例

curl --location 'https://ai-api.mandao.com/v1/images/generations' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
    "model": "gpt-image-1.5",
    "prompt": "A cute baby sea otter",
    "n": 1,
    "size": "1024x1024"
}'

返回响应

200 成功

{
    "created": 1700000000,
    "data": [
        {
            "url": "https://example.com/generated-image.png",
            "revised_prompt": "A cute baby sea otter floating on its back..."
        }
    ]
}

错误响应

{
    "error": {
        "message": "错误描述",
        "type": "invalid_request_error",
        "code": null
    }
}

注意事项

  • 不同模型支持的尺寸和质量参数可能不同,请参考具体模型文档。
  • dall-e-3 模型的 hd 质量在 1024x1792 和 1792x1024 尺寸下计费比为 1.5 倍。
  • response_format 为 b64_json 时,图片数据以 Base64 编码返回在 b64_json 字段中。