AI Nodes & LLM Integration
You have mastered N8N. Now unlock its most powerful capability: integrating Large Language Models. In this lesson you will connect GPT-4 to your workflows, build AI agents that reason and act, chain prompts together, and create fully autonomous AI pipelines.
The OpenAI Node — Direct GPT Integration
N8N's built-in OpenAI node gives you direct access to GPT-4, GPT-3.5-Turbo, DALL-E, Whisper, and the Embeddings API. Set it up once with your API key and use it in any workflow.
{{ $json.email_body }}.{{ $json.message.content }}. Use this in subsequent nodes — send it as an email, save to a spreadsheet, post to Slack, or chain it into another AI call.Gmail Trigger (new email arrives)
↓
OpenAI Node
Model: gpt-4
System: "You are a concise email summarizer. Return 3 bullet points max."
User: "Summarize this email: {{ $json.text }}"
↓
Slack Node → Post summary to #inbox-summary channel
AI Agents — Let AI Drive Your Workflow
N8N's AI Agent node is more powerful than the basic OpenAI node. It gives the AI access to tools (like web search, calculators, or custom N8N sub-workflows) and lets it autonomously decide which tools to use and in what order to achieve a goal.
Prompt Chaining — Multi-Step AI Pipelines
Complex AI tasks often need multiple LLM calls in sequence. Chain OpenAI nodes together where each node's output feeds the next node's input, building up a multi-step reasoning pipeline.
Step 1 — OpenAI (Research)
Prompt: "List 5 key facts about: {{ $json.topic }}"
Output: list of 5 facts → saved to facts variable
Step 2 — OpenAI (Outline)
Prompt: "Create a blog post outline using these facts:
{{ $('Step 1').item.json.message.content }}"
Output: structured outline
Step 3 — OpenAI (Write)
Prompt: "Write a 500-word blog post using this outline:
{{ $('Step 2').item.json.message.content }}"
Output: finished blog post → save to Google Docs