How to Add OpenAI API Key to n8n Node: Complete Step-by-Step Guide (2026)

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}

A checklist graphic showing prerequis

Before you begin, make sure you have:

PrerequisiteDetails
n8n instanceSelf-hosted (Docker/npm) or n8n.cloud account
OpenAI accountSign up at platform.openai.com
OpenAI API keyStarts with sk-...
API creditsMinimum $5-10 balance for testing
Admin accessPermission 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

StepAction
1Go to platform.openai.com
2Sign in or create an account
3Click on your profile picture → “API Keys”
4Click “+ Create new secret key”
5Name your key (e.g., “n8n-workflow”)
6Select permissions (default is fine)
7Click “Create secret key”
8COPY 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:

  1. Go to Settings → Billing
  2. Click “Add to credit balance”
  3. Add minimum $5 (recommended for testing)
  4. 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)

StepAction
1Log into your n8n.cloud account
2Click your profile icon in the top-right
3Select “Credentials” from the dropdown
4Click the “+ Add Credential” button

For Self-Hosted n8n

StepAction
1Open your n8n instance (e.g., http://localhost:5678)
2Click the “Credentials” icon in the left sidebar
3Click 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

StepAction
1In the “Add Credential” modal, type “OpenAI” in the search bar
2You’ll see several options:
– OpenAI API (standard — for regular OpenAI nodes)
– OpenAI Chat Model (for AI Agent / LangChain nodes) 
– OpenAI GPT-5 API (if you installed community node) 
3Select “OpenAI API” for standard use

Which Credential Should You Choose?

Use CaseSelect This Credential
Using the standard “OpenAI” nodeOpenAI API
Using AI Agent with LangChainOpenAI Chat Model
Using OpenAI with community nodesOpenAI GPT-5 API (if installed)
Using Responses API for file processingOpenAI GPT-5 API 

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}

n8n logo new.sv

Basic Configuration

FieldWhat to Enter
API KeyPaste your OpenAI secret key (starts with sk-...)
Base URLLeave 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:

  1. Go to platform.openai.com → Settings → Organization
  2. Copy your Organization ID (starts with org-...)
  3. 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:

Use CaseBase URL
Default OpenAI APILeave empty
OpenAI-compatible proxyhttps://your-proxy.com/v1
Zeabur AI Hub (Tokyo)https://hnd1.aihub.zeabur.ai/v1 
Zeabur AI Hub (San Francisco)https://sfo1.aihub.zeabur.ai/v1 
Local Ollama (OpenAI-compatible)http://localhost:11434/v1 

⚠️ 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

StepAction
1Create a new workflow
2Add an “OpenAI” node
3In the node settings, select your new credential
4Set operation to “Chat Completion”
5Add a simple message: "Say 'Connection successful!'"
6Click “Execute Node” or “Test”

Expected result: You should see a response from the AI model.

Method 2: Check for Errors

Error MessageWhat It Means
Invalid API KeyKey is incorrect or has extra spaces
Insufficient QuotaNo credits in OpenAI account
401 UnauthorizedAPI key is invalid or expired
404 Not FoundWrong Base URL or endpoint
Rate limit exceededToo many requests — wait a moment

If the Test Fails

  1. Verify your API key — Copy it again from OpenAI platform
  2. Check for spaces — Make sure there are no extra spaces before/after
  3. Check credits — Go to OpenAI billing dashboard
  4. 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: 

StepAction
1Add an “AI Agent” node
2Add an “OpenAI Chat Model” node
3In the Chat Model node, select “OpenAI Chat Model” credential
4Connect the Chat Model output to the AI Agent’s model input
5Add 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: 

FeatureDescription
GPT-5, GPT-5 Mini, GPT-5 NanoLatest models
PDF processingUpload PDFs directly
Reasoning controlAdjust reasoning effort (minimal to high)
AI Agent Tool modeUse as a tool with AI Agent nodes
Multiple file supportProcess 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 CauseSolution
Extra spaces in API keyRe-paste the key carefully
Wrong key copiedGenerate a new key from OpenAI dashboard
Key doesn’t start with sk-You might have copied the wrong string
Key was deleted/revokedCheck OpenAI API Keys page

Issue 2: “Insufficient Quota” Error

Possible CauseSolution
No credits in accountAdd credits in OpenAI billing
Free trial expiredAdd payment method
Usage exceeded limitCheck usage dashboard

