n n8n

How to configure OpenAI integration on n8n

beginner 8 min read Updated 2026-03-13
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

Step-by-Step Instructions

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.
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.
For self-hosted: Use <code>npm install n8n -g</code> or Docker <code>docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n</code>.
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.
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.
Defaults: Model <code>gpt-4o-mini</code> or <code>gpt-3.5-turbo</code>, 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.
Verify workflow by manual trigger or webhook.

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.