Nano Banana API
Use this skill when an agent needs to call Nano Banana directly instead of only editing docs.
Official website: INLINECODE0
Quick Start
Set an API key with NANO_BANANA_API_KEY or NB_API_KEY.
Use the bundled CLI for repeatable calls:
CODEBLOCK0
Workflow
- 1. Call
models first when the model name matters. - Omit
--model unless the user explicitly asks for a specific model. - Choose request mode by interaction pattern:
-
sync: simplest request/response flow.
-
stream: real-time progress via SSE.
-
async: immediate submission plus later polling.
- 4. Use
poll --id <generation_id> --wait when an async task must be followed to completion. - Download images during the same session when the user wants local files. Output URLs expire after 15 days.
Operational Rules
- - Do not print or restate the raw API key.
- Prefer
models over hardcoding catalog values. The live model list changes and is the source of truth. - If docs and live API behavior disagree, trust the live endpoints and mention the date of verification.
- Treat
401, 402, 403, and 503 as actionable operational states:
-
401: invalid or missing key.
-
402: insufficient credits.
-
403: account does not have API access enabled.
-
503: async queue is busy; retry later.
- - For
stream, expect newline-delimited SSE data: events. - For
async, only declare success after processingStatus becomes completed.
Command Guide
List models
CODEBLOCK1
Use this before selecting --model. Live verification on 2026-03-25 showed model names that differ from examples in the docs, so avoid assuming nano-banana is the current explicit model ID.
Check credits
CODEBLOCK2
Generate synchronously
CODEBLOCK3
Generate asynchronously and wait
CODEBLOCK4
Follow an existing job
CODEBLOCK5
Generate from a reference image
CODEBLOCK6
Fallback Without The Script
If direct shell execution is unavailable, construct HTTP calls from references/api-reference.md. Use:
- -
POST /generate for sync, stream, or async submission. - INLINECODE26 for polling.
- INLINECODE27 to resolve current model names.
- INLINECODE28 to inspect balance.
Resources
Nano Banana API
当智能体需要直接调用Nano Banana而非仅编辑文档时,使用此技能。
官方网站:https://www.nananobanana.com
快速开始
通过NANOBANANAAPIKEY或NBAPI_KEY设置API密钥。
使用捆绑的CLI进行可重复调用:
bash
python3 scripts/nanobananaapi.py models
python3 scripts/nanobananaapi.py credits
python3 scripts/nanobananaapi.py generate --prompt 一只坐在火车上的电影感橘猫 --mode sync
python3 scripts/nanobananaapi.py generate --prompt 将背景替换为海滩 --reference-image-url https://example.com/image.jpg --mode async --wait
python3 scripts/nanobananaapi.py generate --prompt 夜晚的赛博朋克天际线 --mode stream
工作流程
- 1. 当模型名称重要时,首先调用models。
- 除非用户明确要求特定模型,否则省略--model。
- 根据交互模式选择请求方式:
- sync:最简单的请求/响应流程。
- stream:通过SSE实时获取进度。
- async:立即提交,后续轮询。
- 4. 当异步任务必须跟踪至完成时,使用poll --id --wait。
- 当用户需要本地文件时,在同一会话中下载图片。输出URL在15天后过期。
操作规则
- - 不要打印或复述原始API密钥。
- 优先使用models而非硬编码目录值。实时模型列表会变化,且是权威来源。
- 如果文档和实时API行为不一致,以实时端点为准,并注明验证日期。
- 将401、402、403和503视为可操作的状态:
- 401:密钥无效或缺失。
- 402:积分不足。
- 403:账户未启用API访问权限。
- 503:异步队列繁忙,请稍后重试。
- - 对于stream,期待换行符分隔的SSE data:事件。
- 对于async,仅在processingStatus变为completed后声明成功。
命令指南
列出模型
bash
python3 scripts/nanobananaapi.py models
在选择--model前使用此命令。2026年3月25日的实时验证显示,模型名称与文档中的示例不同,因此避免假设nano-banana是当前的显式模型ID。
检查积分
bash
python3 scripts/nanobananaapi.py credits
同步生成
bash
python3 scripts/nanobananaapi.py generate \
--prompt 日出时分的水彩山村 \
--mode sync \
--download-dir ./outputs
异步生成并等待
bash
python3 scripts/nanobananaapi.py generate \
--prompt 香蕉形台灯的产品主图 \
--mode async \
--wait \
--poll-interval 3 \
--max-polls 60
跟踪现有任务
bash
python3 scripts/nanobananaapi.py poll --id clxx123 --wait
从参考图片生成
bash
python3 scripts/nanobananaapi.py generate \
--prompt 保留主体,将房间变成粗野主义画廊 \
--reference-image-url https://example.com/source.jpg \
--mode sync
无脚本时的备用方案
如果无法直接执行shell,请从references/api-reference.md构建HTTP调用。使用:
- - POST /generate 用于同步、流式或异步提交。
- GET /generate?id=... 用于轮询。
- GET /models 用于解析当前模型名称。
- GET /credits 用于检查余额。
资源