8
n8n 中文网amn8n.com

基于fal.ai的文本转AI图像生成器

中级

这是一个自动化工作流,包含 12 个节点。主要使用 If, Wait, Webhook, HttpRequest, RespondToWebhook 等节点。 基于fal.ai平台的文本转AI图像生成器

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "cb484ba7b742928a2048bf8829668bed5b5ad9787579adea888f05980292a4a7"
  },
  "nodes": [
    {
      "id": "c5b7bac5-6e31-4338-af76-32a34be8ae4d",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -440,
        280
      ],
      "webhookId": "5cca11bb-eaea-4c3a-86f7-16d5802b6ac8",
      "parameters": {
        "path": "ai_text_to_image_generator",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "ba2850cc-3d2b-45d7-9c1d-87bff38d99c3",
      "name": "获取状态",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        300,
        280
      ],
      "parameters": {
        "url": "=https://queue.fal.run/fal-ai/flux/requests/{{ $json.request_id }}/status",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "0qP44IHCmBfL54Vb",
          "name": "Falai Polina"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "44e08f96-e6b2-49a8-8077-571e07108d8d",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        680,
        460
      ],
      "webhookId": "150069ed-885b-497f-a32a-09e7088136e6",
      "parameters": {
        "amount": 1
      },
      "typeVersion": 1.1
    },
    {
      "id": "a1455b63-eed2-4c6d-86dc-11bf0937892b",
      "name": "是否就绪?",
      "type": "n8n-nodes-base.if",
      "position": [
        480,
        280
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ac50759b-e2f3-4efd-a2af-f28b7d209b45",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "COMPLETED"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6b4446ef-0c5f-4d8b-839e-e7a9d6ae4773",
      "name": "提交请求",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        100,
        280
      ],
      "parameters": {
        "url": "https://queue.fal.run/fal-ai/flux/schnell",
        "method": "POST",
        "options": {},
        "jsonBody": "={\"prompt\": \"{{ $json.body.prompt }}\"}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "0qP44IHCmBfL54Vb",
          "name": "Falai Polina"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "3f1df77f-8576-4c32-a1c8-7e80f5bf572d",
      "name": "获取结果",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        680,
        280
      ],
      "parameters": {
        "url": "={{ $json.response_url }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "0qP44IHCmBfL54Vb",
          "name": "Falai Polina"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "744b0b05-d1f7-4972-b16d-70328b7a36c9",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -260,
        440
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "QpFZ2EiM3WGl6Zr3",
          "name": "Marketing OpenAI"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "9ab24ceb-c1c1-42b8-88d9-249c2db60a8d",
      "name": "400 错误",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        100,
        640
      ],
      "parameters": {
        "options": {
          "responseCode": 400
        },
        "respondWith": "json",
        "responseBody": "={{\n{\n  \"error\": \"Prompt is in violation of terms of use. Please try again.\",\n  \"result\": []\n}\n}}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "c5ef424e-1fb5-44d5-9612-4c76c7d1d232",
      "name": "成功",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        900,
        280
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "={{\n{\n  \"error\": null,\n  \"result\": $json.images\n}\n}}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "eb43cc4a-4d15-47b9-9c81-840ecc9cfafa",
      "name": "NSFW 过滤器",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        -260,
        280
      ],
      "parameters": {
        "options": {
          "fallback": "other"
        },
        "inputText": "={{ $json.body.prompt }}",
        "categories": {
          "categories": [
            {
              "category": "NSFW",
              "description": "text is NSFW"
            },
            {
              "category": "SFW",
              "description": "text is SFW"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "db102cc6-b414-4187-b269-8f73158f0fb3",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        120
      ],
      "parameters": {
        "width": 540,
        "height": 460,
        "content": "## 通过 webhook 端点接收文本提示,并使用 AI 审核过滤提示中的不当内容"
      },
      "typeVersion": 1
    },
    {
      "id": "b2ff86e9-62cc-45d1-9f89-6a5d2010c976",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        0
      ],
      "parameters": {
        "width": 540,
        "height": 580,
        "content": "## 将有效提示提交到 Fal.ai,轮询完成状态,并在准备就绪时检索生成的图片"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {
    "Webhook": [
      {
        "body": {
          "prompt": "A person sitting under a moonlit sky",
          "styleId": "1"
        },
        "query": {},
        "params": {},
        "headers": {
          "host": "[insert your host]",
          "accept": "*/*",
          "origin": "http://localhost:3000",
          "pragma": "no-cache",
          "referer": "http://localhost:3000/",
          "priority": "u=1, i",
          "sec-ch-ua": "\"Chromium\";v=\"134\", \"Not:A-Brand\";v=\"24\", \"Google Chrome\";v=\"134\"",
          "x-real-ip": "10.255.0.2",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
          "content-type": "multipart/form-data; boundary=----WebKitFormBoundary6KvXTaJpPc6UJTId",
          "cache-control": "no-cache",
          "content-length": "268",
          "sec-fetch-dest": "empty",
          "sec-fetch-mode": "cors",
          "sec-fetch-site": "cross-site",
          "accept-encoding": "gzip, deflate, br, zstd",
          "accept-language": "pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7,fr;q=0.6,la;q=0.5,de;q=0.4,sk;q=0.3,nl;q=0.2,mt;q=0.1",
          "x-forwarded-for": "10.255.0.2",
          "sec-ch-ua-mobile": "?0",
          "x-forwarded-host": "[insert your host]",
          "x-forwarded-port": "443",
          "x-forwarded-proto": "https",
          "sec-ch-ua-platform": "\"macOS\"",
          "x-forwarded-server": "5f641c71d311"
        },
        "webhookUrl": "https://[insert your host]/webhook/ai_text_to_image_generator",
        "executionMode": "production"
      }
    ]
  },
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Fetch Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "NSFW Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Ready?": {
      "main": [
        [
          {
            "node": "Fetch Result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NSFW Filter": {
      "main": [
        [
          {
            "node": "400 Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Submit Request",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "400 Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Result": {
      "main": [
        [
          {
            "node": "Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Status": {
      "main": [
        [
          {
            "node": "Is Ready?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Submit Request": {
      "main": [
        [
          {
            "node": "Fetch Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "NSFW Filter",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级

需要付费吗?

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

工作流信息
难度等级
中级
节点数量12
分类-
节点类型8
难度说明

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

作者
n8n Team

n8n Team

@n8n-team

Meet the official n8n team. We specialize in building workflows that transform intricate tasks into seamless operations.

外部链接
在 n8n.io 查看

分享此工作流