How to Add OpenAI API Key to n8n Node
To add an OpenAI API key to an n8n node: (1) Go to Settings → Credentials in your n8n dashboard, (2) Click “+ Add Credential” and search for “OpenAI” , (3) Paste your OpenAI API key (starts with sk-) into the API Key field, (4) (Optional) Add a Base URL if using a proxy or custom endpoint, (5) Click Save, (6) In your workflow node, select the credential from the dropdown. If using the AI Agent with LangChain nodes, use the “OpenAI Chat Model” credential type instead. For self-hosted n8n, ensure your API key has sufficient credits and the organization ID is correct.
1. What You Need Before Starting {#prerequisites}
Before you begin, make sure you have:
| Prerequisite | 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-... |
| API credits | Minimum $5-10 balance for testing |
| Admin access | Permission to add credentials in n8n |
Important Note: If you’re using n8n’s AI Agent nodes (LangChain-based), you’ll need a different credential type called “OpenAI Chat Model” instead of the standard OpenAI credential. The standard OpenAI credential works with the regular “OpenAI” node for basic chat completions.
2. Step 1: Get Your OpenAI API Key {#get-api-key}
If you don’t have an OpenAI API key yet, follow these steps.
Creating Your API Key
| Step | Action |
|---|---|
| 1 | Go to platform.openai.com |
| 2 | Sign in or create an account |
| 3 | Click on your profile picture → “API Keys” |
| 4 | Click “+ Create new secret key” |
| 5 | Name your key (e.g., “n8n-workflow”) |
| 6 | Select permissions (default is fine) |
| 7 | Click “Create secret key” |
| 8 | 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...
⚠️ Important: Keep your API key secure. Never share it or commit it to public repositories.
Adding Credits to Your OpenAI Account
New OpenAI accounts need to add credits before using the API:
- Go to Settings → Billing
- Click “Add to credit balance”
- Add minimum $5 (recommended for testing)
- Credits never expire
3. Step 2: Access n8n Credentials Section {#access-credentials}
Once you have your API key, open your n8n instance.
For n8n Cloud (app.n8n.cloud)
| Step | Action |
|---|---|
| 1 | Log into your n8n.cloud account |
| 2 | Click your profile icon in the top-right |
| 3 | Select “Credentials” from the dropdown |
| 4 | Click the “+ Add Credential” button |
For Self-Hosted n8n
| Step | Action |
|---|---|
| 1 | Open your n8n instance (e.g., http://localhost:5678) |
| 2 | Click the “Credentials” icon in the left sidebar |
| 3 | Click the “+ New” button (or “+ Add Credential”) |
Pro tip: You can also access credentials from within any workflow by clicking the “Add Credential” button on an OpenAI node.
4. Step 3: Add OpenAI Credential {#add-credential}
Now you’ll search for and select the correct OpenAI credential type.
Finding the OpenAI Credential
Which Credential Should You Choose?
If you’re unsure, start with the standard “OpenAI API” credential — it works with most basic workflows.
5. Step 4: Configure API Key and Base URL {#configure-credential}
Basic Configuration
| Field | What to Enter |
|---|---|
| API Key | Paste your OpenAI secret key (starts with sk-...) |
| Base URL | Leave blank (uses default https://api.openai.com/v1) |
For most users, that’s it! Click “Save” and you’re done.
Optional: Organization ID
If you belong to multiple organizations in OpenAI, you can add your Organization ID:
- Go to platform.openai.com → Settings → Organization
- Copy your Organization ID (starts with
org-...) - Paste it in the “Organization ID” field in n8n
This ensures API usage is billed to the correct organization.
Advanced: Custom Base URL
You can change the Base URL if you’re using:
⚠️ Important: If you change the Base URL, make sure the endpoint follows the OpenAI API format (/v1 at the end).
6. Step 5: Test the Connection {#test-connection}
After saving your credential, test that it works.
Method 1: Add a Test Node
| Step | Action |
|---|---|
| 1 | Create a new workflow |
| 2 | Add an “OpenAI” node |
| 3 | In the node settings, select your new credential |
| 4 | Set operation to “Chat Completion” |
| 5 | Add a simple message: "Say 'Connection successful!'" |
| 6 | Click “Execute Node” or “Test” |
Expected result: You should see a response from the AI model.
Method 2: Check for Errors
| Error Message | What It Means |
|---|---|
Invalid API Key | Key is incorrect or has extra spaces |
Insufficient Quota | No credits in OpenAI account |
401 Unauthorized | API key is invalid or expired |
404 Not Found | Wrong Base URL or endpoint |
Rate limit exceeded | Too many requests — wait a moment |
If the Test Fails
- Verify your API key — Copy it again from OpenAI platform
- Check for spaces — Make sure there are no extra spaces before/after
- Check credits — Go to OpenAI billing dashboard
- Check Base URL — If you changed it, revert to default for testing
7. Using OpenAI in Different n8n Nodes {#using-in-nodes}
Once your credential is saved, you can use it across different OpenAI-related nodes.
Standard OpenAI Node
The standard “OpenAI” node supports:
- Chat Completions
- Text Completions
- Embeddings
- Image Generation (DALL-E)
- Speech to Text (Whisper)
To use: Add node → Select credential → Choose operation → Configure parameters.
AI Agent with LangChain
For AI Agent workflows using the LangChain nodes:
| Step | Action |
|---|---|
| 1 | Add an “AI Agent” node |
| 2 | Add an “OpenAI Chat Model” node |
| 3 | In the Chat Model node, select “OpenAI Chat Model” credential |
| 4 | Connect the Chat Model output to the AI Agent’s model input |
| 5 | Add memory and tools as needed |
Example workflow structure:
text
Chat Trigger → AI Agent → OpenAI Chat Model → Response
↑
Memory Window
Important: Disable “Use Responses API” for Some Setups
If you’re using a custom Base URL (like Zeabur AI Hub), you may need to disable the “Use Responses API” option in your OpenAI node settings. This option is for OpenAI’s newer Responses API format, which some custom endpoints don’t support.
To disable: Find the “Use Responses API” toggle in your OpenAI node settings and turn it OFF.
OpenAI GPT-5 API Node (Community Node)
If you installed the n8n-nodes-openai-gpt5 community node, you get additional features:
| Feature | Description |
|---|---|
| GPT-5, GPT-5 Mini, GPT-5 Nano | Latest models |
| PDF processing | Upload PDFs directly |
| Reasoning control | Adjust reasoning effort (minimal to high) |
| AI Agent Tool mode | Use as a tool with AI Agent nodes |
| Multiple file support | Process multiple files in one request |
To use: Install the community node → Create “OpenAI GPT-5 API” credential → Use the node in workflows.
8. Troubleshooting Common Issues {#troubleshooting}
Issue 1: “Invalid API Key” Error
| Possible Cause | Solution |
|---|---|
| Extra spaces in API key | Re-paste the key carefully |
| Wrong key copied | Generate a new key from OpenAI dashboard |
Key doesn’t start with sk- | You might have copied the wrong string |
| Key was deleted/revoked | Check OpenAI API Keys page |
Issue 2: “Insufficient Quota” Error
| Possible Cause | Solution |
|---|---|
| No credits in account | Add credits in OpenAI billing |
| Free trial expired | Add payment method |
| Usage exceeded limit | Check usage dashboard |
Fix: Go to platform.openai.com → Settings → Billing → Add credits.
Issue 3: Connection Timeout
| Possible Cause | Solution |
|---|---|
| Internet connectivity | Check your network |
| Firewall blocking | Allow outbound to api.openai.com |
| Self-hosted n8n without internet | Use a local model or proxy |
Issue 4: Base URL Not Working
| Possible Cause | Solution |
|---|---|
Missing /v1 at end | Add /v1 to your Base URL |
| Wrong endpoint | Use default https://api.openai.com/v1 for testing |
| Service down | Check service status page |
Issue 5: “Use Responses API” Causing Failures
If you’re using a custom Base URL (Zeabur, proxy, local LLM), try:
| Step | Action |
|---|---|
| 1 | Open your OpenAI node settings |
| 2 | Find “Use Responses API” toggle |
| 3 | Turn it OFF |
| 4 | Execute again |
Issue 6: Self-Hosted n8n Can’t Connect
If your self-hosted n8n can’t reach OpenAI:
- Check Docker network: If using Docker, ensure outgoing traffic is allowed
- Proxy configuration: Set
HTTP_PROXYandHTTPS_PROXYenvironment variables - DNS resolution: Ensure n8n can resolve api.openai.com
9. Advanced: Custom Base URL for OpenAI-Compatible APIs {#custom-base-url}
n8n’s OpenAI credential can connect to ANY OpenAI-compatible API endpoint — not just OpenAI’s official API.
When to Use Custom Base URL
| Use Case | Example |
|---|---|
| Using a proxy service | Zeabur AI Hub, OpenRouter |
| Local LLM with OpenAI API | Ollama, LM Studio, LocalAI |
| Alternative providers | Together AI, Groq, DeepSeek |
| Enterprise internal proxy | Company API gateway |
Configuration Example for Zeabur AI Hub
⚠️ Important: Disable “Use Responses API” when using Zeabur.
Configuration Example for Ollama (Local)
Configuration Example for Groq
| Field | Value |
|---|---|
| API Key | Your Groq API key (starts with gsk_...) |
| Base URL | https://api.groq.com/openai/v1 |
OpenAI-Compatible Credential Node
For maximum flexibility, install the community node n8n-nodes-openai-compatible-node. It provides explicit support for:
- Custom Base URL for any provider
- Chat completions
- Text completions
- Temperature, max tokens, top-p parameters
Installation: Settings → Community Nodes → Search n8n-nodes-openai-compatible-node → Install.
10. Community Nodes for Enhanced OpenAI Features {#community-nodes}
The standard OpenAI credential covers basic needs. For advanced features, consider these community nodes.
n8n-nodes-openai-gpt5
Best for: Latest GPT-5 models, PDF processing, AI Agent tool mode
| Feature | Details |
|---|---|
| Models | GPT-5, GPT-5 Mini, GPT-5 Nano, O3 series |
| File processing | PDF, images (multiple files) |
| Reasoning | Adjust effort (minimal/low/medium/high) |
| AI Agent Tool | Works as tool with AI Agent nodes |
Installation:
Credential Setup: Create “OpenAI GPT-5 API” credential with your OpenAI API key.
n8n-nodes-openai-compatible-node
Best for: Connecting to any OpenAI-compatible API (Qwen, local models, etc.)
| Feature | Details |
|---|---|
| Chat completions | /v1/chat/completions |
| Text completions | /v1/completions |
| Flexible base URL | Any OpenAI-compatible endpoint |
Installation: Search n8n-nodes-openai-compatible-node in Community Nodes.
n8n-nodes-mtls-openai
Best for: Enterprise environments with mTLS authentication
| Feature | Details |
|---|---|
| mTLS support | x509 client certificate authentication |
| Chat model | For AI Agent nodes |
| Embeddings | For vector store operations |
Use case: Connecting to AI inference endpoints behind corporate proxies with mutual TLS.
11. Security Best Practices {#security}
Protect your OpenAI API key and n8n credentials.
DO NOT
| Action | Why |
|---|---|
| Share API key publicly | Anyone can use it and bill your account |
| Commit API key to GitHub | Bots scan for exposed keys |
| Hardcode API key in workflows | Use credentials system instead |
| Use root/admin API key for testing | Create limited-permission keys |
DO
| Action | Why |
|---|---|
| Use n8n’s credential system | Encrypted storage |
| Create separate API keys per workflow | Easy to revoke if compromised |
| Set usage limits in OpenAI dashboard | Prevent unexpected bills |
| Rotate keys periodically | Security best practice |
| Use environment variables (self-hosted) | Keep keys out of config files |
Setting Usage Limits in OpenAI
- Go to platform.openai.com → Settings → Limits
- Set monthly usage limits (10,50, $100, etc.)
- Set notification thresholds
- You’ll get alerts before hitting the limit
Environment Variables for Self-Hosted n8n
You can also configure OpenAI credentials via environment variables:
bash
# For n8n's built-in OpenAI node OPENAI_API_KEY=sk-proj-your-key-here # For custom Base URL OPENAI_BASE_URL=https://your-proxy.com/v1
This is useful for automation and keeping keys out of the UI.
12. FAQ: How to Add OpenAI API Key to n8n Node
Where do I find my OpenAI API key?
Log into platform.openai.com → Click your profile picture → “API Keys” → “+ Create new secret key” → Copy the key immediately (it won’t be shown again).
How do I add an OpenAI API key to n8n?
Go to Credentials → “+ Add Credential” → Search “OpenAI” → Paste your API key → Click Save. Then select the credential in any OpenAI node.
What’s the difference between “OpenAI API” and “OpenAI Chat Model” credentials?
OpenAI API is for the standard OpenAI node (simple chat completions, images, etc.). OpenAI Chat Model is for AI Agent workflows using LangChain nodes. Use the Chat Model credential when building agents with memory and tools.
Do I need a custom Base URL for n8n?
No — for most users, leave Base URL blank. It defaults to https://api.openai.com/v1. Only change it if you’re using a proxy, local LLM, or alternative provider.
Why is my OpenAI node failing with “Use Responses API” error?
If you’re using a custom Base URL (Zeabur, proxy, local LLM), turn OFF the “Use Responses API” toggle in your OpenAI node settings. This feature uses OpenAI’s newer API format that many custom endpoints don’t support.
Can I use n8n with a local LLM instead of OpenAI?
Yes — install Ollama or LM Studio, then create an OpenAI credential with Base URL http://localhost:11434/v1 (Ollama) and any API key. n8n will treat it as OpenAI-compatible.
How much does OpenAI API cost?
Pay-as-you-go. GPT-4o mini is 0.15permillioninputtokens.Fortesting,add5-10 credit. You can set usage limits in OpenAI billing settings.
Is my API key secure in n8n?
Yes — n8n encrypts credentials in its database. For self-hosted n8n, ensure you have a strong encryption key set in environment variables (N8N_ENCRYPTION_KEY).
Can I use one API key across multiple workflows?
Yes — once saved, an OpenAI credential can be used in any workflow. You don’t need to create separate credentials for each workflow.
What should I do if my API key is compromised?
- Immediately delete the key from OpenAI dashboard (API Keys page)
- Create a new key
- Update the credential in n8n
- Check OpenAI usage dashboard for unauthorized activity
The Bottom Line
Adding your OpenAI API key to n8n is a simple 5-minute process:
| Step | What to Do |
|---|---|
| 1 | Get API key from platform.openai.com |
| 2 | Go to n8n Credentials section |
| 3 | Add “OpenAI” credential |
| 4 | Paste API key and save |
| 5 | Test with an OpenAI node |
Most important tips:
- Copy your API key immediately after creating it
- Add credits to your OpenAI account before testing
- Use the correct credential type (standard vs. Chat Model)
- If using custom Base URL, disable “Use Responses API”
Action Steps for Today
- Get your OpenAI API key (5 minutes)
- Add $5-10 credits to your OpenAI account (2 minutes)
- Open your n8n instance (1 minute)
- Add the OpenAI credential following this guide (3 minutes)
- Create a test workflow with an OpenAI node (2 minutes)
- Run a simple test — prompt: “Say hello!” (1 minute)
Total time: ~15 minutes to fully set up and test.
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)
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