Lesson 12 of 12 · Final Phase 4 · AI Integration

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.

🤖
GPT-4
OpenAI node
🧠
AI Agents
Reason + act
⛓️
Prompt Chains
Multi-step AI
🔧
Langchain
AI toolkit
Section 1

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.

1
Add Your OpenAI Credentials
In N8N, go to Settings → Credentials → Add Credential → OpenAI API. Paste your API key from platform.openai.com. Name it "OpenAI Production". This credential is reusable across all your workflows.
2
Add the OpenAI Node
Click +, search "OpenAI". Select your resource: Message (for GPT chat), Image (DALL-E), Audio (Whisper), or Embed (vectors). For most AI workflows, use "Message" with the "Create a Chat Completion" operation.
3
Configure System + User Messages
Set a System message to define the AI's role and behavior ("You are a professional email summarizer..."). Set the User message to the dynamic data from your workflow using expressions like {{ $json.email_body }}.
4
Use the AI Output
The OpenAI node returns the AI's response in {{ $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.
Example: Email Summarizer Workflow
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
Section 2

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.

🌐
Web Search Tool
Give the agent internet access. It searches, reads results, and uses them to answer questions or make decisions — all automatically.
🔧
Custom Tools
Any N8N workflow can be a tool. The agent calls your internal workflows (lookup customer, send email, query database) as needed to complete its task.
💾
Memory
Agents can maintain conversation memory across multiple messages using N8N's memory nodes, enabling multi-turn conversations and context retention.
💡
When to use Agent vs OpenAI node: Use the OpenAI node for simple one-shot tasks (summarize this, classify this, translate this). Use the AI Agent node when you need the AI to reason through a multi-step problem and decide what actions to take — like a research assistant or autonomous task manager.
Section 3

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.

3-Step Content Generation 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
💰
Control costs: GPT-4 is expensive. For simple classification or short-output tasks, use gpt-3.5-turbo (10x cheaper). Reserve GPT-4 for tasks requiring deep reasoning, complex writing, or nuanced judgment. Use max_tokens to cap output length and prevent runaway costs.

🧠 AI Integration Final Check

1. You want to build a system where the AI can search the web, check your database, and send emails autonomously to complete a task. Which N8N feature should you use?
2. In the OpenAI node, what is the difference between the System message and the User message?
3. How do you pass the output of one OpenAI node into the next OpenAI node in a prompt chain?
Finished Lesson 12?

You have completed all 12 N8N lessons — you are now an N8N automation builder!

🎓

You've Completed N8N Workflow Automation!

Claim your official certificate — includes a unique ID and scannable QR code for instant verification.

🏆 Claim Your Certificate
Scannable QR · Unique Certificate ID · Printable PDF