知识库 · AI 智能体
5、n8n 主流平台批量文生图工作流实操
本篇详解n8n批量文生图工作流全流程,涵盖liblib、runninghub、ComfyUI、即梦、Fluxshell、GPT-Image-1、Google Imagen等平台。采用统一schema+适配器模式,实现批量工厂与即时机器人,支持PPRR循环(感知-规划-执行-回顾),助你高效搭建多模型AI出图系统。
5、n8n 主流平台批量文生图工作流实操
2025年9月28日修改
n8n 批量文生图工作流全流程(liblib / runninghub / ComfyUI / 即梦 / Fluxshell / GPT-img1 / Google Imagen / Gooogle Nano Banana)
【难度较大,看文档能大概理解,搭建基本的即梦和liblib生图工作流即可】
一)课程地图(全景→细节)
我结合sop的一些内容和ChatGPT5的深度思考和互联网搜索,得到一份比较完整的各平台对比表格,供大家参考。
电子表格 · 内容不可用
PPRR 循环
感知:Form / Webhook / Google Sheets / Bitable / Schedule Trigger
规划:Set 统一字段 → Switch 路由 → Provider 适配
执行:Split In Batches + Wait 限速,HTTP Request/官方节点出图,Retry on fail
回顾:上传图床(或飞书 Drive)、回写表/Notion、Error Trigger 告警、成本/成功率看板
目标成品
批量出图工厂:从表格批量读取任务 → 多模型限速生成 → 上传图床 → 回写链接与成本
即时出图机器人:Webhook/表单一键生成(沿用同一“统一 schema + 适配器”)
二)预备知识与环境
必备
n8n(建议 Docker)
任务源:n8n form表单 / 飞书 Bitable(二选一)
模型凭证(至少 1 个):Together(可走 FLUX/GPT-Image-1),或你已有的 liblib/runninghub/即梦/Fluxshell;自部署 ComfyUI(启动需 --enable-api)
凭证清单(先配好)
Google OAuth / 飞书凭证(Bitable/Drive)
Together / 其他平台 API Key(用 n8n Credentials,别放在 Set 明文)
Cloudinary(可选)
三)核心节点
触发:Schedule Trigger(定时扫表)、Form/Webhook(即时触发)
控制流:Split In Batches(批量限速)、Wait(批间停顿)、IF/Switch(路由)、Merge(汇合)
数据:Set(统一 schema)、Code(尺寸解析/成本估算/ComfyUI JSON 组装)
执行:HTTP Request(万能),官方 OpenAI/Cloudinary/Google 节点(能用就用)
观测:Error Trigger(失败→群里告警)
四)模型调用“金字塔”(选型优先级)
官方商业 API(质稳):OpenAI GPT-Image-1、Google Imagen4(质量/稳定性高,成本高)
托管开源聚合(性价比):liblib / runninghub / Fluxshell / 即梦(多模型、排队与稳定性因平台而异)
自部署(终极控制):ComfyUI(零单次费,需 GPU 与维护;API 为“节点图”JSON)
策略:优先走可控且稳定的(Together/官方/企业托管),再兜底开源聚合,最后上自部署。所有分支都走统一输入/输出,随时可替换。
五)统一 schema(极简而通用)
我们把任何来源的任务规范成下列字段,下游所有分支只吃这套:
代码块
{
"request_id": "<自生成哈希,幂等>",
"prompt": "主提示词(英文/中文均可)",
"negative": "可选负面词",
"model": "gpt-image-1 | flux-schnell | imagen | comfyui | liblib | runninghub | jimeng | fluxshell ...",
"width": 1024,
"height": 1024,
"steps": 25,
"cfg": 7.5,
"seed": null,
"style_preset": "可选:风格代号/你的风格库 key",
"ref_image_url": "可选:参考图",
"output_format": "url | b64",
"meta": { "source_row": 123, "source_sheet": "Tasks" }
}课堂心法:入口统一、出口统一、Provider 只做“翻译”。这样换模型=换“适配器”节点,而不是改全局。
六)实战:从 0 搭“批量 AI 艺术工厂”(12 步)
这里先给大家看前面半部分,主要是接受参数,优化提示词,设置路由,到后续具体的平台分支出图。
触发我这里设置了两种方式,一种是n8n中的表单填写,另一种是我们通过父工作流触发,父工作流可以有很多种方式,比如MCP调用,webhook调用,飞书notion等应用事件触发。
1、任务源/触发器
我们这里是用的是表单,未来大家也可以集成到一些文档中,增加触发事件,比如飞书,Notion或者Google Sheets(Google Sheets Trigger:On Row Added(或 Schedule 每 10 分钟扫一次“status=todo”)读出 prompt/model/size/style/ref_image 等原始列)。
复制粘贴下面的json内容到n8n工作流编辑页面,参考其中的内容。内置了很多图像风格,如果希望按照提示词来,则可以选择 跟随提示词 下拉框
代码块
{
"nodes": [
{
"parameters": {
"formTitle": "AI破局:n8n 图片生成工作流",
"formDescription": "多风格创作,助力每一次灵感!",
"formFields": {
"values": [
{
"fieldLabel": "提示词",
"fieldType": "textarea",
"requiredField": true
},
{
"fieldLabel": "平台/模型",
"fieldType": "dropdown",
"fieldOptions": {
"values": [
{
"option": "black-forest-labs/FLUX.1-schnell-Free"
},
{
"option": "GPT Image 1"
},
{
"option": "RunningHub"
},
{
"option": "本地ComfyUI"
},
{
"option": "Google Imagen"
},
{
"option": "Liblib AI"
},
{
"option": "即梦"
}
]
},
"requiredField": true
},
{
"fieldLabel": "图片风格",
"fieldType": "dropdown",
"fieldOptions": {
"values": [
{
"option": "代码风格名片"
},
{
"option": "吉卜力风格"
},
{
"option": "乐高城市景观"
},
{
"option": "玻璃材质重塑"
},
{
"option": "水晶球故事场景"
},
{
"option": "怀旧动漫风格电影海报"
},
{
"option": "社交媒体相框融合"
},
{
"option": "Logo 形状创意书架"
},
{
"option": "定制Q版钥匙扣"
},
{
"option": "金色吊坠项链"
},
{
"option": "迷你 Cyberpunk 傾斜移軸景觀"
},
{
"option": "未来主义 Logo 交易卡"
},
{
"option": "超写实3D游戏"
},
{
"option": "Trompe-l'œil 三维空间艺术"
},
{
"option": "个性化房间设计"
},
{
"option": "3D Q版风格"
},
{
"option": "复古宣传海报"
},
{
"option": "美式传统复古纹身艺术"
},
{
"option": "可爱珐琅别针"
},
{
"option": "迷你 3D 建筑"
},
{
"option": "“极其平凡”的iPhone自拍"
},
{
"option": "物理破坏效果卡片 (劳拉)"
},
{
"option": "时尚杂志封面风格"
},
{
"option": "键盘ESC 键帽微型立体模型"
},
{
"option": "RPG 风格角色卡片制作"
},
{
"option": "3D Q版情侣水晶球"
},
{
"option": "微型立体场景 (孙悟空三打白骨精)"
},
{
"option": "手绘信息图卡片"
},
{
"option": "极简主义 3D 插画 (文字版)"
},
{
"option": "小红书封面"
},
{
"option": "3D 情侣珠宝盒摆件"
},
{
"option": "古典现实主义"
},
{
"option": "拼贴画"
},
{
"option": "视频游戏概念艺术"
},
{
"option": "社交媒体相框"
},
{
"option": "演唱会海报设计 "
},
{
"option": " 肖像画风格"
},
{
"option": "批判现实主义"
},
{
"option": "立体主义艺术"
},
{
"option": "桥社风格/涂鸦"
},
{
"option": "迪士尼动画风格"
},
{
"option": "童话艺术"
},
{
"option": "野兽派"
},
{
"option": "极简主义 3D 插画"
},
{
"option": "布丁老虎机"
},
{
"option": "彩色矢量艺术海报"
},
{
"option": "8位像素图标"
},
{
"option": "跟随提示词"
}
]
},
"requiredField": true
},
{
"fieldLabel": "图片尺寸",
"fieldType": "dropdown",
"fieldOptions": {
"values": [
{
"option": "1024x1024 (1:1) GPT"
},
{
"option": "1536x1024 (3:2) GPT"
},
{
"option": "1024x1536 (2:3) GPT"
},
{
"option": "1280x720 (16:9)"
},
{
"option": "640x960 (2:3)"
},
{
"option": "720x1280 (9:16)"
},
{
"option": "768x1024 (3:4)"
},
{
"option": "1280x960 (4:3)"
},
{
"option": "1280x960 (4:3)"
},
{
"option": "1280x800 (16:10)"
},
{
"option": "1200x800 (3:2)"
},
{
"option": "1200x800 (3:2)"
},
{
"option": "1024x512 (2:1)"
}
]
}
},
{
"fieldLabel": "透明度",
"fieldType": "dropdown",
"fieldOptions": {
"values": [
{
"option": "auto"
},
{
"option": "transparent"
},
{
"option": "opaque"
}
]
},
"requiredField": true
}
]
},
"options": {
"appendAttribution": false,
"buttonLabel": "开始生图",
"path": "xys-text-image-generator"
}
},
"type": "n8n-nodes-base.formTrigger",
"typeVersion": 2.2,
"position": [
-2896,
144
],
"id": "2a7fc84a-e8b6-4545-b7e2-e3e9cdda098e",
"name": "图片要求提交",
"webhookId": "de00e4a7-de71-4e60-b22c-5f7b545da5ec"
}
],
"connections": {
"图片要求提交": {
"main": [
[]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be33e7a4c93bf3fbad46ee9dd2261c1867b920251d4e05c1a2fedf55455fa8e4"
}
}输入-表单
接收表单的数据,标准化字段
统一成“5 统一字段”(prompt/size/style/model/background)
2、设置参数
把一些需要统一设置的参数填在这里,后面各个分支都能拿到。
(这些大家前期不用全部设置,按照自己的工作流后续需要实际设置的动态参数来定)
3、Agent|风格融合与英文化
把 prompt/style/size 喂进去,产出 prompt_en / width / height等等
用户提示词
代码块
图片基础元素描述:
{{ $json.Prompt }}
指定的艺术风格为:
{{ $json.Stytle }}
图片宽高尺寸及宽高比为:
{{ $json.Size }}系统提示词
代码块
# 角色:AI绘画图像风格提示词生成专家
你是一位专精于 Flux 风格及 GPT-image-1、即梦AI 等AI绘画模型风格提示词创作的专家,具备扎实的艺术理论背景与丰富的视觉风格分析经验,能够敏锐捕捉和提取视觉艺术作品中的关键风格元素,并高效地将这些元素转化为准确、细致的文本描述。你善于结合用户的创作意图与多种艺术风格特征,为 Flux 与 GPT-image-1 、即梦图像生成模型创作出精准、具有高度美学价值且能忠实复现指定艺术风格的提示词。
## 任务
1. 深入解析用户提供的图片基础元素描述与指定艺术风格,准确把握创作核心意图。
2. 从320个精选艺术风格库中,提炼用户所选风格的关键视觉元素与独特美学特征。
3. 如果用户指定的艺术风格不在现有风格库中,则根据用户提供的风格描述或参考图片,分析其独特视觉特征、色彩倾向、构图规律和艺术表现手法,创建定制化风格描述。
4. 巧妙融合提取的风格特征与用户基础描述,打造风格表现力强、专业精准且完美契合用户期望的提示词,确保兼容 Flux 和 GPT-image-1 模型的生成需求。
## 目标
输出一个艺术化的图像生成提示词,该提示词需同时满足以下要求:
- 对 Flux & GPT-image-1、即梦AI 风格模型充分保留用户的原始创作意图,并精准融合所指定艺术风格的关键视觉特征。
- 输出的提示词中无需包含比例及尺寸信息。
## 输出格式
按照如下示例输出 JSON 格式结果
{
"image_name_zh": "<图片名称(中文)>",
"image_name_en": "<Image Name (English)>",
"prompt_zh": "<生成提示词(中文)>",
"prompt_en": "<Prompt for Generation (English)>",
"image_width": "<Image Width (px)>",
"image_height": "<Image Height (px)>"
}
## 图片风格参考:
1. **风格名称** : 代码风格名片 (by [@umesh_ai](https://x.com/umesh_ai))
**提示词**:
```
特写镜头:一只手正拿着一张设计成 VS Code 中 JSON 文件外观的名片。名片上的代码以真实的 JSON 语法高亮格式呈现。窗口界面包含典型的工具栏图标和标题栏,标题显示为 Business Card.json,整体风格与 VS Code 界面完全一致。背景略微虚化,突出展示名片内容。
名片上的 JSON 代码如下所示:
{
"name": "Jamez Bondos",
"title": "Your Title",
"email": "your@email.com",
"link": "yourwebsite"
}
```
2. **风格名称** : 乐高城市景观 (by [@dotey](https://x.com/dotey))
**提示词**:
```
创建一幅高度精细且色彩鲜艳的乐高版上海外滩景象。前景呈现经典的外滩历史建筑群,用乐高砖块精致还原西式与新古典主义风格的建筑立面,包括钟楼、穹顶、柱廊等细节。乐高小人们正在沿江漫步、拍照、观光,街道两旁停靠着经典样式的乐高汽车。背景是壮观的黄浦江,以蓝色半透明乐高砖拼接,江面上有乐高渡轮和游览船。对岸的浦东陆家嘴高楼林立,包括东方明珠塔、上海中心、金茂大厦和环球金融中心,这些超现代乐高摩天大楼色彩丰富、造型逼真。天空为乐高明亮蓝色,点缀少量白色乐高积木云朵,整体呈现充满活力与现代感的视觉效果。
```
3. **风格名称** : 玻璃材质重塑 (by [@egeberkina](https://x.com/egeberkina))
**提示词**:
```
retexture the image attached based on the json below:
{
"style": "photorealistic",
"material": "glass",
"background": "plain white",
"object_position": "centered",
"lighting": "soft, diffused studio lighting",
"camera_angle": "eye-level, straight-on",
"resolution": "high",
"aspect_ratio": "2:3",
"details": {
"reflections": true,
"shadows": false,
"transparency": true
}
}
```
*注意:此提示词需要上传参考图片。*
4. **风格名称** : 水晶球故事场景 (by [@dotey](https://x.com/dotey))
**提示词**:
```
一枚精致的水晶球静静摆放在窗户旁温暖柔和的桌面上,背景虚化而朦胧,暖色调的阳光轻柔地穿透水晶球,折射出点点金光,温暖地照亮了四周的微暗空间。水晶球内部自然地呈现出一个以 {嫦娥奔月} 为主题的迷你立体世界,细腻精美而梦幻的3D景观,人物与物体皆是可爱的Q版造型,精致而美观,彼此之间充满灵动的情感互动。整体氛围充满了东亚奇幻色彩,细节极为丰富,呈现出魔幻现实主义般的奇妙质感。整个场景如诗如梦,华美而典雅,散发着温馨柔和的光芒,仿佛在温暖的光影中被赋予了生命。
```
*注意:可替换提示词中括号 {} 内文字。*
5. **风格名称** : 怀旧动漫风格电影海报 (by photis (Sora))
**提示词**:
```
{The Lord of the Rings} 的动漫电影海报,这张动漫海报的风格参考了《恶魔高中DXD(High School DXD)》。
海报上可以清晰看到折叠的痕迹,因为长时间以来被反复折叠,导致在褶皱处出现了物理性的损伤和擦痕,颜色也在部分区域出现了褪色。
由于来回搬动,海报表面散布着无规律的折痕、翻折痕迹和细微划痕,这些微小但不断累积的损耗,正如无法逃避的熵增过程一样,渐渐扩展。
然而,留存在我们心中的美好回忆却始终完整无缺。
当你凝视这张充满怀旧气息的海报时,所能感受到的,正是那些随着岁月积累、变得无比珍贵的点点收藏物所承载的情感本质。
```
大模型我这里选择的是Gemini-2.5-flash,大家也可以根据自己的需求和方便选择模型。
结构化解析
代码块
{
"image_name_zh": "<图片名称(中文)>",
"image_name_en": "<Image Name (English)>",
"prompt_zh": "<生成提示词(中文)>",
"prompt_en": "<Prompt for Generation (English)>",
"image_width": "<Image Width (px)>",
"image_height": "<Image Height (px)>"
}可选 | 去重/幂等
Code 生成 request_id = md5(model + prompt + width + height + (ref_image_url||""))
在“结果表”里查这个 request_id 是否存在 → 存在则跳过(A−B)
可选 | 限速阀
Split In Batches(batchSize=8)→ 批尾 Wait(7500ms) → 回到 Split
统一把所有任务压平后再分发,避免单 Provider 峰值
4、Switch|路由
{{$('设置参数').item.json.Model}} in [“gpt-image-1”, “flux-schnell”, “imagen”, “comfyui”, “liblib”, “runninghub”, “jimeng”, “fluxshell”]
每个分支接“适配器(HTTP/官方)”
【注意】这里不一定每个平台都需要,大家按需即可,每个平台都跑通需要花不少时间。
参考json文件
代码块
{
"nodes": [
{
"parameters": {
"rules": {
"values": [
{
"conditions": {
"options": {
"caseSensitive": false,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"leftValue": "={{ $('设置参数').item.json.Model }}",
"rightValue": "black-forest-labs/FLUX.1-schnell-Free",
"operator": {
"type": "string",
"operation": "equals"
},
"id": "8dfc7437-ec98-476b-adfd-2263b23c4600"
}
],
"combinator": "and"
},
"renameOutput": true,
"outputKey": "black-forest-labs/FLUX.1-schnell-Free"
},
{
"conditions": {
"options": {
"caseSensitive": false,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "2e62839d-b620-4767-b64e-0b4b80380a2c",
"leftValue": "={{ $('设置参数').item.json.Model }}",
"rightValue": "GPT Image 1",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
}
],
"combinator": "and"
},
"renameOutput": true,
"outputKey": "GPT Image 1"
},
{
"conditions": {
"options": {
"caseSensitive": false,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "de00c2bf-d9b6-4699-a78e-daec475ba23f",
"leftValue": "={{ $('设置参数').item.json.Model }}",
"rightValue": "RunningHub",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
}
],
"combinator": "and"
},
"renameOutput": true,
"outputKey": "RunningHub"
},
{
"conditions": {
"options": {
"caseSensitive": false,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "753ca103-8439-4bbe-b798-b77bef2cadf4",
"leftValue": "={{ $('设置参数').item.json.Model }}",
"rightValue": "本地ComfyUI",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
}
],
"combinator": "and"
},
"renameOutput": true,
"outputKey": "本地ComfyUI"
},
{
"conditions": {
"options": {
"caseSensitive": false,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "efd9efde-e09c-437d-a8e6-a42be4244cd9",
"leftValue": "={{ $('设置参数').item.json.Model }}",
"rightValue": "Google Imagen",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
}
],
"combinator": "and"
},
"renameOutput": true,
"outputKey": "Google Imagen"
},
{
"conditions": {
"options": {
"caseSensitive": false,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "b199261d-175f-4763-ac6a-cc52271b391d",
"leftValue": "={{ $('设置参数').item.json.Model }}",
"rightValue": "Liblib AI",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
}
],
"combinator": "and"
},
"renameOutput": true,
"outputKey": "Liblib AI"
},
{
"conditions": {
"options": {
"caseSensitive": false,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "edca4391-27b8-43cd-aa20-68eba9784556",
"leftValue": "={{ $('设置参数').item.json.Model }}",
"rightValue": "即梦",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
}
],
"combinator": "and"
},
"renameOutput": true,
"outputKey": "即梦"
}
]
},
"options": {
"fallbackOutput": 0,
"ignoreCase": true,
"allMatchingOutputs": false
}
},
"type": "n8n-nodes-base.switch",
"typeVersion": 3.2,
"position": [
-1472,
224
],
"id": "fedbe967-4024-4cda-96d5-7a31b111bb61",
"name": "路由-模型"
}
],
"connections": {
"路由-模型": {
"main": [
[],
[],
[],
[],
[],
[],
[]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be33e7a4c93bf3fbad46ee9dd2261c1867b920251d4e05c1a2fedf55455fa8e4"
}
}5、即梦(推荐)
即梦是字节跳动旗下的AI绘画,视频平台,中国风的相关内容效果非常好,整体综合实力比较强。
参考结果,一次请求四张图片
工作流整体节点参考
合法化宽高是可选的,用来约束输入的图片尺寸
(可能会存在即梦模型更新问题,导致部分尺寸即梦不支持,前期测试图片尺寸尽可能用1024x1024)
代码块
return items.map(it => {
const iw = it.json?.output?.image_width;
const ih = it.json?.output?.image_height;
const toInt = (s, def) => {
const n = Number(String(s ?? '').replace(/[^\d.-]/g, ''));
return Number.isFinite(n) ? Math.trunc(n) : def;
};
// 即梦系接口常见约束:正整数、范围、并常见要求按 64 对齐
const normalize = (n, min=512, max=2048, step=64) => {
n = Math.min(Math.max(n, min), max);
return Math.round(n / step) * step;
};
const width = normalize(toInt(iw, 1024));
const height = normalize(toInt(ih, 1024));
return {
json: {
...it.json,
prompt_zh: String(it.json?.output?.prompt_zh ?? ''),
width, // 纯 number
height // 纯 number
}
};
});n8n 调用即梦的两种方式对比
电子表格 · 内容不可用
方法一(可选):
即梦的API在火山引擎上面,我们首先要开通相关服务:https://www.volcengine.com/product/jimeng
点击即梦 AI-图片生成 的产品详情
按照这四步依次进行,最终我们在 n8n 里面一个 http 节点或者 n8n 的jimeng 节点 使用即梦的 AI 绘画能力
我们要先获取密钥,然后复制下来,作为后面即梦节点里面的凭证。
这种方法大家感兴趣可以尝试,参考文档:https://www.volcengine.com/docs/85621/1756900
下面内容大致参考下,主要是授权那个参数比较难处理
方法二(推荐):
官方认证的节点是这个 n8n-nodes-jimeng。
这样就说明安装成功了
回到 n8n 工作流页面搜索 jimeng 就能使用我们安装的这个节点了,其他的扩展节点也是类似的方法,大家后续可以举一反三。
点开发现很多节点,我们选择本次需要的文生图节点即可。
我们接着去创建凭证,注意,如果是插件节点 要这样获取
是F12快捷键 到 application 里面看 cookies 下的 jimeng 的 sessionid
保存到该节点的凭证,保存即可。
启动工作流,填写表单,进行变量引入和调试。
把路由里面对应的字段拖到里面去。
这样我们生成了四张图片
注意⚠️:即梦的图片长度宽度得是数字,别用字符串
对应我们前端页面也有这么多图片
如果是想把所有的图片都下载,增加一个code节点,命名 展开图片List
代码块
// 输入示例:{ list: ["https://...0.png","https://...1.png","https://...2.png","https://...3.png"] }
const urls = $json.list || [];
return urls.map((u, i) => ({ json: { url: u, index: i + 1 }}));
然后使用http节点,用请求每个url,即可下载。
写入到磁盘节点
取名可以参考下面的表达式
代码块
/data/files/1/{{ $('图片要求提交').item.json['平台/模型'] }}_{{ $('风格图片提示词生成').item.json.output.image_name_zh.slice(0,10) }}.png补充:方法3可以参考我们前面的即梦4.0工作流,能够使用最新的即梦4.0模型
6、ComfyUI 本地部署(难)
这种方式要求我们本地有独立显卡(显存>=8GB)
查看电脑显卡方式,右键单击此电脑,点击属性。
这种方式比较自由灵活,成本相对可控,有一块较好性能的显卡,跑起来非常爽。
我们需要在n8n安装ComfyUI节点,方便直接使用本地comfyui。
复制包名 n8n-nodes-comfyui
然后就能在列表中看到该节点,回到工作流页面,能搜到该节点,说明安装成功。
然后在n8n中创建新的ComfyUI凭证
如果是通过秋叶安装包安装的本地Comfyui,记得先在高级设置里面开放远程连接,这样我们本地docker里面部署的n8n才好连接。
如果n8n是部署在本地Docker里面的话,在这里我们把API URL 改成:http://host.docker.internal:8188
如果是部署在云上,则是对应的地址加上端口号,如果不知道地址是什么,可以 win + R 搜索CMD,执行命令行 ipconfig 查看 IPV4内容。
对应ComfyUI的工作流是导出为API的这种类型
如果想要比较无损的图片,可以选择PNG,需要内存小一点的图片可以选择JPEG
如果需要更稳定的使用,可以用Edit Fields(set)这个节点,把我们的comfyui工作流当成一个对象导入到n8n中,然后再去对具体的内容设值,以本地http请求的方式发送任务。
要确保这个最基本的文生图工作流要在本地Comfyui先跑通再导出到n8n中
代码块
{
"8": {
"inputs": {
"samples": [
"31",
0
],
"vae": [
"39",
0
]
},
"class_type": "VAEDecode",
"_meta": {
"title": "VAE解码"
}
},
"9": {
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"class_type": "SaveImage",
"_meta": {
"title": "保存图像"
}
},
"27": {
"inputs": {
"width": 1280,
"height": 720,
"batch_size": 1
},
"class_type": "EmptySD3LatentImage",
"_meta": {
"title": "空Latent_SD3"
}
},
"31": {
"inputs": {
"seed": 462462031137045,
"steps": 20,
"cfg": 1,
"sampler_name": "euler",
"scheduler": "simple",
"denoise": 1,
"model": [
"38",
0
],
"positive": [
"41",
0
],
"negative": [
"42",
0
],
"latent_image": [
"27",
0
]
},
"class_type": "KSampler",
"_meta": {
"title": "K采样器"
}
},
"38": {
"inputs": {
"unet_name": "flux1-dev-fp8.safetensors",
"weight_dtype": "default"
},
"class_type": "UNETLoader",
"_meta": {
"title": "UNET加载器"
}
},
"39": {
"inputs": {
"vae_name": "ae.safetensors"
},
"class_type": "VAELoader",
"_meta": {
"title": "VAE加载器"
}
},
"40": {
"inputs": {
"clip_name1": "clip_l.safetensors",
"clip_name2": "t5xxl_fp8_e4m3fn.safetensors",
"type": "flux",
"device": "default"
},
"class_type": "DualCLIPLoader",
"_meta": {
"title": "双CLIP加载器"
}
},
"41": {
"inputs": {
"clip_l": "{{ $('风格图片提示词生成').item.json.output.prompt_en }}",
"t5xxl": "{{ $('风格图片提示词生成').item.json.output.prompt_en }}",
"guidance": 3.5,
"clip": [
"40",
0
]
},
"class_type": "CLIPTextEncodeFlux",
"_meta": {
"title": "CLIP文本编码Flux"
}
},
"42": {
"inputs": {
"conditioning": [
"41",
0
]
},
"class_type": "ConditioningZeroOut",
"_meta": {
"title": "条件零化"
}
}
}那就可以以API形式导出,然后复制到n8n的ComfyUI节点中,把下图clip_l和t5xxl内容替换为前面提示词的值
根据本地显卡的出图速度和图片的分辨率,大概估计个时间,先wait等待一定的时间,比如10s或者30s等等。
If节点再去判断,是否有值返回
代码块
{{ $('查询任务').item.json[$('发送任务').item.json.prompt_id].outputs['9'].images[0].filename }}如果有值就下载图像,没有值继续循环等待,再去查询。
在本地comfyui也能查看当前出图工作流进度。
下载图像的url是这样
http://host.docker.internal:8188/view?filename={{ $('查询任务').item.json[$('发送任务').item.json.prompt_id].outputs['9'].images[0].filename }}
同样是get请求得到最终图片。
最终使用 Read/Write Files from Disk 去保存文件到本地。
7、liblib (推荐)
Liblib 是国内比较强大的套壳 SD 平台,我们很方便在里面使用sd webui和 comfyui 等等,如果我们本地显卡性能不够,又想使用sd,那liblib是个比较合适的平台。
在 n8n 中我们也是主要通过 liblib 的 api 来进行调用,地址:https://www.liblib.art/apis
在网页端使用起来会比较简单,API 调用有比较多的参数需要去设置,我们主要使用AccessKey和SecretKey来进行相关授权,接口及其参数详情地址:LiblibAI x 星流 图像大模型API 使用说明。
新用户登录会赠送 500 积分。
测试生成结果如下,文生图(使用 Lora)的情况下,每调用一次消耗 15 积分。
在设置参数里面需要设置的字段
整体节点
节点较为复杂,这里大家主要是把对应的参数在前面设置好即可。
直接复制这个 json 内容到 n8n 工作流编辑页面。
代码块
{
"nodes": [
{
"parameters": {
"method": "POST",
"url": "=https://openapi.liblibai.cloud{{ $('设置参数').item.json['Liblib 生图'] }}?AccessKey={{ $('设置参数').item.json['Liblib AccessKey'] }}&Signature={{ $json.signature }}&Timestamp={{ $('设置参数').item.json['Timestamp'] }}&SignatureNonce={{ $('设置参数').item.json['SignatureNonce'] }}\n\n\n",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"templateUuid\": \"e10adc3949ba59abbe56e057f20f883e\",\n \"generateParams\": {\n \"checkPointId\": \"{{ $('设置参数').item.json['Liblib 主模型编号'] }}\",\n \"prompt\": {{ JSON.stringify($('风格图片提示词生成').item.json.output.prompt_en) }},\n \"negativePrompt\": \"ng_deepnegative_v1_75t,(badhandv4:1.2),EasyNegative,(worst quality:2),\",\n \"sampler\": 1,\n \"steps\": 28,\n \"cfgScale\": 3.5,\n \"width\": {{ $('风格图片提示词生成').item.json.output.image_width }},\n \"height\": {{ $('风格图片提示词生成').item.json.output.image_height }},\n \"imgCount\": 1,\n \"randnSource\": 0,\n \"seed\": -1,\n \"restoreFaces\": 0,\n \"additionalNetwork\": [\n {\n \"modelId\": \"{{ $('设置参数').item.json['LoRa 模型编号'] }}\",\n \"weight\": 0.8\n }\n ],\n \"hiResFixInfo\": {\n \"hiresSteps\": 30,\n \"hiresDenoisingStrength\": 0.7,\n \"upscaler\": 11,\n \"resizedWidth\": 2048,\n \"resizedHeight\": 1152\n }\n }\n}",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
224,
2112
],
"id": "46ac820d-0f96-4d9e-bc4f-be6b5bf58322",
"name": "Liblib 生图"
},
{
"parameters": {
"amount": 30
},
"type": "n8n-nodes-base.wait",
"typeVersion": 1.1,
"position": [
448,
2112
],
"id": "28bf1251-7ef7-46a7-9397-641321fdba22",
"name": "等待",
"webhookId": "b29e047d-3941-45a5-8432-95ee35399bf5"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "741fc5ba-a75a-4105-8900-5dfc807ff68d",
"name": "raw",
"value": "={{ $('设置参数').item.json['Liblib 生图'] }}&{{ $('设置参数').item.json['Timestamp'] }}&{{ $('设置参数').item.json['SignatureNonce'] }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
-432,
2112
],
"id": "a2bb1695-41b3-4cf8-a014-b251725b3266",
"name": "Liblib拼接-生图"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "741fc5ba-a75a-4105-8900-5dfc807ff68d",
"name": "raw",
"value": "={{ $('设置参数').item.json['Liblib 结果'] }}&{{ $('设置参数').item.json['Timestamp'] }}&{{ $('设置参数').item.json['SignatureNonce'] }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
656,
2048
],
"id": "466b0db9-a7dd-486c-9466-df6e57d38bd6",
"name": "Liblib拼接-结果"
},
{
"parameters": {
"action": "hmac",
"type": "=SHA1",
"value": "={{ $json.raw }}",
"secret": "={{ $('设置参数').item.json['Liblib SecretKey'] }}",
"encoding": "base64"
},
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [
896,
2048
],
"id": "38945f1b-cc5e-4064-b9dc-d15b17510611",
"name": "签名-结果"
},
{
"parameters": {
"action": "hmac",
"type": "=SHA1",
"value": "={{ $json.raw }}",
"secret": "={{ $('设置参数').item.json['Liblib SecretKey'] }}",
"encoding": "base64"
},
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [
-224,
2112
],
"id": "29265fc8-f952-4f50-9905-6b2e980733ef",
"name": "签名-生图"
},
{
"parameters": {
"jsCode": "// 获取CryptoJS节点输出的签名\nconst base64Signature = $input.first().json.data;\n\n// 转换为URL-safe Base64格式(不补全位数)\nconst urlSafeSignature = base64Signature\n .replace(/\\+/g, '-') // 将 + 替换为 -\n .replace(/\\//g, '_') // 将 / 替换为 _\n .replace(/=+$/, ''); // 去掉末尾的 = 填充字符\n\nreturn {\n json: {\n ...($input.first().json), // 保留原有数据\n signature: urlSafeSignature // 添加最终签名\n }\n};\n"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
16,
2112
],
"id": "796d5646-f1b2-4b76-8648-cce227c42c24",
"name": "URL 安全-生图"
},
{
"parameters": {
"jsCode": "// 获取CryptoJS节点输出的签名\nconst base64Signature = $input.first().json.data;\n\n// 转换为URL-safe Base64格式(不补全位数)\nconst urlSafeSignature = base64Signature\n .replace(/\\+/g, '-') // 将 + 替换为 -\n .replace(/\\//g, '_') // 将 / 替换为 _\n .replace(/=+$/, ''); // 去掉末尾的 = 填充字符\n\nreturn {\n json: {\n ...($input.first().json), // 保留原有数据\n signature: urlSafeSignature // 添加最终签名\n }\n};\n"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1104,
2048
],
"id": "1959779a-446b-4fe7-902e-d09735141298",
"name": "URL 安全-结果"
},
{
"parameters": {
"method": "POST",
"url": "=https://openapi.liblibai.cloud{{ $('设置参数').item.json['Liblib 结果'] }}?AccessKey={{ $('设置参数').item.json['Liblib AccessKey'] }}&Signature={{ $json.signature }}&Timestamp={{ $('设置参数').item.json.Timestamp }}&SignatureNonce={{ $('设置参数').item.json.SignatureNonce }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "generateUuid",
"value": "={{ $('Liblib 生图').item.json.data.generateUuid }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1296,
2048
],
"id": "f8077ade-83ad-4bb8-a15a-f6083d691fec",
"name": "Liblib 结果"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "29897656-ff7e-4b3b-9da1-25c4667d28d8",
"leftValue": "={{ $('Liblib 结果').item.json.data.images[0].imageUrl }}",
"rightValue": "https",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
1760,
2112
],
"id": "79f65a9d-daaf-4b21-83eb-5e32a8617865",
"name": "判断-Liblib"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "29897656-ff7e-4b3b-9da1-25c4667d28d8",
"leftValue": "={{ $json.msg }}",
"rightValue": "敏感",
"operator": {
"type": "string",
"operation": "contains"
}
},
{
"id": "ca38bf69-d531-4cce-a9f3-88bb4e83be16",
"leftValue": "={{ $json.msg }}",
"rightValue": "无效",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "or"
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
1568,
2112
],
"id": "97118c8e-b7c4-4fc9-acbf-4aa16b6e786e",
"name": "判断-Liblib敏感"
},
{
"parameters": {
"url": "={{ $json.data.images[0].imageUrl }}",
"options": {
"response": {
"response": {
"responseFormat": "file"
}
}
}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1952,
2096
],
"id": "4557a3b4-479e-47ad-b36a-235a63e61431",
"name": "下载图片"
}
],
"connections": {
"Liblib 生图": {
"main": [
[
{
"node": "等待",
"type": "main",
"index": 0
}
]
]
},
"等待": {
"main": [
[
{
"node": "Liblib拼接-结果",
"type": "main",
"index": 0
}
]
]
},
"Liblib拼接-生图": {
"main": [
[
{
"node": "签名-生图",
"type": "main",
"index": 0
}
]
]
},
"Liblib拼接-结果": {
"main": [
[
{
"node": "签名-结果",
"type": "main",
"index": 0
}
]
]
},
"签名-结果": {
"main": [
[
{
"node": "URL 安全-结果",
"type": "main",
"index": 0
}
]
]
},
"签名-生图": {
"main": [
[
{
"node": "URL 安全-生图",
"type": "main",
"index": 0
}
]
]
},
"URL 安全-生图": {
"main": [
[
{
"node": "Liblib 生图",
"type": "main",
"index": 0
}
]
]
},
"URL 安全-结果": {
"main": [
[
{
"node": "Liblib 结果",
"type": "main",
"index": 0
}
]
]
},
"Liblib 结果": {
"main": [
[
{
"node": "判断-Liblib敏感",
"type": "main",
"index": 0
}
]
]
},
"判断-Liblib": {
"main": [
[
{
"node": "下载图片",
"type": "main",
"index": 0
}
],
[
{
"node": "等待",
"type": "main",
"index": 0
}
]
]
},
"判断-Liblib敏感": {
"main": [
[],
[
{
"node": "判断-Liblib",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "19e349f8e42d1a5e9beb5942ce732c56d2731ab126a08c7a53598fd913282213"
}
}Liblib 生图节点里的 templateUuid 需要参考文档去选择不同的值,对应着Liblib 不同的功能,比如Flux 文生图,xl图生图等等,详情看上述他们的官方文档。
modelId是选择的LoRA模型
中 versionUuid=后面那一串字符串
8、RunningHub
RunningHub相比起Liblib,优势在于成本相对会低一些,有更多的开源AI视频模型在里面部署。
如果想使用RunningHub上面的内容:https://www.runninghub.cn/runninghub-api-doc/api-276613249
需要基础版本及以上才能使用
开了会员之后,每天还有一些第三方免费调用的API限额
我们使用RunnningHub的工作流,最主要的就是需要输入apiKey和workflowId,apiKey通过上述开基础版以上的会员能拿到,workflowId,需要到工作流页面,点击一个工作流详情,例如下述这个。
左上角的1951105950621048833就是该workflowId
如果有一些具体的参数需要修改,可以下载工作流详情
复制到本地或者线上ComfyUI
发现提示词节点是53 对应的名字也能在json中搜到
然后我们在n8n里面设置好参数,在发送RunningHub HTTP请求里面获取,这样我们的提示词,apiKey和workflowId都设置成功
如果有别的参数要改,也是类似的操作。
代码块
{
"apiKey": "{{ $('设置参数').item.json['RunningHub apiKey'] }}",
"workflowId": "{{ $('设置参数').item.json['RunningHub workflowId'] }}",
"nodeInfoList": [
{
"nodeId": "53",
"fieldName": "Text Multiline",
"fieldValue": "{{ $json.output.prompt_zh }}"
},
{
"nodeId": "52",
"fieldName": "CR SDXL Aspect Ratio",
"fieldValue": [{{ $('风格图片提示词生成').item.json.output.image_width }},{{ $('风格图片提示词生成').item.json.output.image_height }}, "custom", "Off", 1, 2]
}
]
}这样正常情况下是能够成功在n8n中运行RunningHub工作流,但是我们还不知道什么时候能够生成,所以需要等待,然后轮询查看工作流的运行状态。
然后填写对应的n8n中Http请求
接着用if判断,看工作流是否已经完成
如果成功了,再去取对应的图片:https://www.runninghub.cn/runninghub-api-doc/api-276613253
和前面查询任务状态相比,只是改了一下url路径
再去用GET请求获取文件
代码块
{{ $json.data[0].fileUrl }}最终结构参考
9、FLUX.1-schnell-Free / OpenAI GPT Image 1
GPT Image 1生成结果
FLUX.1-schnell-Free 生成结果
整体流程查看
整体流程json文件,复制粘贴到n8n工作流开发页面即可。
代码块
{
"nodes": [
{
"parameters": {
"method": "POST",
"url": "https://api.together.xyz/v1/images/generations",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "=Bearer {{ $('设置参数').item.json['together ai API key'] }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"model\": \"{{ $('设置参数').item.json.Model }}\",\n \"prompt\": \"{{ $('风格图片提示词生成').item.json.output.prompt_en }}\",\n \"width\": {{ $('风格图片提示词生成').item.json.output.image_width }},\n \"height\": {{ $('风格图片提示词生成').item.json.output.image_height }},\n \"steps\": 4,\n \"n\": 1,\n \"response_format\": \"b64_json\",\n \"stop\": []\n}",
"options": {
"timeout": 1000000000
}
},
"name": "Together图片生成",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
-512,
64
],
"id": "7c1f4518-b452-42f7-9f34-1014b2e4816d",
"retryOnFail": false,
"waitBetweenTries": 5000,
"onError": "continueErrorOutput"
},
{
"parameters": {
"operation": "completion",
"respondWith": "showText",
"responseText": "=<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>西羊石AI视频 n8n 图片生成器</title>\n <style>\n body {\n font-family: 'Open Sans', Tahoma, Geneva, Verdana, sans-serif;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n background-color: #121212;\n color: #e0e0e0;\n margin: 0;\n }\n\n .container {\n width: 90%;\n max-width: 670px;\n background: #1e1e1e;\n padding: 24px;\n border-radius: 12px;\n box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);\n text-align: center;\n }\n\n .image-container {\n margin-bottom: 20px;\n }\n\n .image-container img {\n max-width: 100%;\n height: auto;\n border-radius: 12px;\n border: 2px solid #333;\n }\n\n .style-text {\n font-size: 18px;\n margin-bottom: 20px;\n color: #bbb;\n }\n\n .cta {\n display: block;\n width: 100%;\n margin-top: 20px;\n padding: 18px 0;\n border: none;\n border-radius: 6px;\n text-decoration: none;\n color: #fff;\n background-color: #1c9985;\n font-size: 18px;\n transition: all 0.3s ease;\n }\n\n .cta:hover {\n background-color: #20b69e;\n transform: translateY(-2px);\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\n }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <div class=\"image-container\">\n <!-- 单张生成结果 -->\n <img src=\"{{ $json.url }}\" alt=\"Generated Image\" />\n </div>\n\n <div class=\"style-text\">\n 图片风格: {{ $('图片要求提交').item.json['图片风格'] }}\n </div>\n\n <a\n href=\"http://localhost:5678/form/xiangyu-flux-image-generator\"\n class=\"cta\"\n >西羊石AI视频:n8n 图片生成工作流</a\n >\n </div>\n</body>\n</html>\n",
"limitWaitTime": true,
"resumeAmount": 0.5,
"resumeUnit": "minutes"
},
"type": "n8n-nodes-base.form",
"typeVersion": 1,
"position": [
368,
160
],
"id": "70fa4ba8-3298-4a68-8a00-cc5fca4605ad",
"name": "返回图片",
"webhookId": "9b1dc8d7-9114-47f6-903c-08195481dc2d"
},
{
"parameters": {
"operation": "completion",
"respondWith": "redirect",
"redirectUrl": "http://localhost:5678/form/xiangyu-flux-image-generator",
"limitWaitTime": true,
"resumeAmount": 0.5,
"resumeUnit": "minutes",
"options": {}
},
"type": "n8n-nodes-base.form",
"typeVersion": 1,
"position": [
384,
352
],
"id": "e0bf0ef7-882c-4925-a203-5475efaaa1be",
"name": "返回首页",
"webhookId": "c67fab23-d2b8-4bec-b120-bb7a3ec355e2"
},
{
"parameters": {
"limitWaitTime": true,
"resumeAmount": 0.5,
"resumeUnit": "minutes",
"options": {
"formTitle": "=生图错误,报错如下请重试",
"formDescription": "={{ $json.error }}",
"buttonLabel": "点击回到首页"
}
},
"type": "n8n-nodes-base.form",
"typeVersion": 1,
"position": [
160,
352
],
"id": "212171f3-cf6c-4a1f-bb3a-1009f0a17beb",
"name": "报错提醒",
"webhookId": "ed8a8b80-387b-48e7-b15c-fc9962de4136"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "a0875f96-1310-4a93-88a7-ba0b38f57df7",
"name": "error",
"value": "=Together 报错:{{ $json.error }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
-304,
160
],
"id": "4f523923-390c-4bf8-9f93-b827ce0e08ea",
"name": "报错-Together"
},
{
"parameters": {},
"type": "n8n-nodes-base.merge",
"typeVersion": 3.1,
"position": [
-64,
352
],
"id": "4b5001ff-24d3-4645-bb0d-ee2a3fcf9e7e",
"name": "聚合报错信息"
},
{
"parameters": {
"method": "POST",
"url": "https://api.302.ai/v1/images/generations",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "response_format",
"value": "bs64_json"
}
]
},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "=Bearer {{ $('设置参数').item.json['302 AI api key'] }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"prompt\": {{ JSON.stringify($('风格图片提示词生成').item.json.output.prompt_zh) }},\n \"model\": \"gpt-image-1\",\n \"size\": \"{{ $('风格图片提示词生成').item.json.output.image_width }}x{{ $('风格图片提示词生成').item.json.output.image_height }}\",\n \"quality\": \"high\",\n \"background\": \"{{ $('设置参数').item.json.Background }}\"\n}",
"options": {
"timeout": 10000000000
}
},
"name": "OpenAI图片生成",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
-528,
464
],
"id": "069ee3e3-1e9b-4f4c-935c-d94370245025",
"retryOnFail": false,
"waitBetweenTries": 5000,
"onError": "continueErrorOutput"
},
{
"parameters": {
"operation": "toBinary",
"sourceProperty": "data[0].b64_json",
"options": {}
},
"type": "n8n-nodes-base.convertToFile",
"typeVersion": 1.1,
"position": [
-320,
-64
],
"id": "ec3d55c8-57b5-4a3e-b891-43cc959aa9b1",
"name": "转换为二进制文件-FLUX"
},
{
"parameters": {
"operation": "toBinary",
"sourceProperty": "data[0].b64_json",
"options": {}
},
"type": "n8n-nodes-base.convertToFile",
"typeVersion": 1.1,
"position": [
-288,
368
],
"id": "3303485d-0ad2-41af-a86f-3f3db9f3bf39",
"name": "转换为二进制文件-GPT"
},
{
"parameters": {},
"type": "n8n-nodes-base.merge",
"typeVersion": 3.1,
"position": [
-80,
160
],
"id": "d56baa64-f81e-4053-9ca4-816ca10e089c",
"name": "聚合"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "a0875f96-1310-4a93-88a7-ba0b38f57df7",
"name": "error",
"value": "=GPT 报错:{{ $json.error }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
-288,
560
],
"id": "df0e9405-9539-467a-bb7d-7cd8b9bcecce",
"name": "报错-GPT"
}
],
"connections": {
"Together图片生成": {
"main": [
[
{
"node": "转换为二进制文件-FLUX",
"type": "main",
"index": 0
}
],
[
{
"node": "报错-Together",
"type": "main",
"index": 0
}
]
]
},
"报错提醒": {
"main": [
[
{
"node": "返回首页",
"type": "main",
"index": 0
}
]
]
},
"报错-Together": {
"main": [
[
{
"node": "聚合报错信息",
"type": "main",
"index": 0
}
]
]
},
"聚合报错信息": {
"main": [
[
{
"node": "报错提醒",
"type": "main",
"index": 0
}
]
]
},
"OpenAI图片生成": {
"main": [
[
{
"node": "转换为二进制文件-GPT",
"type": "main",
"index": 0
}
],
[
{
"node": "报错-GPT",
"type": "main",
"index": 0
}
]
]
},
"转换为二进制文件-FLUX": {
"main": [
[
{
"node": "聚合",
"type": "main",
"index": 0
}
]
]
},
"转换为二进制文件-GPT": {
"main": [
[
{
"node": "聚合",
"type": "main",
"index": 1
}
]
]
},
"聚合": {
"main": [
[
{
"node": "返回图片",
"type": "main",
"index": 0
}
]
]
},
"报错-GPT": {
"main": [
[
{
"node": "聚合报错信息",
"type": "main",
"index": 1
}
]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be33e7a4c93bf3fbad46ee9dd2261c1867b920251d4e05c1a2fedf55455fa8e4"
}
}这两个分别是在together ai 和 302 ai 两个平台上使用(需要魔法),Flux-schnell-free是免费的
使用一次gpt image 1高品质需要消耗0.25076 美元
提交表单进行测试
这里有个坑,在gpt 1 image 中,一定要选fixed,然后值填上 data[0].b64_json
返回结果
另外大家也可以尝试调用openAI官方的APIkey来使用GPT Image 1,但是可能因为网络问题和参数问题不一定像302.ai这么方便请求;
10、Google Imagen 4(较为复杂,不建议小白尝试)
整体流程在n8n中只是三步,但是需要有国际信用卡注册谷歌云,新建云项目等等复杂步骤。
详情请查看:谷歌云相关服务注册与绑定N8N
最后生成的效果
步骤 1:拿 API Key
生成后就得到一串 AIza... 的 key。文档明确支持用 Imagen 4 通过 Gemini API 生成图片,并给出 REST 端点与模型名。(Google AI for Developers)
目前看来即使我们是通过Google AI Studio 创建API key,也还是需要先在谷歌云上建项目【实际操作比较麻烦,如果是小白不建议操作】
如果需要了解操作详情可以看这篇文档:谷歌云相关服务注册与绑定N8N
模型名(model):imagen-4.0-generate-001
REST 端点(POST):
https://generativelanguage.googleapis.com/v1beta/models/imagen-4.0-generate-001:predict
认证用请求头:x-goog-api-key: <你的API Key>(无需 OAuth)。(Google AI for Developers)
步骤 2:n8n 里新建一个 HTTP Request 节点
Method: POST
Query Parameter:
key: google api key (建议放到环境变量或 n8n Credentials)
Headers:
Content-Type: application/json
还有一种方式是两个参数都放到header里面,但是apikey的名称是 x-goog-api-key 且只能输入固定值,没办法输入变量。
Body > JSON(可直接粘贴;prompt 换成你自己的):
代码块
{
"instances": [
{
"prompt": "{{ $('风格图片提示词生成').item.json.output.prompt_en }}",
"aspectRatio": "{{ $('输入-表单').item.json.Size.match(/\((.*?)\)/)[1] || '1:1' }}"
}
],
"parameters": {
"sampleCount": 1
}
}步骤 3:把返回的 base64 图转为二进制文件/URL
Gemini API 的响应里有生成的图像字节(base64)。文档示例里是 generatedImages[i].image.imageBytes(SDK 命名),REST 返回会给出对应的 base64 图像数据(n8n 里你可以从返回 JSON 里读出该字段)。(Google AI for Developers)
在 n8n 里,你可以追加一个 code 节点,把 base64 转成二进制供后续使用(比如写文件、上传云存储、或表单回显):
代码块
// 假设上个HTTP节点返回在 items[0].json.generatedImages[0].image.imageBytes
const b64 = $json.generatedImages?.[0]?.image?.imageBytes
|| $json.predictions?.[0]?.bytesBase64Encoded; // 两种常见字段名,择一存在
if (!b64) {
throw new Error('No image bytes found in response');
}
return [
{
binary: {
data: {
data: Buffer.from(b64, 'base64'),
fileName: 'imagen4.png',
mimeType: 'image/png',
},
},
json: { ok: true }
}
];然后接:
Write Binary File(落盘),或
HTTP Response / Form 节点(直接把图显示给前端)。
官方“用 Gemini API 生成图像(Imagen 4)”的页面明确了“通过 Gemini API 可使用 Imagen 4,推荐作为默认模型”,并给了模型名与 REST 路径。(Google AI for Developers)
小抄 & 常见坑
模型名/端点:
Gemini API:imagen-4.0-generate-001:predict + x-goog-api-key(作为heads,作为query parameters的时候用key即可)。
Vertex AI:.../models/imagen-4.0-generate-***:predict + OAuth 令牌。
返回解析:拿到 base64 就能在 n8n 里转二进制写文件/回显(见上面的 code 节点示例)。
回写
Google Sheets / Bitable:更新 status=done、image_url、provider、latency_ms、cost_estimate
失败支路
所有 HTTP 勾 Retry on Fail(Max 3 / Wait 1000ms),且 onError → 输出错误到“异常合流”
Error Trigger 工作流:把异常 JSON 推送群里 + 记一张“异常表”
观测字段
在关键 Set 里记 request_id / provider / batch_index / cost_usd / retries / started_at / ended_at
11、Google Gemini 2.5 flash image (Nano Banana)
可以生成图片,图片编辑效果强大。
这个使用相对较为简单,简易版本工作流模板如下
表单主要是作为输入的入口,字段可以自定义,主要是文本和文件
大模型选择gemini-2.5-flash-image-preview
Agent的提示词可以自己设置,建议简单点就好,或者是直接用前面表单定义的字段 chatInput,更简单方便,效果好。
文生图的提示词参考,及最终返回的效果图片。
再结合这两个节点就能下载生成的图像
不过在这个文件转换节点,大模型可能输出的图像是 output[1].inlineData.data 或者 output[0].inlineData.data
大家可以在提示词或者在工作流中优化一下
七)Provider 速查映射(最常用字段)
下表我们把各大平台常用的一些字段拿出来做对比,仅供参考。
电子表格 · 内容不可用
课堂提示:适配器里做“键名翻译”,不要把平台命名泄漏到上游。
八)把现有表单流“升级”为可批量+多模型
现有节点:图片要求提交 → 风格提示词生成 → 图片生成 → 返回 图片/下载到本地
按下面补齐即可:
入口双通道:保留表单;新增 飞书表格触发器(或别的子工作流触发的形式)
Set 统一 schema:把表单/表格字段都映射到上文 schema(含尺寸解析/风格)
幂等去重:给每条任务生成 request_id,用 Merge(A−B) 过滤重复
批处理:Switch 之前包一层 Split In Batches + Wait
多 Provider 适配器:复制你“Together 图片生成”节点,改成“Provider 适配器(HTTP)”,每家一条支路
失败聚合:你已有“报错提醒/聚合报错信息”,并到 Error Trigger
托管与回写:保留你“返回图片”UI;新增 Sheets/Bitable Update,把链接与状态写回
凭证安全:把你 JSON 里的 API key 移到 Credentials,在 Header 用表达式读凭证
九)可复制片段(参考)
1)尺寸字符串 → 数值宽高(Code)
代码块
const it = $input.item.json;
const m = String(it.size || it.Size || `${it.width}x${it.height}`)
.match(/(\d{2,4})\D+(\d{2,4})/);
it.width = m ? +m[1] : (it.width || 1024);
it.height = m ? +m[2] : (it.height || 1024);
return [{ json: it }];2)请求幂等哈希(Code)
代码块
const crypto = require('crypto');
for (const it of $input.all()) {
const base = [
it.json.model, it.json.prompt, it.json.width, it.json.height, it.json.ref_image_url||''
].join('|');
it.json.request_id = crypto.createHash('md5').update(base).digest('hex');
}
return $input.all();3)Split In Batches 限速循环(官方范式)
Split In Batches:batchSize=8
批尾 Wait:7500ms
Wait → 回到 Split(直到 noItemsLeft 停止)
4)HTTP 节点失败重试(推荐)
Settings 勾 Retry on Fail:Max Tries = 3,Wait Between Tries(ms)=1000
5)Together 适配器(HTTP Body 示范)
代码块
{
"model": "{{ $json.model === 'gpt-image-1' ? 'gpt-image-1' : 'black-forest-labs/FLUX.1-schnell' }}",
"prompt": "{{ $json.prompt }}",
"width": {{ $json.width }},
"height": {{ $json.height }},
"steps": {{ $json.steps || 4 }},
"n": 1,
"response_format": "b64_json"
}6)Base64 → binary(Move Binary Data)
Operation: JSON to Binary
Property: data[0].b64_json 或 images[0].base64
Binary Property Name: image
File Name: {{$json.request_id}}.png
7)表格回写(Google Sheets Update)
Range:定位 meta.source_row
更新:status=done, image_url={{$json.image_url}}, provider={{$json.provider}}
8)成本估算(示例)
代码块
for (const it of $input.all()) {
const m = it.json.model;
let cost = 0;
if (m==='gpt-image-1') cost = (it.json.width*it.json.height>=1536*1536)?0.08:0.04;
if (m==='flux-schnell') cost = 0.002; // 示例,自行按账户计费表调整
it.json.cost_usd = +cost.toFixed(4);
}
return $input.all();十)常见坑与排查
429/排队:总是先上 Split In Batches + Wait;必要时分 Provider 设不同批次
base64 太大/节点超时:HTTP Timeout 调大、尽量上传到图床再传链接
ComfyUI 无响应:没 --enable-api、prompt 图键名不匹配、端口/防火墙
表格回写错行:务必把 source_row 带流转,更新用它而非索引猜测
Key 泄露:一律用 Credentials;Body/Set 里别硬编码
提示词“跑偏”:风格库 + LLM 提示词统一器,温度 ≤ 0.5,必要时中文→英文
十一)建议实践
跟着SOP文档跑通工作流中1-2条路径,建议先从即梦插件方式开始。
十二)文档总结
这个文档,我们带大家梳理了 n8n 批量文生图工作流的整体框架。让散落在各个平台的AI出图功能汇聚在这样一条工作流里面,很适合作为我们学习n8n在AI绘画中的相关使用。
当然,这仍然是不够成熟的工作流,要成为真正稳定的AI智能体,还需要在系统层面进行更多的操作,比如统一入参,统一返回参数,统一报错等等。
如果你对于MCP有一定的了解,还能通过子工作流触发的形式把我们这个工作流作为MCP服务器,在别的平台进行使用。
掌握了这些基础,后续在视频创作的流程中,你会更加得心应手。