AutomationFlowsAI & RAG › AI Prompt Generator Workflow - Gemini

AI Prompt Generator Workflow - Gemini

AI Prompt Generator Workflow - Gemini. Uses httpRequest. Webhook trigger; 9 nodes.

Webhook trigger★★★★☆ complexity9 nodesHTTP Request
AI & RAG Trigger: Webhook Nodes: 9 Complexity: ★★★★☆ Added:

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "AI Prompt Generator Workflow - Gemini",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "generate-prompt",
        "responseMode": "responseNode",
        "options": {
          "cors": true
        }
      },
      "id": "webhook-start",
      "name": "Webhook Start",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "user_input",
              "name": "user_input",
              "value": "={{ $json.body.prompt || 'Default prompt' }}",
              "type": "string"
            },
            {
              "id": "prompt_type",
              "name": "prompt_type",
              "value": "={{ $json.body.type || 'general' }}",
              "type": "string"
            },
            {
              "id": "creativity_level",
              "name": "creativity_level",
              "value": "={{ $json.body.creativity || 0.7 }}",
              "type": "number"
            },
            {
              "id": "language",
              "name": "language",
              "value": "={{ $json.body.language || 'Indonesian' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "extract-parameters",
      "name": "Extract Parameters",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Prompt enhancement logic based on type\nconst userInput = $input.item(0).json.user_input;\nconst promptType = $input.item(0).json.prompt_type;\nconst creativityLevel = $input.item(0).json.creativity_level;\nconst language = $input.item(0).json.language;\n\n// Define prompt templates\nconst promptTemplates = {\n  'creative-writing': {\n    prefix: 'Sebagai penulis kreatif yang berpengalaman, buatlah',\n    structure: 'cerita/artikel yang menarik dengan gaya naratif yang engaging',\n    suffix: 'Pastikan untuk menggunakan bahasa yang hidup dan deskriptif.'\n  },\n  'technical': {\n    prefix: 'Sebagai ahli teknis, jelaskan dengan detail',\n    structure: 'konsep atau solusi dengan pendekatan sistematis',\n    suffix: 'Berikan contoh praktis dan implementasi yang jelas.'\n  },\n  'marketing': {\n    prefix: 'Sebagai marketing strategist, buatlah',\n    structure: 'konten pemasaran yang persuasif dan menarik target audience',\n    suffix: 'Fokus pada value proposition dan call-to-action yang kuat.'\n  },\n  'educational': {\n    prefix: 'Sebagai educator yang berpengalaman, ajarkan',\n    structure: 'materi dengan pendekatan yang mudah dipahami',\n    suffix: 'Gunakan analogi dan contoh untuk memperjelas konsep.'\n  },\n  'general': {\n    prefix: 'Tolong bantu saya dengan',\n    structure: 'informasi yang komprehensif dan akurat',\n    suffix: 'Berikan jawaban yang terstruktur dan mudah dipahami.'\n  }\n};\n\n// Get template based on type\nconst template = promptTemplates[promptType] || promptTemplates['general'];\n\n// Create enhanced prompt\nlet enhancedPrompt = `${template.prefix} ${userInput}. ${template.structure}. ${template.suffix}`;\n\n// Add creativity instructions based on level\nif (creativityLevel > 0.8) {\n  enhancedPrompt += ' Jadilah sangat kreatif dan inovatif dalam pendekatan Anda.';\n} else if (creativityLevel > 0.5) {\n  enhancedPrompt += ' Gunakan pendekatan yang seimbang antara kreativitas dan struktur.';\n} else {\n  enhancedPrompt += ' Fokus pada akurasi dan struktur yang jelas.';\n}\n\n// Add language instruction\nif (language !== 'Indonesian') {\n  enhancedPrompt += ` Jawab dalam bahasa ${language}.`;\n}\n\n// Add metadata\nconst metadata = {\n  original_prompt: userInput,\n  enhanced_prompt: enhancedPrompt,\n  prompt_type: promptType,\n  creativity_level: creativityLevel,\n  language: language,\n  timestamp: new Date().toISOString(),\n  template_used: template\n};\n\nreturn [{ json: metadata }];"
      },
      "id": "enhance-prompt",
      "name": "Enhance Prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "ai_provider_check",
              "leftValue": "={{ $json.prompt_type }}",
              "rightValue": "technical",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "check-ai-integration",
      "name": "Check AI Integration",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "={{ $credentials.googleGenAiApi.apiKey }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "contents",
              "value": "=[{\"parts\": [{\"text\": \"{{ $json.enhanced_prompt }}\"}]}]"
            },
            {
              "name": "generationConfig",
              "value": "={\"temperature\": {{ $json.creativity_level }}, \"maxOutputTokens\": 1000, \"topP\": 0.8, \"topK\": 10}"
            },
            {
              "name": "safetySettings",
              "value": "=[{\"category\": \"HARM_CATEGORY_HARASSMENT\", \"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"}, {\"category\": \"HARM_CATEGORY_HATE_SPEECH\", \"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"}, {\"category\": \"HARM_CATEGORY_SEXUALLY_EXPLICIT\", \"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"}, {\"category\": \"HARM_CATEGORY_DANGEROUS_CONTENT\", \"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"}]"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "id": "gemini-request",
      "name": "Gemini Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1120,
        200
      ],
      "credentials": {
        "googleGenAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "final_response",
              "name": "final_response",
              "value": "={{ $json.enhanced_prompt }}",
              "type": "string"
            },
            {
              "id": "metadata",
              "name": "metadata",
              "value": "={{ $json }}",
              "type": "object"
            },
            {
              "id": "response_type",
              "name": "response_type",
              "value": "enhanced_prompt_only",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "format-response-no-ai",
      "name": "Format Response (No AI)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        1120,
        400
      ]
    },
    {
      "parameters": {
        "jsCode": "// Format Gemini response\nconst geminiResponse = $input.item(0).json;\nconst originalData = $input.item(1).json;\n\n// Extract text from Gemini response structure\nlet aiResponseText = 'No AI response available';\nif (geminiResponse.candidates && geminiResponse.candidates.length > 0) {\n  const candidate = geminiResponse.candidates[0];\n  if (candidate.content && candidate.content.parts && candidate.content.parts.length > 0) {\n    aiResponseText = candidate.content.parts[0].text || 'No text available';\n  }\n}\n\nlet finalResponse = {\n  success: true,\n  original_prompt: originalData.original_prompt,\n  enhanced_prompt: originalData.enhanced_prompt,\n  ai_response: aiResponseText,\n  metadata: {\n    prompt_type: originalData.prompt_type,\n    creativity_level: originalData.creativity_level,\n    language: originalData.language,\n    timestamp: originalData.timestamp,\n    ai_model_used: 'gemini-1.5-flash',\n    tokens_used: geminiResponse.usageMetadata?.totalTokenCount || 0,\n    safety_ratings: geminiResponse.candidates?.[0]?.safetyRatings || []\n  }\n};\n\nreturn [{ json: finalResponse }];"
      },
      "id": "format-ai-response",
      "name": "Format AI Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1340,
        200
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "final_output",
              "name": "final_output",
              "value": "={{ $json }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "merge-responses",
      "name": "Merge Responses",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        1560,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json.final_output || $json }}",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              },
              {
                "name": "Access-Control-Allow-Origin",
                "value": "*"
              }
            ]
          }
        }
      },
      "id": "webhook-response",
      "name": "Webhook Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1780,
        300
      ]
    }
  ],
  "connections": {
    "Webhook Start": {
      "main": [
        [
          {
            "node": "Extract Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Parameters": {
      "main": [
        [
          {
            "node": "Enhance Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enhance Prompt": {
      "main": [
        [
          {
            "node": "Check AI Integration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check AI Integration": {
      "main": [
        [
          {
            "node": "Gemini Request",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Format Response (No AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Request": {
      "main": [
        [
          {
            "node": "Format AI Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Response (No AI)": {
      "main": [
        [
          {
            "node": "Merge Responses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format AI Response": {
      "main": [
        [
          {
            "node": "Merge Responses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Responses": {
      "main": [
        [
          {
            "node": "Webhook Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "createdAt": "2025-01-08T10:00:00.000Z",
      "updatedAt": "2025-01-08T10:00:00.000Z",
      "id": "prompt-generator-gemini",
      "name": "Prompt Generator Gemini"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2025-01-08T10:00:00.000Z",
  "versionId": "1"
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

AI Prompt Generator Workflow - Gemini. Uses httpRequest. Webhook trigger; 9 nodes.

Source: https://github.com/kairokuaa/asssa/blob/2f6c7ca7b7740e921d7037290e103d4aaddeb166/workflows/prompt-generator-gemini-workflow.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This workflow automates end-to-end social media publishing powered by Late API. It generates text content with Google Gemini, creates branded visuals with Kie.ai, uploads media to Late, and publishes

HTTP Request
AI & RAG

This workflow is perfect for app developers, SaaS founders, and mobile growth teams who need constant UGC-style video ads without hiring creators or agencies. If you're spending $500+ per creator and

HTTP Request, Google Drive
AI & RAG

AI Background Generation with Nano Banana (Gemini Image). Uses httpRequest, googleDrive. Webhook trigger; 35 nodes.

HTTP Request, Google Drive
AI & RAG

This template is for developers, teams, and automation enthusiasts who want a private, PIN-protected Telegram chatbot that answers questions from their own documents — without relying on external AI A

Postgres, Telegram, HTTP Request +2
AI & RAG

Elevate your digital presence with high-fidelity cinematic video automation. This workflow orchestrates the complex, asynchronous rendering process of OpenAI Sora—transforming static product images or

HTTP Request, N8N Nodes Uploadtourl