How to configure OpenAI integration on n8n
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
Step-by-Step Instructions
Obtain OpenAI API Key
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.Access n8n Credentials
http://localhost:5678, or desktop app), log in to the main dashboard, and click Credentials in the left sidebar.Add New OpenAI Credential
Enter API Key and Options
https://api.openai.com/v1 for proxies). Name it (e.g., 'My OpenAI Key') and leave defaults unless needed.Test and Save Credential
Create or Open Workflow
Add OpenAI Node
Configure Node Parameters
[{ "role": "user", "content": "Hello" }]. Adjust Model, Temperature, Max Tokens. Toggle Simplify Output for clean JSON.Test OpenAI Node
Common Issues & 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 <code>OPENAI_API_KEY</code> or n8n's credentials manager; avoid hardcoding in workflows.
Connection test fails due to network/proxy
Set custom <code>Base URL</code> in credential for proxies; check firewall and ensure n8n can reach <code>api.openai.com</code>.
Node execution errors with models
Use allowed models like <code>gpt-4o-mini</code> for basic accounts; check OpenAI billing and quotas.