进阶 docs.leonardo.ai 2026-11-22 15:11:20 · 0 阅读
第13章 Leonardo.AI 集成 GPT Image 2 生成指南
第13章 GPT Image 2
本指南展示如何通过 Leonardo.AI REST API 使用 GPT Image-2.0 模型生成图像。本指南展示了如何使用 GPT Image-2.0 模型通过 Leonardo.AI REST API 生成图像。
示例请求
curl --location 'https://cloud.leonardo.ai/api/rest/v2/generations' \
--header 'authorization: Bearer {api-key}' \
--header 'Content-Type: application/json' \
--data '{
"public": false,
"model": "gpt-image-2",
"parameters": {
"quality": "MEDIUM",
"prompt": "Koala with purple hat",
"quantity": 2,
"width": 1376,
"height": 768,
"prompt_enhance": "OFF",
"guidances": {
"image_reference": [
{
"image": {
"id": "00000000-0000-0000-0000-000000000001",
"type": "UPLOADED"
}
}
]
}
}
}'
API 请求端点、请求头和参数
端点
https://cloud.leonardo.ai/api/rest/v2/generations
请求头
--header "accept: application/json" \
--header "authorization: Bearer <YOUR_API_KEY>" \
--header "content-type: application/json"
请求体参数
| 参数 | 类型 | 定义 |
|---|---|---|
| guidances | object | 可选。定义影响生成结果的图像引导输入的对象。 |
| guidances.image_reference | array | 可选。最多 6 张参考图像的数组。每个参考项包含 image.id 和 image.type(GENERATED 或 UPLOADED)。注意:GPT Image 2 不使用强度参数处理图像参考。 |
| height | integer | 可选。高度输入分辨率。 |
| model | string | 必填。模型标识符。设置为 gpt-image-2。 |
| prompt | string | 必填。描述你希望模型生成的图像内容的文本提示。 |
| prompt_enhance | string | 可选。设置为 "ON" 时启用提示词增强;设置为 "OFF" 时禁用。 |
| public | boolean | 可选。布尔标志,决定生成内容是公开(true)还是私有(false)。 |
| quality | string | 可选。接受 LOW、MEDIUM 或 HIGH。 |
| quantity | integer | 可选。单次请求生成的图像数量(1-8)。 |
| width | integer | 可选。宽度输入分辨率。 |
宽高比设置
| 宽高比 | 宽度 | 高度 |
|---|---|---|
| 1:1 | 1024 | 1024 |
| 2:3 | 848 | 1264 |
| 3:2 | 1264 | 848 |
| 16:9 | 1376 | 768 |
| 9:16 | 768 | 1376 |
分辨率约束
GPT Image 2 支持灵活的自定义分辨率,需满足以下约束:
最大边长
width 和 height 都必须能被 16 整除。 宽高比限制
令 long = max(width, height),short = min(width, height)。
long / short ≤ 3
(宽高比不能超过 3:1 或 1:3。) 像素数量范围
655,360 ≤ width × height ≤ 8,294,400 不支持自动尺寸
不支持 size: "auto",不要向 API 传入该值。
更新于 4 个月前 这个页面对你有帮助吗?