Beginner
How to configure an OpenAI integration on n8n
Quick Answer
Obtain an OpenAI API key, create credentials in n8n's Credentials section, test the connection, and select the credential in OpenAI nodes for workflows. Setup takes 5-10 minutes; common issues like invalid keys or missing org IDs are fixed by regenerating keys and re-testing. Use native OpenAI nodes for chat, embeddings, or images with defaults like gpt-4o-mini.
Prerequisites
- Active OpenAI account with billing enabled
- n8n instance (cloud, self-hosted, or desktop app)
- OpenAI API key from platform.openai.com
- Optional: OpenAI Organization ID
1
Obtain OpenAI API Key
Log into your OpenAI account at
platform.openai.com, go to the API Keys section in the dashboard sidebar, click Create new secret key, name it (e.g., 'n8n-prod'), and copy the key immediately as it won't be viewable again. Optionally note your Organization ID from settings if using multiple orgs.Tip
Enable billing on OpenAI for API usage, as it's paid.
2
Access n8n Credentials
Open your n8n instance (cloud at app.n8n.cloud, self-hosted at
http://localhost:5678, or desktop app), log in to the main dashboard, and click Credentials in the left sidebar.Tip
For self-hosted: Use
npm install n8n -g or Docker docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n.3
Add New OpenAI Credential
On the Credentials page, click Add Credential or Create New, search for OpenAI, and select the OpenAI credential type.
4
Enter API Key and Options
Paste your OpenAI API key into the API Key field (labeled 'Secret API Key'). Optionally add Organization ID from OpenAI settings or set custom Base URL (default:
https://api.openai.com/v1 for proxies). Name it (e.g., 'My OpenAI Key') and leave defaults unless needed.Tip
Avoid extra spaces in the key; no Base URL override for standard use.
5
Test and Save Credential
Click Test Connection or Verify—n8n pings OpenAI (green check on success). Fix key/network issues if failed, then click Save to store securely.
6
Create or Open Workflow
Go to Workflows section, create a new workflow or open existing one.
7
Add OpenAI Node
Click + to add a node, search OpenAI, select operation like Chat or Chat Model. In node settings (right panel), choose your saved credential from Credential to connect with dropdown.
Tip
Defaults: Model
gpt-4o-mini or gpt-3.5-turbo, Temperature 1.0, Max Tokens 4096.8
Configure Node Parameters
Set Messages as array:
[{ "role": "user", "content": "Hello" }]. Adjust Model, Temperature, Max Tokens. Toggle Simplify Output for clean JSON.9
Test OpenAI Node
Click Execute Node with sample input. Check Output tab for results.
Tip
Verify workflow by manual trigger or webhook.
Troubleshooting
Invalid or expired API key (401 Unauthorized or Invalid Authentication)
Regenerate new secret key in OpenAI dashboard, paste into n8n credential without extra spaces, re-test connection.
Missing Organization ID (403 Forbidden or Invalid organization)
Copy Org ID from OpenAI settings, enter in n8n credential's Organization ID field (leave blank for single org), save and test.
Self-hosted n8n key exposure or credential fails
Use environment variables like
OPENAI_API_KEY or n8n's credentials manager; avoid hardcoding in workflows.Connection test fails due to network/proxy
Set custom
Base URL in credential for proxies; check firewall and ensure n8n can reach api.openai.com.Node execution errors with models
Use allowed models like
gpt-4o-mini for basic accounts; check OpenAI billing and quotas.Ready to get started with n8n?
Put this tutorial into practice. Visit n8n and follow the steps above.
Visit n8n →