Fix: Go to platform.openai.com → Settings → Billing → Add credits.

Issue 3: Connection Timeout

Possible CauseSolution
Internet connectivityCheck your network
Firewall blockingAllow outbound to api.openai.com
Self-hosted n8n without internetUse a local model or proxy

Issue 4: Base URL Not Working

Possible CauseSolution
Missing /v1 at endAdd /v1 to your Base URL 
Wrong endpointUse default https://api.openai.com/v1 for testing
Service downCheck service status page

Issue 5: “Use Responses API” Causing Failures

If you’re using a custom Base URL (Zeabur, proxy, local LLM), try: 

StepAction
1Open your OpenAI node settings
2Find “Use Responses API” toggle
3Turn it OFF
4Execute again

Issue 6: Self-Hosted n8n Can’t Connect

If your self-hosted n8n can’t reach OpenAI:

  1. Check Docker network: If using Docker, ensure outgoing traffic is allowed
  2. Proxy configuration: Set HTTP_PROXY and HTTPS_PROXY environment variables
  3. 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 CaseExample
Using a proxy serviceZeabur AI Hub, OpenRouter
Local LLM with OpenAI APIOllama, LM Studio, LocalAI
Alternative providersTogether AI, Groq, DeepSeek
Enterprise internal proxyCompany API gateway

Configuration Example for Zeabur AI Hub

FieldValue
API KeyYour Zeabur AI Hub API key
Base URLhttps://hnd1.aihub.zeabur.ai/v1 

⚠️ Important: Disable “Use Responses API” when using Zeabur. 

Configuration Example for Ollama (Local)

FieldValue
API Keyollama (any value works, not checked)
Base URLhttp://localhost:11434/v1 

Configuration Example for Groq

FieldValue
API KeyYour Groq API key (starts with gsk_...)
Base URLhttps://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 

FeatureDetails
ModelsGPT-5, GPT-5 Mini, GPT-5 Nano, O3 series
File processingPDF, images (multiple files)
ReasoningAdjust effort (minimal/low/medium/high)
AI Agent ToolWorks as tool with AI Agent nodes

Installation:

  1. Settings → Community Nodes
  2. Search n8n-nodes-openai-gpt5
  3. Click Install
  4. Restart n8n 

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.) 

FeatureDetails
Chat completions/v1/chat/completions
Text completions/v1/completions
Flexible base URLAny OpenAI-compatible endpoint

Installation: Search n8n-nodes-openai-compatible-node in Community Nodes.

n8n-nodes-mtls-openai

Best for: Enterprise environments with mTLS authentication 

FeatureDetails
mTLS supportx509 client certificate authentication
Chat modelFor AI Agent nodes
EmbeddingsFor 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

ActionWhy
Share API key publiclyAnyone can use it and bill your account
Commit API key to GitHubBots scan for exposed keys
Hardcode API key in workflowsUse credentials system instead
Use root/admin API key for testingCreate limited-permission keys

DO

ActionWhy
Use n8n’s credential systemEncrypted storage
Create separate API keys per workflowEasy to revoke if compromised
Set usage limits in OpenAI dashboardPrevent unexpected bills
Rotate keys periodicallySecurity best practice
Use environment variables (self-hosted)Keep keys out of config files

Setting Usage Limits in OpenAI

  1. Go to platform.openai.com → Settings → Limits
  2. Set monthly usage limits (10,10,50, $100, etc.)
  3. Set notification thresholds
  4. 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,add0.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?

  1. Immediately delete the key from OpenAI dashboard (API Keys page)
  2. Create a new key
  3. Update the credential in n8n
  4. Check OpenAI usage dashboard for unauthorized activity

The Bottom Line

Adding your OpenAI API key to n8n is a simple 5-minute process:

StepWhat to Do
1Get API key from platform.openai.com
2Go to n8n Credentials section
3Add “OpenAI” credential
4Paste API key and save
5Test 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

  1. Get your OpenAI API key (5 minutes)
  2. Add $5-10 credits to your OpenAI account (2 minutes)
  3. Open your n8n instance (1 minute)
  4. Add the OpenAI credential following this guide (3 minutes)
  5. Create a test workflow with an OpenAI node (2 minutes)
  6. Run a simple test — prompt: “Say hello!” (1 minute)

Total time: ~15 minutes to fully set up and test.

Explore More on Coggnix.io

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

Recent Articles

spot_img

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox