/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.5dall-e-3
prompt string - 图片生成提示词
n integer 1 生成图片数量
size string 1024x1024 图片尺寸。可选:256x256512x5121024x10241024x17921792x1024
quality string standard 生成质量。standardhd(仅 dall-e-3 支持)
response_format string url 响应格式。url(返回 URL)或 b64_json(返回 Base64)
style string - 图片风格
user string - 用户标识
output_format string - 输出图片格式:pngjpegwebp
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 质量在 1024x17921792x1024 尺寸下计费比为 1.5 倍。
  • response_formatb64_json 时,图片数据以 Base64 编码返回在 b64_json 字段中。