8
n8n 中文网amn8n.com

使用Nano Banana API的产品创意生成器

中级

这是一个Miscellaneous, Multimodal AI领域的自动化工作流,包含 11 个节点。主要使用 If, Set, Wait, FormTrigger, HttpRequest 等节点。 通过Defapi使用Google Nano-Banana模型生成产品创意图片

前置要求
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "GMfEqz8V4eeXfCDn",
  "meta": {
    "instanceId": "323608cbec55d18261b8bc24f73f48c4455cb4a115f1b3e3d2435ba7c138103c"
  },
  "name": "使用 Nano Banana API 的产品创意生成器",
  "tags": [],
  "nodes": [
    {
      "id": "13d4148f-d422-4f53-8616-37be77c04fd6",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        -192
      ],
      "parameters": {
        "color": 3,
        "width": 780,
        "height": 760,
        "content": "## 概述"
      },
      "typeVersion": 1
    },
    {
      "id": "c42eb223-63e1-4466-85be-a7c176cc7827",
      "name": "获取生成状态",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        416,
        640
      ],
      "parameters": {
        "url": "https://api.defapi.org/api/task/query",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "task_id",
              "value": "={{$json.data.task_id}}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Submit Image for Creative Generation').item.json.api_key }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "36596c60-09d6-4229-9c44-0716a59a1b6a",
      "name": "提交图像进行创意生成",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -272,
        640
      ],
      "webhookId": "791b190b-2acc-4d10-b593-c1929e67686c",
      "parameters": {
        "options": {},
        "formTitle": "AI Product Creative Generator",
        "formFields": {
          "values": [
            {
              "fieldLabel": "prompt",
              "placeholder": "Generate a gorgeous scene for this product for advertising creative"
            },
            {
              "fieldLabel": "img_url",
              "placeholder": "https://cdn.openai.com/API/docs/images/body-lotion.png"
            },
            {
              "fieldLabel": "api_key",
              "placeholder": "dk-087cc3********************"
            }
          ]
        },
        "formDescription": "Please fill in the following information to generate your creative."
      },
      "typeVersion": 2.2
    },
    {
      "id": "8c32a27f-5011-4036-b948-01a16be29348",
      "name": "发送图像生成请求到 Defapi.org API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -48,
        640
      ],
      "parameters": {
        "url": "https://api.defapi.org/api/image/gen",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"prompt\": \"{{$json.prompt}}\",\n  \"model\": \"google/nano-banana\",\n  \"images\": [\"{{ $json.img_url }}\"]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.api_key }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "33610f89-caec-46df-bcc2-82a259bc83bb",
      "name": "等待图像处理完成",
      "type": "n8n-nodes-base.wait",
      "position": [
        192,
        640
      ],
      "webhookId": "bb6c2821-9586-44b7-8606-2ee69a77ed75",
      "parameters": {
        "amount": 10
      },
      "typeVersion": 1.1
    },
    {
      "id": "d3c7114f-445c-4e03-92f9-df88d7ed79ef",
      "name": "检查图像生成是否完成",
      "type": "n8n-nodes-base.if",
      "position": [
        576,
        640
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "db9a5dec-997b-4c3f-9582-37c9bbeb19ff",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "=true",
              "rightValue": "={{ $json.data.status == 'success' }}"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "2fef9e5e-e875-4af0-98eb-0704c9ff581c",
      "name": "格式化并显示图像结果",
      "type": "n8n-nodes-base.set",
      "position": [
        752,
        624
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fa5f375f-cddc-4f7b-a018-67c28015d18b",
              "name": "image_url",
              "type": "string",
              "value": "={{$json.data.result[0].image}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8f4ae369-fe8b-49a6-b55e-2cd73daa43e4",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        864
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 448,
        "content": "## 产品图像"
      },
      "typeVersion": 1
    },
    {
      "id": "90067c5f-f30e-4195-ba68-da6f89632485",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        864
      ],
      "parameters": {
        "width": 416,
        "height": 432,
        "content": "## 产品创意"
      },
      "typeVersion": 1
    },
    {
      "id": "43ae9653-32cc-4c3b-ae80-9ecba7be06b7",
      "name": "获取您的余额",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        784,
        864
      ],
      "parameters": {
        "url": "https://api.defapi.org/api/user",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Submit Image for Creative Generation').item.json.api_key }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "66ee4b63-3333-4a55-8ff4-4e7d28ce26e4",
      "name": "显示余额",
      "type": "n8n-nodes-base.set",
      "position": [
        784,
        1104
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "9ec6c9af-4e73-43c8-bc43-7dbef0919ee2",
              "name": "data.credit",
              "type": "string",
              "value": "={{ $json.data.credit }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "active": true,
  "pinData": {
    "Get Your Balance": [
      {
        "json": {
          "code": 0,
          "data": {
            "credit": "100.50000000"
          },
          "message": "ok"
        }
      }
    ],
    "Obtain the generated status": [
      {
        "json": {
          "code": 0,
          "data": {
            "result": [
              {
                "image": "https://google.datas.systems/fileSystem/response_images/287/2025/08/29/1756432513771985292_2989.png"
              }
            ],
            "status": "success",
            "task_id": "ta823dfb-eaac-44fd-aec2-3e2c7ba8e071",
            "consumed": "0.00100000",
            "created_at": "2025-09-10T10:22:20.010Z",
            "status_reason": {
              "message": null
            }
          },
          "message": "ok"
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "dd1b311a-8a3d-4bd3-8c7d-a10595b6eb54",
  "connections": {
    "Get Your Balance": {
      "main": [
        [
          {
            "node": "Show Balance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Obtain the generated status": {
      "main": [
        [
          {
            "node": "Check if Image Generation is Complete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format and Display Image Results": {
      "main": [
        [
          {
            "node": "Get Your Balance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Submit Image for Creative Generation": {
      "main": [
        [
          {
            "node": "Send Image Generation Request to Defapi.org API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Image Processing Completion": {
      "main": [
        [
          {
            "node": "Obtain the generated status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Image Generation is Complete": {
      "main": [
        [
          {
            "node": "Format and Display Image Results",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for Image Processing Completion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Image Generation Request to Defapi.org API": {
      "main": [
        [
          {
            "node": "Wait for Image Processing Completion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 杂项, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量11
分类2
节点类型6
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流