How to Add OpenAI API Key to n8n & Build AI Workflows 2025
How to Add OpenAI API Key to n8n & Build AI Workflows 2025
Integrating Artificial Intelligence into your automations is a game-changer. In this guide, we’ll show you exactly how to add OpenAI API key to n8n node and build your first AI-powered workflow.
Step 1: Get Your OpenAI API Key
Before opening n8n, you need a key from OpenAI.
- Log in to OpenAI Platform.
- Go to API Keys in the dashboard.
- Click Create new secret key.
- Copy it immediately (you won’t see it again).
⚠️ Important: Ensure you have added billing information to OpenAI, or the API calls will fail.
Step 2: Add Credentials in n8n
Now, let’s secure that key in n8n.
- Open your n8n dashboard.
- Click on Credentials in the left sidebar.
- Click Add Credential.
- Search for “OpenAI API”.
- Paste your key starting with
sk-...into the API Key field. - Click Save.
🎉 You’ve successfully connected OpenAI!
Step 3: Build an AI Workflow
Let’s build a simple “Article Summarizer”.
1. Add the OpenAI Node
- Drag an OpenAI node onto the canvas.
- Select your new credential.
- Resource: Chat
- Operation: Complete
2. Configure the Prompt
In the Messages parameter:
- Role: System
- Content: “You are a helpful assistant that summarizes text concisely.”
- Role: User
- Content: Map the input from your trigger (e.g., an RSS feed item description).
3. Test It
Click Execute Node. You should see a JSON response with the generated summary in message.content.
Advanced: Building n8n AI Agents
n8n has introduced advanced LangChain nodes for building autonomous agents.
Key Components:
- Agent Node: The brain (uses OpenAI).
- Memory Node: Remembers conversation context.
- Tool Nodes: Gives the AI abilities (e.g., Google Search, Calculator).
Example Use Case: A customer support bot that can:
- Read an incoming email.
- Check the order status in your database (Tool).
- Draft a personalized reply using GPT-4.
- Send the draft to Slack for approval.
Troubleshooting
- Error 401 (Unauthorized): Your API key is wrong or deleted.
- Error 429 (Too Many Requests): You hit your OpenAI rate limit or ran out of credits. Check billing.
Conclusion
Knowing how to add OpenAI API key to n8n node is just the beginning. With this connection, you can automate content writing, data analysis, customer support, and more—all tailored to your specific needs.