Connecting OpenAI to n8n takes under 5 minutes and requires only your OpenAI API key. Step 1: Go to platform.openai.com/api-keys, sign in, and click “Create new secret key” — copy the key immediately (it won’t be shown again). Step 2: In n8n, navigate to Credentials → + Add Credential, search for “OpenAI API,” and paste your key . Step 3: Select your preferred model (GPT-4o-mini is most cost-effective for testing; GPT-4o for higher quality) . Step 4: Add an OpenAI node to your workflow, select your credential, choose an operation (Chat Completion, Text Completion, or Assistant), and configure parameters like temperature (0.2 for factual, 0.8 for creative). Step 5: Test the connection by executing the node — you should receive an AI-generated response. For AI Agent workflows, set the OpenAI Chat Model node as the language model and reference it in the AI Agent node . For advanced features like GPT-5, you can install the n8n-nodes-openai-gpt5 community node .
1. Prerequisites: What You Need Before Starting {#prerequisites}
Before connecting OpenAI to n8n, ensure you have:
| Requirement | Details |
|---|---|
| n8n instance | Self-hosted (Docker/npm) or n8n.cloud account |
| OpenAI account | Sign up at platform.openai.com |
| OpenAI API key | Starts with sk-proj-... |
| API credits | Minimum $5 recommended for testing |
| Admin access | Permission to add credentials in n8n |
*”Before importing this workflow, make sure you have: n8n Instance (cloud or self-hosted), OpenAI API Key (with GPT-4 Vision access)”*
2. Step 1: Get Your OpenAI API Key {#get-api-key}
Creating Your API Key
| Step | Action |
|---|---|
| 1 | Go to platform.openai.com/api-keys |
| 2 | Sign in or create an account |
| 3 | Click “+ Create new secret key” |
| 4 | Name your key (e.g., “n8n-automation”) |
| 5 | Select permissions (default is fine) |
| 6 | Click “Create secret key” |
| 7 | COPY THE KEY IMMEDIATELY — you won’t see it again |
API Key Format
Your OpenAI API key will look like this:
text
sk-proj-abc123def456ghi789jkl012mno345pqr678stu...
Add Credits to Your Account
| Step | Action |
|---|---|
| 1 | Go to Settings → Billing |
| 2 | Click “Add to credit balance” |
| 3 | Add minimum $5 (recommended for testing) |
“You can get your OpenAI API key from platform.openai.com. Create a new API key, copy it, and add it to the OpenAI Chat Model node credentials”
Optional: Get Organization ID
If you belong to multiple organizations in OpenAI:
- Go to platform.openai.com → Settings → Organization
- Copy your Organization ID (starts with
org-...) - You’ll need this if using the GPT-5 community node
3. Step 2: Configure OpenAI Credentials in n8n {#configure-credentials}
Now add your OpenAI API key to n8n.
For Standard OpenAI API (Most Common)
| Step | Action |
|---|---|
| 1 | Open your n8n instance |
| 2 | Click Credentials in the left sidebar |
| 3 | Click “+ Add Credential” |
| 4 | Search for “OpenAI API” |
| 5 | Paste your API key into the API Key field |
| 6 | (Optional) Add Organization ID if applicable |
| 7 | Click Save |
“In n8n, go to Credentials → Create New. Select ‘OpenAI API’ and enter your OpenAI API Key”
“Configure the OpenAI Chat Model node: Create a new OpenAI credential in n8n and store your API key securely”
For HTTP Header Auth (Alternative Method)
Some workflows use HTTP Header Authentication instead of the native node :
| Step | Action |
|---|---|
| 1 | Go to Credentials → New |
| 2 | Select HTTP Header Auth |
| 3 | Header name: Authorization |
| 4 | Value: Bearer YOUR-OPENAI-API-KEY |
| 5 | Name it (e.g., openAIApiHeader) |
| 6 | Click Save |
“Go to Credentials → New → HTTP Header Auth. Header name: Authorization. Value: Bearer YOUR-OPENAI-API-KEY”
4. Step 3: Add and Configure OpenAI Node {#add-openai-node}
Adding the Node
| Step | Action |
|---|---|
| 1 | Create a new workflow or open an existing one |
| 2 | Click “+” to add a node |
| 3 | Search for “OpenAI” |
| 4 | Select the OpenAI node |
| 5 | Connect it to your trigger node (Webhook, Schedule, Manual) |
Configuring the Node
*”Choose a model that matches your performance and cost requirements. Common choices include gpt-4o-mini for cost-efficient, responsive interactions or gpt-4/gpt-4o for higher quality responses”*
Example Configuration for Chat Completion
json
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant for customer support. Keep responses concise and friendly."
},
{
"role": "user",
"content": "{{ $json.message }}"
}
],
"temperature": 0.7,
"max_tokens": 500
}
System Prompt Best Practices
| Do | Don’t |
|---|---|
| Be specific about role | Use vague instructions |
| Set response length expectations | Leave open-ended |
| Define tone and style | Mix contradictory instructions |
| Add guardrails for out-of-scope queries | Skip error handling |
5. Step 4: Test Your Connection {#test-connection}
Method 1: Execute Node
| Step | Action |
|---|---|
| 1 | Click “Execute Node” (play button) on the OpenAI node |
| 2 | If using Chat Trigger, send a test message |
| 3 | Wait for response (typically 2-5 seconds) |
| 4 | Check the output in the Execution Data panel |
Expected Successful Output
json
{
"messages": [
{
"role": "assistant",
"content": "Hello! How can I help you today?"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 10,
"total_tokens": 35
}
}
Troubleshooting Test Failures
| Error | Likely Cause | Solution |
|---|---|---|
Invalid API Key | Key is incorrect or has spaces | Regenerate key, paste carefully |
Insufficient Quota | No credits in OpenAI account | Add credits via Billing |
401 Unauthorized | API key invalid or expired | Check key, create new one |
429 Rate Limit | Too many requests | Wait or upgrade tier |
Connection timeout | Network issue | Check n8n internet access |
6. Using OpenAI with AI Agent Workflows {#ai-agent-workflows}
n8n’s AI Agent nodes create more powerful automations by adding memory and tool-use capabilities to OpenAI .
Architecture Overview
The AI Agent workflow connects these components :
| Component | Role |
|---|---|
| Chat Trigger / Webhook | Receives user messages |
| AI Agent Node | Orchestrates memory, model, and tools |
| OpenAI Chat Model | Generates responses |
| Simple Memory | Stores conversational context |
| Tools (e.g., SerpAPI) | External actions like web search |
“The AI Agent node sits at the center of the workflow. It uses the OpenAI Chat Model for reasoning and response generation, consults Simple Memory for contextual continuity, and selectively invokes SerpAPI when a query requires fresh, external data”
Step-by-Step: Building an AI Agent
Step 1: Add AI Agent Node
| Setting | Value |
|---|---|
| Node | AI Agent |
| Credential | (none – uses connected nodes) |
| System Instructions | Define the agent’s role and behavior |
Step 2: Add OpenAI Chat Model Node
| Setting | Value |
|---|---|
| Credential | Your OpenAI credential |
| Model | gpt-4o-mini or gpt-4o |
Step 3: Connect Nodes
text
Chat Trigger → AI Agent → OpenAI Chat Model
↓
Simple Memory
↓
[Tool Nodes]
“Within the AI Agent node, link all components: Set the Chat Model node as the agent’s language model. Specify the Simple Memory node as the memory store. Register tool nodes (e.g., SerpAPI) for external actions”
Step 4: Configure Simple Memory
| Setting | Recommendation |
|---|---|
| Memory window size | 5-10 conversation turns |
| Storage | What fields to retain |
| Session ID | User identifier for context |
Step 5: Add System Instructions
text
You are a helpful customer support assistant for [Company Name]. You have access to web search for current information. Be concise, friendly, and accurate. If you don't know something, say so rather than guessing.
Example: AI Agent with Web Search
This workflow connects OpenAI Chat Model, Simple Memory, and SerpAPI for live web search .
“The AI Agent node is responsible for receiving the user message from the trigger, calling the configured OpenAI Chat Model, reading from and writing to the Simple Memory node, and invoking SerpAPI as a tool when a web search is appropriate”
7. Advanced: GPT-5 Model Support via Community Node {#gpt5-community-node}
For access to OpenAI’s latest GPT-5 models, install the n8n-nodes-openai-gpt5 community node .
Key Features of GPT-5 Node
| Feature | Details |
|---|---|
| Models supported | GPT-5, GPT-5 Mini, GPT-5 Nano, O3, O3 Pro, O3 Mini |
| PDF Processing | Upload and process PDF files directly |
| Reasoning Control | Fine-tune reasoning effort (minimal, low, medium, high) |
| Verbosity Control | Adjust output length (low, medium, high) |
| AI Agent Tool Support | Use as a tool with n8n AI Agent nodes |
| Multiple File Support | Process multiple PDFs/images in one request |
*”This is an n8n community node that provides access to OpenAI’s GPT-5 models and advanced features through the Responses API. Supports PDF processing, multiple file inputs, and all the latest GPT-5 capabilities”*
Installation Steps
| Step | Action |
|---|---|
| 1 | In n8n, go to Settings → Community Nodes |
| 2 | Search for n8n-nodes-openai-gpt5 |
| 3 | Click Install |
| 4 | Restart n8n if prompted |
Alternative Manual Installation:
bash
npm install n8n-nodes-openai-gpt5 # Then restart n8n instance
Configuring GPT-5 Credentials
| Step | Action |
|---|---|
| 1 | Go to Credentials → + Add Credential |
| 2 | Search for “OpenAI GPT-5 API” |
| 3 | Enter your OpenAI API key |
| 4 | (Optional) Add Organization ID |
| 5 | Click Save |
Enable AI Agent Tool Mode
If using as an AI Agent tool, set this environment variable:
bash
N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true
*”This node can be used as a tool with n8n’s AI Agent nodes, allowing AI agents to leverage GPT-5’s advanced reasoning capabilities”*
8. Advanced: OpenAI-Compatible APIs (Custom Base URL) {#openai-compatible}
You can connect n8n to any OpenAI-compatible API service (like Qwen, local LLMs, or proxies) using custom credentials .
Installing the OpenAI-Compatible Node
| Step | Action |
|---|---|
| 1 | Go to Settings → Community Nodes |
| 2 | Search for n8n-nodes-openai-compatible-node |
| 3 | Click Install |
Configuring Custom Credentials
| Field | Value |
|---|---|
| Base URL | Your API endpoint (e.g., https://your-service.com/v1) |
| API Key | Your service’s API key |
“This node allows you to interact with any OpenAI-compatible API service. Configure Base URL (e.g., https://api.openai.com, https://your-service.com) and API Key”
Supported Operations
| Operation | Use Case |
|---|---|
| Chat Completion | Conversational AI responses |
| Text Completion | General text generation |
9. Common Use Cases & Workflow Examples {#use-cases}
Use Case 1: AI Email Generator with Tone Selection
Generate professional emails with custom tones .
Components:
- Webhook/Form trigger
- OpenAI Chat Model node
- Response node
“Setup: Get OpenAI API key, add it to the OpenAI Chat Model node credentials. Customize tones, adjust AI settings (model, temperature, max tokens)”
Use Case 2: Personalized Job Application Assistant
Telegram + OpenAI + Gmail workflow .
Components:
- Telegram Bot trigger
- OpenAI node (with file upload)
- Gmail node
*”Prerequisites: n8n instance, Telegram Bot Token, OpenAI API Key (with GPT-4 Vision access), Gmail Account”*
Use Case 3: Document Summarizer with OpenAI Assistants API
Generate summaries from uploaded files .
Components:
- HTTP Request node (to OpenAI)
- File upload node
- OpenAI Assistant node
“This workflow automates the creation and management of a custom OpenAI Assistant. Requires OpenAI API key and Assistant ID (starts with asst_)”
Use Case 4: Travel Agency Assistant with Google Drive
Custom OpenAI Assistant using Google Drive for document storage .
Components:
- Google Drive node (download document)
- OpenAI node (create assistant, upload file)
- Chat Trigger node
- Window Buffer Memory
“This workflow automates the creation and management of a custom OpenAI Assistant, leveraging Google Drive for document storage. Uses Window Buffer Memory to retain chat context”
Use Case 5: AI Agent with Memory and Web Search
Production-ready workflow with OpenAI + SerpAPI + Memory .
Components:
- Chat trigger / webhook
- AI Agent node
- OpenAI Chat Model
- Simple Memory
- SerpAPI
*”Automate intelligent, context-aware conversations and real-time search. Connects n8n AI Agent to OpenAI Chat Model, SerpAPI for web search, and Simple Memory for conversational context”*
10. Troubleshooting Common Issues {#troubleshooting}
Issue 1: “Invalid API Key”
| Cause | Solution |
|---|---|
| Extra spaces in key | Re-paste carefully |
| Wrong key copied | Generate new key |
| Key deleted/revoked | Check OpenAI API Keys page |
Issue 2: “Insufficient Quota”
| Cause | Solution |
|---|---|
| No credits in account | Add credits in Billing |
| Free trial expired | Add payment method |
Issue 3: AI Agent Not Using Tools
| Cause | Solution |
|---|---|
| Tool not registered in agent config | Register node as tool in AI Agent |
| System instructions don’t mention tools | Add: “You have access to web search” |
| Incorrect tool configuration | Verify node connections |
Issue 4: Memory Not Retaining Context
| Cause | Solution |
|---|---|
| Memory node not connected | Connect to AI Agent |
| Window size too small | Increase memory window |
| Session ID not set | Configure session identifier |
Issue 5: Slow Response Times
| Cause | Solution |
|---|---|
| Using GPT-4 (slower) | Switch to GPT-4o-mini |
| High temperature settings | Lower temperature for faster |
| Large context window | Reduce conversation history |
Issue 6: OpenAI Assistants API Issues
For OpenAI Assistants API workflows, ensure :
- Assistant ID is correctly entered (starts with
asst_) - File Search and Code Interpreter are enabled
- Credential uses Header Auth:
Bearer YOUR-API-KEY
11. Comparison Table: OpenAI Models in n8n {#comparison-table}
| Model | Best For | Speed | Cost | Context Window |
|---|---|---|---|---|
| GPT-4o-mini | Cost-efficient, fast responses | Fastest | Lowest | 128K |
| GPT-4o | High quality, complex reasoning | Medium | Medium | 128K |
| GPT-5 | Latest capabilities, advanced reasoning | Slower | Higher | 1M |
| GPT-5 Mini | Balanced cost/quality | Fast | Medium | 1M |
| GPT-5 Nano | Most cost-efficient | Fastest | Lowest | 1M |
| O3 Series | Advanced reasoning tasks | Slow | Highest | 200K |
*”Choose a model that matches your performance and cost requirements. Common choices include gpt-4o-mini for cost-efficient, responsive interactions or gpt-4/gpt-4o for higher quality”*
12. Frequently Asked Questions : How to Connect OpenAI to N8N Step By Step Guide
How do I get an OpenAI API key for n8n?
Go to platform.openai.com/api-keys, sign in, click “Create new secret key,” name it, and copy the key immediately — it won’t be shown again .
Where do I add the OpenAI API key in n8n?
Go to Credentials → + Add Credential → Search “OpenAI API” → Paste your API key → Save .
What’s the difference between OpenAI node and OpenAI Chat Model node?
The OpenAI node is for direct API calls (Chat Completion, Text Completion, Assistant). The OpenAI Chat Model node is specifically designed to work with AI Agent nodes and includes memory integration .
How do I use GPT-5 in n8n?
Install the community node n8n-nodes-openai-gpt5 from Settings → Community Nodes. Then create credentials and add the GPT-5 node to your workflow .
Can I use n8n with OpenAI Assistants API?
Yes. You need an Assistant ID (starts with asst_), enable File Search and Code Interpreter, and use HTTP Header Auth credentials (Bearer YOUR-API-KEY) .
How do I add memory to OpenAI conversations in n8n?
Use the AI Agent node with Simple Memory node. Configure memory window size and connect it to the AI Agent — it will automatically retain conversation context .
What’s the best OpenAI model for n8n workflows?
For most use cases, gpt-4o-mini offers the best balance of speed, cost, and quality. Use gpt-4o for higher quality when needed. Use GPT-5 series for advanced reasoning or PDF processing .
How do I test if my OpenAI connection is working?
Add an OpenAI node to a workflow, select your credential, add a simple user message like “Say hello,” and click “Execute Node.” You should receive an AI-generated response.
Can I connect n8n to non-OpenAI APIs?
Yes. Install the n8n-nodes-openai-compatible-node community node and configure a custom Base URL and API key for any OpenAI-compatible service .
How much does it cost to use OpenAI with n8n?
OpenAI API costs are pay-per-token. GPT-4o-mini is approximately $0.15 per million input tokens and $0.60 per million output tokens. The first $5-10 in credits is usually enough for extensive testing .
The Bottom Line
The most important takeaway: Getting started takes under 5 minutes — just get your API key from OpenAI, paste it into n8n credentials, and add an OpenAI node to your workflow. For more sophisticated automations, use the AI Agent node with memory and tools .
Action Steps for Today
- Get your OpenAI API key (5 minutes at platform.openai.com)
- Add $5-10 in credits to your OpenAI account (2 minutes)
- Open n8n and add OpenAI credential (2 minutes)
- Create a test workflow with OpenAI node (3 minutes)
- Execute and verify you receive a response (1 minute)
Total time to first working AI automation: Under 15 minutes
Explore More on Coggnix.io
- Best AI Tool for Proposal Writing: 7 Tools Tested & Compared (2026 Guide)
Best Free AI Image Generator With No Restrictions: 7 Tools That Actually Work (2026) - Best Free AI Workflow Automation Tools: 8 Tools That Save Hours Every Day (2026)
- Best AI Video Generator Free No Sign Up No Limits
This article contains affiliate links. Coggnix.io may earn a commission if you purchase through these links, at no additional cost to you. We only recommend tools we have tested and believe deliver value.
Follow us one Facebook for more Educational Content