进阶 docs.leonardo.ai 2026-11-22 15:11:20 · 0 阅读

第30章 Leonardo.AI 中使用 Nano Banana 2.1 生成图像指南

# 第30章 Nano Banana 2.1 本指南介绍如何通过 Leonardo.AI REST API 使用 Nano Banana 2.1 生成图像。 ## 示例请求 ``` curl --location 'https://cloud.leonardo.ai/api/rest/v2/generations' \ --header 'authorization: Bearer {api-key}' \ --header 'Content-Type: application/json' \ --data '{ "model": "google/nano-banana-2.1", "parameters": { "width": 1024, "height": 1024, "prompt": "a portrait-style photograph featuring a koala", "quantity": 1, "style_ids": [ "111dc692-d470-4eec-b791-3475abac4c46" ], "prompt_enhance": "OFF" }, "public": false }' ``` ## 配方 API 请求端点、Headers、参数 Endpoint ``` https://cloud.leonardo.ai/api/rest/v2/generations ``` Headers ``` --header "accept: application/json" \ --header "authorization: Bearer " \ --header "content-type: application/json" ``` Body 参数
参数类型说明
guidancesobject可选。定义图像引导输入的对象,会影响生成结果。
guidances.image_referencearray可选。最多 14 张参考图的数组。每张参考图包含 image.type(UPLOADED、GENERATED、VARIATION、URL 或 BASE64),以及 image.id(对应 UPLOADED、GENERATED 或 VARIATION)、image.url(type 为 URL 时必填)或 image.data(Base64 编码的图像数据,type 为 BASE64 时必填)之一。可选的 order(整数,最小值 0)用于指定参考图在列表中的位置。
heightinteger可选。输入分辨率的高度,默认 1024。有效的 height 和 width 组合见下方表格。
modelstring必填。模型标识符,设置为 google/nano-banana-2.1。
promptstring必填。描述希望模型生成什么图像的文本提示词。
prompt_enhancestring可选。控制提示词增强,可选值:"AUTO"、"ON"、"OFF",默认为 "AUTO"。
publicboolean可选。布尔值,决定生成结果是公开(true)还是私有(false)。
quantityinteger可选。单次请求生成的图像数量,默认 1,最大 8。
style_idsarray可选。用于为输出应用预设艺术风格的 style UUID 数组,最多 1 个。默认为 111dc692-d470-4eec-b791-3475abac4c46(Dynamic)。完整的 style ID 列表见下方表格。
widthinteger可选。输入分辨率的宽度,默认 1024。有效的 height 和 width 组合见下方表格。
## Height 和 Width 列表
模型HeightWidth
Nano Banana 2.1672, 768, 848, 896, 928, 1024, 1152, 1200, 1264, 1344, 1376, 1536, 1696, 1792, 1856, 2048, 2304, 2400, 2528, 2688, 2752, 3072, 3392, 3584, 3712, 4096, 4608, 4800, 5056, 5504768, 848, 896, 928, 1024, 1152, 1200, 1264, 1376, 1536, 1584, 1696, 1792, 1856, 2048, 2304, 2400, 2528, 2752, 3072, 3168, 3392, 3584, 3712, 4096, 4608, 4800, 5056, 5504, 6336
## 尺寸 API 支持以下宽高比组合的 width 和 height 参数:
宽高比1K(小)2K(中)4K(大)
1:11024 × 10242048 × 20484096 × 4096
2:3848 × 12641696 × 25283392 × 5056
3:21264 × 8482528 × 16965056 × 3392
3:4896 × 12001792 × 24003584 × 4800
4:31200 × 8962400 × 17924800 × 3584
4:5928 × 11521856 × 23043712 × 4608
5:41152 × 9282304 × 18564608 × 3712
9:16768 × 13761536 × 27523072 × 5504
16:91376 × 7682752 × 15365504 × 3072
21:91584 × 6723168 × 13446336 × 2688
另外还支持以下 1:1 尺寸:768 × 768、848 × 848、896 × 896、928 × 928、1152 × 1152、1200 × 1200、1264 × 1264、1376 × 1376、1696 × 1696、1792 × 1792、1856 × 1856、2304 × 2304、2400 × 2400、2528 × 2528、2752 × 2752、3392 × 3392、3584 × 3584、3712 × 3712、4608 × 4608、4800 × 4800、5056 × 5056、5504 × 5504。 注意:width 和 height 参数会各自独立校验,但不会校验其组合是否符合支持的宽高比配对。也就是说,即使两个值各自有效,但组合不在上表列出的支持范围内,请求依然会被接受。此时传给模型的宽高比会静默回退为 1:1,且不会返回任何校验错误。 为确保使用预期的宽高比,请务必提供与支持配对完全一致的 width 和 height 组合。 当 width 和 height 均为 0 时,系统会尝试匹配输入参考图的宽高比。 ## Style ID 列表
预设风格UUID
3D Renderdebdf72a-91a4-467b-bf61-cc02bdeb69c6
Acrylic3cbb655a-7ca4-463f-b697-8a03ad67327c
Creative6fedbf1f-4a17-45ec-84fb-92fe524a29ef
Dynamic111dc692-d470-4eec-b791-3475abac4c46
Fashion594c4a08-a522-4e0e-b7ff-e4dac4b6b622
Game Concept09d2b5b5-d7c5-4c02-905d-9f84051640f4
Graphic Design 2D703d6fe5-7f1c-4a9e-8da0-5331f214d5cf
Graphic Design 3D7d7c2bc5-4b12-4ac3-81a9-630057e9e89f
Illustration645e4195-f63d-4715-a3f2-3fb1e6eb8c70
None556c1ee5-ec38-42e8-955a-1e82dad0ffa1
Portraitab5a4220-7c42-41e5-a578-eddb9fed3d75
Portrait Cinematic4edb03c9-8a26-4041-9d01-f85b5d4abd71
Portrait Fashion0d34f8e1-46d4-428f-8ddd-4b11811fa7c9
Pro B&W photography22a9a7d2-2166-4d86-80ff-22e2643adbcf
Pro Color Photography7c3f932b-a572-47cb-9b9b-f20211e63b5b
Pro Film Photography581ba6d6-5aac-4492-bebe-54c424a0d46e
Ray Tracedb504f83c-3326-4947-82e1-7fe9e839ec0f
Stock Photo5bdc3f2a-1be6-4d1c-8e77-992a30824a2c
Watercolor1db308ce-c7ad-4d10-96fd-592fa6b75cc4
## 图像引导 ### 示例请求 ``` curl --location 'https://cloud.leonardo.ai/api/rest/v2/generations' \ --header 'authorization: Bearer {api-key}' \ --header 'Content-Type: application/json' \ --data '{ "model": "google/nano-banana-2.1", "parameters": { "width": 1024, "height": 1024, "prompt": "A koala is wearing a colourful Hawaiian shirt", "quantity": 1, "guidances": { "image_reference": [ { "image": { "id": "fc6f78c6-e7ac-491b-ad26-01f6843db870", "type": "GENERATED" } }, { "image": { "id": "a8e374dd-52f8-4236-ad9e-99b1f601fa3a", "type": "UPLOADED" } } ] }, "style_ids": [ "111dc692-d470-4eec-b791-3475abac4c46" ], "prompt_enhance": "OFF" }, "public": false }' ``` 更新于 26 天前  这个页面对你有帮助吗?

评论 (0)