APIMODELSAPIMODELS
API 文档

apimodels.app

Docs/图片生成/Nano Banana 2.1 API

Nano Banana 2.1 API

Google 的高效图像生成与编辑模型,模型名 nano-banana-2-1。文生图和改图是同一个模型:只给提示词就是生成,带上参考图(最多 10 张)就是编辑或融合。15 种画面比例,1K / 2K / 4K 三档输出,每张 $0.022 / $0.036 / $0.06,成功才扣费。

认证

所有请求在 Header 携带 API Key:

Authorization: Bearer YOUR_API_KEY

价格(按分辨率,每张)

resolution价格 / 张说明
1K$0.022默认档
2K$0.036
4K$0.06最高档

价格只看分辨率:参考图张数、画面比例、提示词长短都不影响价格。不传 resolution 按 1K 计。失败不扣费。计费示例:1K 100 张 = $2.20,2K 100 张 = $3.60,4K 100 张 = $6.00。

文生图

POST/v1/images/generations

异步契约:创建任务立即返回 taskId,再轮询 GET /v1/images/generations?task_id= 直到 state 为 completed 取 resultUrls,或者传 callback_url 接 webhook。下面这条正是我们 2026-10-07 首测用的请求:16:9、1K,约 20 秒出图,实得 1376×768,招牌文字拼写正确。

# Step 1: create the task (text-to-image) — returns a taskId right away
curl -X POST https://api.apimodels.app/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2-1",
    "prompt": "A cozy bookstore cafe on a rainy evening, warm window light, a hand-painted sign reading NANO BANANA 2.1 above the door, cinematic wide shot",
    "aspect_ratio": "16:9",
    "resolution": "1K"
  }'
# → { "code": 200, "data": { "taskId": "...", "state": "pending", "model": "nano-banana-2-1" } }

# Step 2: poll until state is "completed" (or "failed")
curl "https://api.apimodels.app/v1/images/generations?task_id=TASK_ID" \
  -H "Authorization: Bearer YOUR_API_KEY"
# → { "code": 200, "data": { "state": "completed", "resultUrls": ["https://..."] } }

改图 · 多图融合

同一端点、同一个模型名:传 image(单张)或 image_urls(数组)就进入编辑,两者合计最多 10 张。每张可以是 URL、data URI 或裸 base64,格式 JPEG / PNG / WebP。在提示词里按「图 1、图 2」指代参考图即可。

# Edit one image — image accepts a URL, a data URI or bare base64
curl -X POST https://api.apimodels.app/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2-1",
    "prompt": "Keep the room and the lighting, replace the sofa with a dark green velvet one",
    "image": "https://example.com/living-room.jpg",
    "resolution": "2K"
  }'

# Combine several references — image_urls takes up to 10 (image + image_urls together: 10 max)
curl -X POST https://api.apimodels.app/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2-1",
    "prompt": "Put the character from image 1 into the street scene from image 2, wearing the jacket from image 3",
    "image_urls": [
      "https://example.com/character.png",
      "https://example.com/street.jpg",
      "https://example.com/jacket.jpg"
    ],
    "aspect_ratio": "4:5",
    "resolution": "2K"
  }'
# Poll GET ?task_id= exactly as in the text-to-image example.

请求参数

字段必填类型说明
model是stringnano-banana-2-1
prompt是string图片描述或编辑指令,最长 20,000 字符
image否string单张参考图:URL、data URI 或裸 base64(也可用 image_url / image_base64)
image_urls否string[]多张参考图,与 image 合计最多 10 张;超过 10 张返回 400
aspect_ratio否stringauto, 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 1:4, 4:1, 1:8, 8:1。默认 auto
resolution否string1K(默认)/ 2K / 4K,决定价格
callback_url否string任务完成后回调的 webhook 地址,可代替轮询

任务状态

  • pending / processing:还在生成,隔 2–3 秒再查
  • completed:data.resultUrls 里是结果图链接
  • failed:data.failMsg 说明原因,这一单不扣费

和同门模型怎么选

  • gemini-3.1-flash-image(Nano Banana 2 正式版):1K/2K $0.06、4K $0.10,另有 512 档 $0.04。三档单价都高于 Nano Banana 2.1。
  • nanobanana2(Nano Banana 2 preview 通道):1K/2K $0.05、4K $0.08。
  • nanobanana-2-lite:统一 $0.025、只出 1K,同样最多 10 张参考图。
  • nanobananapro(Nano Banana Pro,Gemini 3 Pro Image):1K/2K $0.068、4K $0.13,画质与文字渲染上限更高时选它。

它们都走同一个端点、同一套参数,切换只改 model 一个字符串。

说明

  • 一次请求出一张图;要多张就并行多发几单,每单各自计费、各自可查。
  • aspect_ratio 传上表以外的值会返回 400,不会被静默改成别的比例。
  • 结果文件保留 30 天后自动删除,请及时下载或转存。
  • 失败不扣费。

试一试:Playground(不写代码,在网页上选比例、分辨率、传参考图)。

常见问题

Nano Banana 2.1 API 多少钱?

按张计价,只看分辨率:1K(默认)$0.022、2K $0.036、4K $0.06。参考图张数、画面比例、提示词长短都不影响价格,失败不扣费。

Nano Banana 2.1 怎么传参考图?

单张用 image,多张用 image_urls 数组,两者合计最多 10 张,超过 10 张返回 400。每张可以是 URL、data URI 或裸 base64,格式 JPEG / PNG / WebP。数组字段请写 image_urls 而不是 images —— 图片端点读的是 image_urls。

Nano Banana 2.1 支持哪些画面比例?

15 种:auto(默认)、1:1、2:3、3:2、3:4、4:3、4:5、5:4、9:16、16:9、21:9,以及适合横幅和长条图的 1:4、4:1、1:8、8:1。传其它值返回 400,不会被悄悄换成相近的比例。