n8n 集成
在 n8n 内部生成图像和视频 生成、等待、下载、发布,一个工作流全搞定
只需一个 API 密钥,即可将 n8n 连接到 BananaBanana,并在工作流中调用 Nano Banana、Veo、Gemini Omni、Wan、Grok Imagine、GPT Image、Qwen 和 Gemini TTS。两种接入方式:搭配 MCP Client Tool 节点的 AI Agent,或完全不需要语言模型的纯 HTTP Request 节点。
工作流能做什么,费用是多少
每次生成都从您的 BananaBanana 余额中扣费,价格与网站一致。没有订阅,也没有 n8n 专属费用。高成本调用(视频、一次生成多张图像)会先返回报价,在您确认之前不会扣费;失败和被过滤的生成会自动退款。
| 调用 | 价格 |
|---|---|
| 图像(generate_image、edit_image) | 每张 $0.03–$0.20 |
| 视频片段(generate_video、edit_video) | 每段 $0.06–$6.00 |
| 语音(generate_speech) | 每 200 个字符(不足按 200 计)$0.01 |
| 状态、模型、账户(get_result、list_models、get_account) | 免费 |
各模型、分辨率和时长的准确价格见 list_models 和价格页面。
创建 API 密钥
- 注册账户并为余额充值。
- 打开个人资料 → API Keys并创建密钥。密钥以
bb_live_开头,只显示一次,请直接复制到 n8n 凭据中。 - 为密钥设置与工作流相匹配的每日消费上限,例如您预计每天运行所需的费用。这样即使循环失控,也会在达到上限时停止,而不会耗尽余额。
- 在 n8n 中创建
Bearer Auth凭据,并将密钥粘贴为 Bearer Token。下面两种方式都使用这同一个凭据。
AI Agent + MCP Client Tool
添加一个 AI Agent 节点,连接一个聊天模型,再连接 MCP Client Tool 节点,并按以下方式设置:
Node: MCP Client Tool (connect it to the AI Agent "Tool" input)
Endpoint URL: https://bananabanana.pro/api/mcp
Server Transport: HTTP Streamable
Authentication: Bearer Auth → your BananaBanana credential
Tools to Include: Selected → list_models, get_account, generate_image, get_resultAgent 需要自己的语言模型(OpenAI、Anthropic、Gemini 或 n8n 支持的任何模型)及相应的 API 密钥:BananaBanana 负责生成媒体,由模型决定调用哪些工具。
价格确认
视频和多图调用会先返回 status: confirmation_required 以及 quoted_cost_usd,且不扣费。只有当同一调用带着与报价相同的 confirm_cost 再次发出时,才会扣款。请在 Agent 的系统消息中说明该怎么做:停止并报告价格(如下所示),或在您设定的限额内自行确认。
现成工作流中使用的系统消息
You create images with the BananaBanana tools. Call generate_image with the user's
request (model nano-banana-2-lite unless the user names another model; list_models
shows models and prices). generate_image returns a job_id: call get_result with that
job_id and wait_seconds 30 until status is completed. If a tool answers status
confirmation_required, tell the user the quoted price and stop: never pass
confirm_cost on your own. Finish with the first file URL from get_result on its own line.生成是异步的:generate_image 返回 job_id,get_result 每次调用最多等待 30 秒,直到文件就绪。返回内容包含带签名的文件链接,由 Agent 之后的 HTTP Request 节点将其作为文件下载。
Node: HTTP Request (after the AI Agent)
Method: GET
URL: {{ $json.output.match(/https?:\/\/\S+?\/api\/files\/[^\s)"'\]]+/)[0] }}
Options → Response → Response Format: FileHTTP Request 节点,无需语言模型
MCP 端点是通过 POST 发送的普通 JSON,因此用常规的 HTTP Request 节点即可直接调用。这是最便宜、最可预测的方式:没有模型 token 开销,也不会有 Agent 自行选择参数。
- 生成图像 — 对
generate_imagePOST 一个tools/call。在idempotency_key中使用{{ $execution.id }}:如果 n8n 重试该节点,相同的 key 会返回原来的任务,而不会重复扣费。 - 获取结果 — 携带
job_id和wait_seconds: 30POSTget_result。用If节点把status: processing送入 5 秒的Wait后再回到查询;completed则继续向下执行。 - 下载文件 — 将 Response Format 设为 File,GET
files[0].url。得到的二进制数据可传给 Google Drive、S3、WordPress、YouTube、社交媒体发布等任何接受文件的节点。
Node: HTTP Request "Generate image"
Method: POST
URL: https://bananabanana.pro/api/mcp
Authentication: Generic Credential Type → Bearer Auth
Send Headers: Accept = application/json, text/event-stream
Send Body: JSON →
{{ JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: {
name: "generate_image",
arguments: { prompt: $json.prompt, model: "nano-banana-2-lite",
aspect_ratio: "1:1", idempotency_key: "n8n-" + $execution.id } } }) }}
→ {{ $json.result.structuredContent.job_id }} (status: "processing")Node: HTTP Request "Get result" (same URL, credential and headers)
{{ JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: {
name: "get_result",
arguments: { job_id: $('Generate image').item.json.result.structuredContent.job_id,
wait_seconds: 30 } } }) }}
If {{ $json.result.structuredContent.status }} is "processing" → Wait 5 s → Get result
If … is "completed" → HTTP Request GET {{ $json.result.structuredContent.files[0].url }}
Options → Response → Response Format: File视频:报价、检查、确认
对于 generate_video,需要发送两次调用:第一次的返回中包含 quoted_cost_usd;用 If 节点将其与您的限额比较,通过后第二次调用再把它作为 confirm_cost 传回。视频需要一到十分钟,所以请保留 get_result 循环。
1. generate_video { prompt, model: "veo-3.1-fast", duration: 8, resolution: "720p" }
← { status: "confirmation_required", quoted_cost_usd: 0.70 } nothing charged
2. If {{ $json.result.structuredContent.quoted_cost_usd }} ≤ your limit
3. generate_video { …same arguments…, confirm_cost: {{ $json.result.structuredContent.quoted_cost_usd }},
idempotency_key: "n8n-" + $execution.id }
← { job_id, status: "processing", cost_charged_usd: 0.70 }
4. get_result loop as above (videos take 1–10 minutes)一分钟导入工作流
两个工作流都不含任何密钥或凭据。在 n8n 中选择 Workflows → Import from File(或将 JSON 粘贴到编辑器中),然后在带警告标记的节点中选择您自己的凭据。
AI Agent + MCP Client Tool:Manual Trigger → AI Agent(OpenAI Chat Model、BananaBanana MCP)→ 下载文件。请选择您的 OpenAI 凭据和 Bearer Auth 凭据。
下载 JSON · bananabanana-n8n-agent.jsonHTTP Request:Manual Trigger → 请求设置 → 生成图像 → 获取结果(带等待循环)→ 下载文件,并包含明确的错误终止分支。请在三个请求节点中选择 Bearer Auth 凭据。
下载 JSON · bananabanana-n8n-http.json
两个工作流都已在自托管的 n8n 2.48.7 上导入并完整执行验证;默认图像每次运行费用为 $0.03。
常见错误及处理方法
401— 密钥缺失、输入有误或已被撤销。凭据中必须填写密钥本身,Bearer 一词由 n8n 自动添加。INSUFFICIENT_BALANCE— 余额不足以支付此次调用。返回内容包含充值链接,未产生任何扣费。confirmation_required— 这不是错误:该调用需要confirm_cost(见方式 A 和视频流程)。RATE_LIMITED— 单个密钥每分钟的工具调用超过 20 次。请添加Wait节点,或启用 Retry On Fail 并设置间隔。DAILY_CAP_EXCEEDED— 密钥已达到您设置的每日上限。请在个人资料中调高上限,或等到下一个 UTC 日。SAFETY_FILTERED— 模型的内容过滤器拒绝了提示词或结果;已扣费用将退还。请改写提示词。- 文件链接 24 小时后失效。请在同一次运行中下载文件;30 天内
get_result会返回新的链接。
关于 n8n 与 BananaBanana 的常见问题
n8n 中有 BananaBanana 节点吗?
节点列表中暂时还没有。不过 n8n 自带的 MCP Client Tool 和 HTTP Request 节点已经可以调用 BananaBanana 的所有工具,上面的现成工作流也已替您配置好。
我需要 OpenAI 或其他模型的密钥吗?
仅方式 A 需要,由 AI Agent 决定调用哪个工具。使用 HTTP Request 节点的方式 B 只需要 BananaBanana 密钥。
运行一次工作流要花多少钱?
正好是所生成内容的价格:图像低至 $0.03,视频片段低至 $0.06,语音每 200 个字符(不足按 200 计)$0.01。状态查询和下载免费,失败的生成会退款。
重试或循环会让我被重复扣费吗?
只要调用中带有 idempotency_key 就不会:使用相同 key 的重复调用会返回原来的任务,不会再次扣费。为密钥设置每日上限,还能限制循环失控造成的损失。
工作流可以使用哪些模型?
平台的所有模型:图像有 Nano Banana 2、2.1、Lite 和 Pro、GPT Image 与 Qwen;视频有 Veo 3.1、Gemini Omni、Wan 3.0 与 Grok Imagine;语音有 Gemini TTS。list_models 会返回当前列表及价格。