n8n + OpenAI Integration Guide
Published May 2026Pair n8n with OpenAI and you have an automation engine with a brain. This guide shows you how to build AI-powered workflows that generate content, process data, and make decisions without human input.
What You Can Build
- Daily AI-generated blog summaries posted to Slack
- Auto-reply to customer emails with GPT-4
- Extract action items from meeting transcripts
- Generate social media posts from RSS feeds
- Classify and route support tickets by sentiment
Setup: Connect OpenAI to n8n
1. Get an OpenAI API Key
Go to platform.openai.com, create a new secret key, and copy it. Set billing limits to avoid surprises.
2. Add the Credential in n8n
- Open n8n → Credentials → New
- Select "OpenAI"
- Paste your API key
- Test the connection
3. Build Your First AI Workflow
Create a simple workflow: Schedule trigger → OpenAI node → Slack node.
Example Workflow: AI Content Generator
Trigger: Every day at 9 AM
|
v
OpenAI (Chat Model)
Model: gpt-4o
System Prompt: "You are a tech news summarizer."
User Prompt: "Summarize today's top AI news in 3 bullet points."
|
v
Slack (Send Message)
Channel: #ai-news
Message: {{ $json.content }}
Advanced: Chain Multiple AI Calls
Use the "Loop" functionality to process multiple items. Generate 10 tweet variations from one article. Translate content to 5 languages. Summarize 50 customer reviews in parallel.
Cost Optimization
- Use GPT-4o-mini for 95% of tasks — it is 20x cheaper
- Set API usage limits in OpenAI dashboard
- Use n8n's "Wait" node to stay within rate limits
- Cache responses for identical prompts
Error Handling
Always add an "Error Trigger" node. When OpenAI fails, send a notification instead of silently failing. Set retries: 3 attempts with exponential backoff.
Security Best Practices
- Never hardcode API keys in workflows
- Use n8n's built-in credential vault
- Restrict API key access in OpenAI dashboard
- Rotate keys every 90 days
Start with one simple workflow. The compound value of 5-10 AI automations running daily is transformative for any small business or solo operator.