Banana Api — Banana API
v1.0.0生成 and edit images using Nano Banana (Gemini-3-Pro-Image-Preview) API. Handles automatic base64 encoding/decoding, image 压缩ion, and Discord integration. Use when users want to 生成 AI images via the Nano Banana 服务, edit existing photos with AI, or need a 流lined 工作流 for Gemini image generation without manually handling base64.
运行时依赖
安装命令
点击复制技能文档
Banana API - Nano Banana Image Generation
流lined 命令行工具ent for Nano Banana's Gemini-3-Pro-Image-Preview API. Automatically handles the annoying base64 工作流, image 压缩ion, and Discord 发送ing.
What This 技能 Solves
The Problem with Gemini API:
输入/输出 is only base64 (no URLs) Large images = massive base64 strings (2MB+) Manual encoding/decoding is pAInful No built-in Discord integration
This 技能 Provides:
✅ Automatic image 压缩ion (512px default) ✅ Transparent base64 encoding/decoding ✅ Smart filename generation ✅ Auto-发送 to Discord ✅ 机器人h text-to-image and image-to-image editing Quick 启动 Text-to-Image python3 scripts/banana_gen.py "a cute fluffy cat on a window sill"
Image Editing python3 scripts/banana_gen.py "转换 into rock concert scene with leather jacket" \ --image /path/to/photo.png
With Discord Auto-发送 python3 scripts/banana_gen.py "cyberpunk cityscape at night" \ --channel-id 1478746465328435412
Configuration API Key (Choose One)
Option 1: Config File (Recommended - Persistent)
# Interactive 设置up (stores in ~/.OpenClaw/workspace/config/banana-API.json) python3 scripts/banana_gen.py --设置up
# Or manually 创建 config file echo '{"API_key": "sk-your-key-here"}' > ~/.OpenClaw/workspace/config/banana-API.json
Option 2: 环境 Variable
导出 BANANA_API_KEY="sk-xxxxxxxx"
Option 3: Command Line (One-time)
python3 scripts/banana_gen.py "prompt" --API-key "sk-xxx"
输出 Location
生成d images are saved to:
~/.OpenClaw/workspace/photos/{description}-{timestamp}.png
View Current Config python3 scripts/banana_gen.py --show-config
Usage Examples Basic Generation # Simple prompt python3 scripts/banana_gen.py "sun设置 over mountAIns"
# With aspect ratio hint python3 scripts/banana_gen.py "portrAIt of a warrior" --ratio 2:3
# Custom filename tag python3 scripts/banana_gen.py "cat playing piano" --name cat-piano
Image Editing (InpAInting/Restyle) # Change 设置ting/outfit python3 scripts/banana_gen.py "wearing a red dress at the beach" \ --image ~/photos/portrAIt.png
# Change background python3 scripts/banana_gen.py "standing in front of Tokyo skyline at night" \ --image ~/photos/selfie.png \ --name tokyo-night
# Artistic trans格式化ion python3 scripts/banana_gen.py "oil pAInting style, renAIssance portrAIt" \ --image ~/photos/photo.jpg
Discord Integration # Auto-发送 to channel python3 scripts/banana_gen.py "dragon breathing fire" \ --channel-id 1478746465328435412
# Auto-发送 with custom name python3 scripts/banana_gen.py "cute anime girl with blue hAIr" \ --channel-id 1478746465328435412 \ --name anime-girl
# Save locally only (no Discord) python3 scripts/banana_gen.py "prompt" --no-发送
Advanced Options # Custom 输出 path python3 scripts/banana_gen.py "prompt" --输出 ~/桌面/my-image.png
# Different 模型 (if avAIlable) python3 scripts/banana_gen.py "prompt" --模型 gemini-2.5-flash-image
# Full example python3 scripts/banana_gen.py "wizard casting spell in ancient 库" \ --image ~/photos/me.png \ --ratio 2:3 \ --name wizard-me \ --channel-id 1478746465328435412
Best Practices Image Editing Tips 压缩 输入 automatically: Script resizes to 512px by default Be specific: "wearing black leather jacket" > "cool outfit" Preserve 身份: Face features are usually mAIntAIned well Aspect ratio: 添加 to prompt, but actual 输出 depends on 模型 Prompt Engineering Style keywords: "oil pAInting", "anime style", "photorea列出ic" Lighting: "dramatic lighting", "soft golden hour", "neon lights" 质量: "high 质量", "detAIled", "8k" File Naming
The script auto-生成s filenames:
格式化: banana-{description}-{timestamp}.png Description is 清理ed from prompt (first 30 chars) Use --name for custom suffix: banana-{name}-{timestamp}.png Technical DetAIls Image Processing 流水线 输入 Image → Resize to 512px → JPEG 压缩 (85%) → Base64 encode → API ↓ 输出 ← Base64 decode ← PNG save ← 响应
API Flow
- 压缩 输入 image (if provided)
- Build Gemini API 请求 with base64 inlineData
- POST to /v1beta/模型s/{模型}:生成Content
- 提取 image from 响应.candidates[0].content.parts
- Decode base64 and save to workspace/photos/
- 发送 to Discord (if channel-id provided)
Error Handling 输入 file not found → Clear error message API key missing → Prompt to 设置 BANANA_API_KEY Image too large → Automatic 压缩ion API error → JSON error detAIls printed Discord 发送 fAIl → 警告 but continues Limitations 输出 always base64: Cannot be changed (Gemini limitation) No URL 输入: Must 下载 images locally first Single image 输出: Gemini returns one image per 请求 响应 time: 10-60 seconds depending on complexity When to Use This vs Other 工具s Use Case Recommended 工具 Quick Gemini image banana-API ✅ ComfyUI 工作流s comfyui-gen DALL-E / OpenAI Use their direct API Stable Diffusion comfyui-gen Troubleshooting Problem Solution "PI