How to Connect OpenAI to N8N Step By Step Guide

Connecting OpenAI to n8n takes under 5 minutes and requires only your OpenAI API key. Step 1: Go to platform.openai.com/api-keys, sign in, and click “Create new secret key” — copy the key immediately (it won’t be shown again). Step 2: In n8n, navigate to Credentials → + Add Credential, search for “OpenAI API,” and paste your key Step 3: Select your preferred model (GPT-4o-mini is most cost-effective for testing; GPT-4o for higher quality) Step 4: Add an OpenAI node to your workflow, select your credential, choose an operation (Chat Completion, Text Completion, or Assistant), and configure parameters like temperature (0.2 for factual, 0.8 for creative). Step 5: Test the connection by executing the node — you should receive an AI-generated response. For AI Agent workflows, set the OpenAI Chat Model node as the language model and reference it in the AI Agent node . For advanced features like GPT-5, you can install the n8n-nodes-openai-gpt5 community node .

1. Prerequisites: What You Need Before Starting {#prerequisites}

Before connecting OpenAI to n8n, ensure you have:

RequirementDetails
n8n instanceSelf-hosted (Docker/npm) or n8n.cloud account
OpenAI accountSign up at platform.openai.com
OpenAI API keyStarts with sk-proj-...
API creditsMinimum $5 recommended for testing
Admin accessPermission to add credentials in n8n

*”Before importing this workflow, make sure you have: n8n Instance (cloud or self-hosted), OpenAI API Key (with GPT-4 Vision access)”* 

2. Step 1: Get Your OpenAI API Key {#get-api-key}

Creating Your API Key

StepAction
1Go to platform.openai.com/api-keys
2Sign in or create an account
3Click “+ Create new secret key”
4Name your key (e.g., “n8n-automation”)
5Select permissions (default is fine)
6Click “Create secret key”
7COPY THE KEY IMMEDIATELY — you won’t see it again

API Key Format

Your OpenAI API key will look like this:

text

sk-proj-abc123def456ghi789jkl012mno345pqr678stu...

Add Credits to Your Account

StepAction
1Go to Settings → Billing
2Click “Add to credit balance”
3Add minimum $5 (recommended for testing)

“You can get your OpenAI API key from platform.openai.com. Create a new API key, copy it, and add it to the OpenAI Chat Model node credentials” 

Optional: Get Organization ID

If you belong to multiple organizations in OpenAI:

  1. Go to platform.openai.com → Settings → Organization
  2. Copy your Organization ID (starts with org-...)
  3. You’ll need this if using the GPT-5 community node 

3. Step 2: Configure OpenAI Credentials in n8n {#configure-credentials}

Now add your OpenAI API key to n8n.

For Standard OpenAI API (Most Common)

StepAction
1Open your n8n instance
2Click Credentials in the left sidebar
3Click “+ Add Credential”
4Search for “OpenAI API”
5Paste your API key into the API Key field
6(Optional) Add Organization ID if applicable
7Click Save

“In n8n, go to Credentials → Create New. Select ‘OpenAI API’ and enter your OpenAI API Key” 

“Configure the OpenAI Chat Model node: Create a new OpenAI credential in n8n and store your API key securely” 

For HTTP Header Auth (Alternative Method)

Some workflows use HTTP Header Authentication instead of the native node :

StepAction
1Go to Credentials → New
2Select HTTP Header Auth
3Header name: Authorization
4Value: Bearer YOUR-OPENAI-API-KEY
5Name it (e.g., openAIApiHeader)
6Click Save

“Go to Credentials → New → HTTP Header Auth. Header name: Authorization. Value: Bearer YOUR-OPENAI-API-KEY” 

4. Step 3: Add and Configure OpenAI Node {#add-openai-node}

Adding the Node

StepAction
1Create a new workflow or open an existing one
2Click “+” to add a node
3Search for “OpenAI”
4Select the OpenAI node
5Connect it to your trigger node (Webhook, Schedule, Manual)

Configuring the Node

SettingRecommendationNotes
CredentialSelect the OpenAI credential you created
OperationChat Completion (most common)Also: Text Completion, Assistant
Modelgpt-4o-mini (testing) / gpt-4o (production)Most cost-effective is gpt-4o-mini 
MessagesAdd system + user messagesSystem defines AI behavior
Temperature0.2-0.5 (factual) / 0.7-1.0 (creative)Lower = more consistent 
Max Tokens500-2000 depending on use case

*”Choose a model that matches your performance and cost requirements. Common choices include gpt-4o-mini for cost-efficient, responsive interactions or gpt-4/gpt-4o for higher quality responses”* 

Example Configuration for Chat Completion

json

{
  "model": "gpt-4o-mini",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant for customer support. Keep responses concise and friendly."
    },
    {
      "role": "user",
      "content": "{{ $json.message }}"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 500
}

System Prompt Best Practices

DoDon’t
Be specific about roleUse vague instructions
Set response length expectationsLeave open-ended
Define tone and styleMix contradictory instructions
Add guardrails for out-of-scope queriesSkip error handling

5. Step 4: Test Your Connection {#test-connection}

Method 1: Execute Node

StepAction
1Click “Execute Node” (play button) on the OpenAI node
2If using Chat Trigger, send a test message
3Wait for response (typically 2-5 seconds)
4Check the output in the Execution Data panel

Expected Successful Output

json

{
  "messages": [
    {
      "role": "assistant",
      "content": "Hello! How can I help you today?"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 10,
    "total_tokens": 35
  }
}

Troubleshooting Test Failures

ErrorLikely CauseSolution
Invalid API KeyKey is incorrect or has spacesRegenerate key, paste carefully
Insufficient QuotaNo credits in OpenAI accountAdd credits via Billing
401 UnauthorizedAPI key invalid or expiredCheck key, create new one
429 Rate LimitToo many requestsWait or upgrade tier
Connection timeoutNetwork issueCheck n8n internet access

6. Using OpenAI with AI Agent Workflows {#ai-agent-workflows}

n8n’s AI Agent nodes create more powerful automations by adding memory and tool-use capabilities to OpenAI .

How to Connect OpenAI to N8N Step By Step Guide

Architecture Overview

The AI Agent workflow connects these components :

ComponentRole
Chat Trigger / WebhookReceives user messages
AI Agent NodeOrchestrates memory, model, and tools
OpenAI Chat ModelGenerates responses
Simple MemoryStores conversational context
Tools (e.g., SerpAPI)External actions like web search

“The AI Agent node sits at the center of the workflow. It uses the OpenAI Chat Model for reasoning and response generation, consults Simple Memory for contextual continuity, and selectively invokes SerpAPI when a query requires fresh, external data” 

Step-by-Step: Building an AI Agent

Step 1: Add AI Agent Node

SettingValue
NodeAI Agent
Credential(none – uses connected nodes)
System InstructionsDefine the agent’s role and behavior

Step 2: Add OpenAI Chat Model Node

SettingValue
CredentialYour OpenAI credential
Modelgpt-4o-mini or gpt-4o

Step 3: Connect Nodes

text

Chat Trigger → AI Agent → OpenAI Chat Model
                      ↓
                 Simple Memory
                      ↓
                  [Tool Nodes]

“Within the AI Agent node, link all components: Set the Chat Model node as the agent’s language model. Specify the Simple Memory node as the memory store. Register tool nodes (e.g., SerpAPI) for external actions” 

Step 4: Configure Simple Memory

SettingRecommendation
Memory window size5-10 conversation turns
StorageWhat fields to retain
Session IDUser identifier for context

Step 5: Add System Instructions

text

You are a helpful customer support assistant for [Company Name]. 
You have access to web search for current information. 
Be concise, friendly, and accurate. 
If you don't know something, say so rather than guessing.

Example: AI Agent with Web Search

This workflow connects OpenAI Chat Model, Simple Memory, and SerpAPI for live web search .

“The AI Agent node is responsible for receiving the user message from the trigger, calling the configured OpenAI Chat Model, reading from and writing to the Simple Memory node, and invoking SerpAPI as a tool when a web search is appropriate” 

7. Advanced: GPT-5 Model Support via Community Node {#gpt5-community-node}

For access to OpenAI’s latest GPT-5 models, install the n8n-nodes-openai-gpt5 community node .

Key Features of GPT-5 Node

FeatureDetails
Models supportedGPT-5, GPT-5 Mini, GPT-5 Nano, O3, O3 Pro, O3 Mini
PDF ProcessingUpload and process PDF files directly
Reasoning ControlFine-tune reasoning effort (minimal, low, medium, high)
Verbosity ControlAdjust output length (low, medium, high)
AI Agent Tool SupportUse as a tool with n8n AI Agent nodes
Multiple File SupportProcess multiple PDFs/images in one request

*”This is an n8n community node that provides access to OpenAI’s GPT-5 models and advanced features through the Responses API. Supports PDF processing, multiple file inputs, and all the latest GPT-5 capabilities”* 

Installation Steps

StepAction
1In n8n, go to Settings → Community Nodes
2Search for n8n-nodes-openai-gpt5
3Click Install
4Restart n8n if prompted

Alternative Manual Installation:

bash

npm install n8n-nodes-openai-gpt5
# Then restart n8n instance

Configuring GPT-5 Credentials

StepAction
1Go to Credentials → + Add Credential
2Search for “OpenAI GPT-5 API”
3Enter your OpenAI API key
4(Optional) Add Organization ID
5Click Save

Enable AI Agent Tool Mode

If using as an AI Agent tool, set this environment variable:

bash

N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true

*”This node can be used as a tool with n8n’s AI Agent nodes, allowing AI agents to leverage GPT-5’s advanced reasoning capabilities”* 

8. Advanced: OpenAI-Compatible APIs (Custom Base URL) {#openai-compatible}

You can connect n8n to any OpenAI-compatible API service (like Qwen, local LLMs, or proxies) using custom credentials .

Installing the OpenAI-Compatible Node

StepAction
1Go to Settings → Community Nodes
2Search for n8n-nodes-openai-compatible-node
3Click Install

Configuring Custom Credentials

FieldValue
Base URLYour API endpoint (e.g., https://your-service.com/v1)
API KeyYour service’s API key

“This node allows you to interact with any OpenAI-compatible API service. Configure Base URL (e.g., https://api.openai.comhttps://your-service.com) and API Key” 

Supported Operations

OperationUse Case
Chat CompletionConversational AI responses
Text CompletionGeneral text generation

9. Common Use Cases & Workflow Examples {#use-cases}

Use Case 1: AI Email Generator with Tone Selection

Generate professional emails with custom tones .

Components:

  • Webhook/Form trigger
  • OpenAI Chat Model node
  • Response node

“Setup: Get OpenAI API key, add it to the OpenAI Chat Model node credentials. Customize tones, adjust AI settings (model, temperature, max tokens)” 

Use Case 2: Personalized Job Application Assistant

Telegram + OpenAI + Gmail workflow .

Components:

  • Telegram Bot trigger
  • OpenAI node (with file upload)
  • Gmail node

*”Prerequisites: n8n instance, Telegram Bot Token, OpenAI API Key (with GPT-4 Vision access), Gmail Account”* 

Use Case 3: Document Summarizer with OpenAI Assistants API

Generate summaries from uploaded files .

Components:

  • HTTP Request node (to OpenAI)
  • File upload node
  • OpenAI Assistant node

“This workflow automates the creation and management of a custom OpenAI Assistant. Requires OpenAI API key and Assistant ID (starts with asst_)” 

Use Case 4: Travel Agency Assistant with Google Drive

Custom OpenAI Assistant using Google Drive for document storage .

Components:

  • Google Drive node (download document)
  • OpenAI node (create assistant, upload file)
  • Chat Trigger node
  • Window Buffer Memory

“This workflow automates the creation and management of a custom OpenAI Assistant, leveraging Google Drive for document storage. Uses Window Buffer Memory to retain chat context” 

Use Case 5: AI Agent with Memory and Web Search

Production-ready workflow with OpenAI + SerpAPI + Memory .

Components:

  • Chat trigger / webhook
  • AI Agent node
  • OpenAI Chat Model
  • Simple Memory
  • SerpAPI

*”Automate intelligent, context-aware conversations and real-time search. Connects n8n AI Agent to OpenAI Chat Model, SerpAPI for web search, and Simple Memory for conversational context”* 

10. Troubleshooting Common Issues {#troubleshooting}

Issue 1: “Invalid API Key”

CauseSolution
Extra spaces in keyRe-paste carefully
Wrong key copiedGenerate new key
Key deleted/revokedCheck OpenAI API Keys page

Issue 2: “Insufficient Quota”

CauseSolution
No credits in accountAdd credits in Billing
Free trial expiredAdd payment method

Issue 3: AI Agent Not Using Tools

CauseSolution
Tool not registered in agent configRegister node as tool in AI Agent
System instructions don’t mention toolsAdd: “You have access to web search”
Incorrect tool configurationVerify node connections

Issue 4: Memory Not Retaining Context

CauseSolution
Memory node not connectedConnect to AI Agent
Window size too smallIncrease memory window
Session ID not setConfigure session identifier

Issue 5: Slow Response Times

CauseSolution
Using GPT-4 (slower)Switch to GPT-4o-mini
High temperature settingsLower temperature for faster
Large context windowReduce conversation history

Issue 6: OpenAI Assistants API Issues

For OpenAI Assistants API workflows, ensure :

  • Assistant ID is correctly entered (starts with asst_)
  • File Search and Code Interpreter are enabled
  • Credential uses Header Auth: Bearer YOUR-API-KEY

11. Comparison Table: OpenAI Models in n8n {#comparison-table}

ModelBest ForSpeedCostContext Window
GPT-4o-miniCost-efficient, fast responsesFastestLowest128K
GPT-4oHigh quality, complex reasoningMediumMedium128K
GPT-5Latest capabilities, advanced reasoningSlowerHigher1M
GPT-5 MiniBalanced cost/qualityFastMedium1M
GPT-5 NanoMost cost-efficientFastestLowest1M
O3 SeriesAdvanced reasoning tasksSlowHighest200K

*”Choose a model that matches your performance and cost requirements. Common choices include gpt-4o-mini for cost-efficient, responsive interactions or gpt-4/gpt-4o for higher quality”* 

12. Frequently Asked Questions : How to Connect OpenAI to N8N Step By Step Guide

How do I get an OpenAI API key for n8n?

Go to platform.openai.com/api-keys, sign in, click “Create new secret key,” name it, and copy the key immediately — it won’t be shown again .

Where do I add the OpenAI API key in n8n?

Go to Credentials → + Add Credential → Search “OpenAI API” → Paste your API key → Save .

What’s the difference between OpenAI node and OpenAI Chat Model node?

The OpenAI node is for direct API calls (Chat Completion, Text Completion, Assistant). The OpenAI Chat Model node is specifically designed to work with AI Agent nodes and includes memory integration .

How do I use GPT-5 in n8n?

Install the community node n8n-nodes-openai-gpt5 from Settings → Community Nodes. Then create credentials and add the GPT-5 node to your workflow .

Can I use n8n with OpenAI Assistants API?

Yes. You need an Assistant ID (starts with asst_), enable File Search and Code Interpreter, and use HTTP Header Auth credentials (Bearer YOUR-API-KEY.

How do I add memory to OpenAI conversations in n8n?

Use the AI Agent node with Simple Memory node. Configure memory window size and connect it to the AI Agent — it will automatically retain conversation context .

What’s the best OpenAI model for n8n workflows?

For most use cases, gpt-4o-mini offers the best balance of speed, cost, and quality. Use gpt-4o for higher quality when needed. Use GPT-5 series for advanced reasoning or PDF processing .

How do I test if my OpenAI connection is working?

Add an OpenAI node to a workflow, select your credential, add a simple user message like “Say hello,” and click “Execute Node.” You should receive an AI-generated response.

Can I connect n8n to non-OpenAI APIs?

Yes. Install the n8n-nodes-openai-compatible-node community node and configure a custom Base URL and API key for any OpenAI-compatible service .

How much does it cost to use OpenAI with n8n?

OpenAI API costs are pay-per-token. GPT-4o-mini is approximately $0.15 per million input tokens and $0.60 per million output tokens. The first $5-10 in credits is usually enough for extensive testing .

The Bottom Line

Your NeedRecommended Configuration
Basic API callsOpenAI node with GPT-4o-mini
Conversational AI with memoryAI Agent + OpenAI Chat Model + Simple Memory
PDF/document processingGPT-5 community node 
Web search integrationAI Agent + OpenAI + SerpAPI 
Custom API endpointOpenAI-Compatible node + custom Base URL 

The most important takeaway: Getting started takes under 5 minutes — just get your API key from OpenAI, paste it into n8n credentials, and add an OpenAI node to your workflow. For more sophisticated automations, use the AI Agent node with memory and tools .

Action Steps for Today

  1. Get your OpenAI API key (5 minutes at platform.openai.com)
  2. Add $5-10 in credits to your OpenAI account (2 minutes)
  3. Open n8n and add OpenAI credential (2 minutes)
  4. Create a test workflow with OpenAI node (3 minutes)
  5. Execute and verify you receive a response (1 minute)

Total time to first working AI automation: Under 15 minutes

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