Add OpenAI API Key to N8N: Step By Step Guide

If you're looking to integrate the power of OpenAI's ChatGPT into your automations, n8n is a great place to start. But before building your AI-enhanced workflows, you'll need to make sure you authenticate with the OpenAI API correctly. In this beginner-friendly guide, we’ll walk you through exactly how to add OpenAI API key to n8n node so you can start generating AI responses in your custom automations.

Whether you're using GPT-4 for content summaries, intelligent replies, or AI agents, this simple setup will unlock a wide range of automation possibilities.

Why Connect OpenAI to n8n?

Using OpenAI within n8n allows you to automate tasks like:

  • Generating content like emails, summaries, or SEO descriptions
  • Creating AI chat agents for customer service or sales support
  • Analyzing sentiment or summarizing feedback using natural language models
  • Powering personalized automation flows based on user input

With a valid API key from OpenAI, you can bring all this intelligence into n8n using just a few clicks.

Step 1: Get Your OpenAI API Key

To begin, you’ll need an OpenAI account with API access. Follow these steps:

  1. Go to OpenAI platform
  2. Sign up or log in to your account
  3. Navigate to API Keys section from your account dashboard
  4. Click “Create new secret key”
  5. Copy the key and store it in a secure place

Note: Keep your API key private. Anyone with access to it could potentially rack up charges on your behalf.

Step 2: Open n8n and Add OpenAI Credentials

Now let’s head to n8n and securely store the OpenAI API key.

For Self-Hosted n8n:

Follow these steps to add a new credential manually:

  1. Open your n8n dashboard
  2. Click the gear icon ⚙️ in the top-right corner and go to Credentials
  3. Click + New Credential
  4. Search for OpenAI in the list
  5. Choose OpenAI API (not OAuth)
  6. Paste your API key in the required field
  7. Give your credential a name (e.g., “My OpenAI Key”) and click Save

For Cloud or Hosted n8n:

The process is basically the same — just make sure you store the key in the credentials section for security and avoid hardcoding it into workflows.

Step 3: Use the OpenAI Node in Your Workflow

Once the API key is securely stored, you can begin using it in the OpenAI nodes.

Example: Use OpenAI to Summarize Text

Here’s how to build a quick test workflow:

  1. Start with a “Manual Trigger” node

  2. Add a Set node to input custom text

    • Field Name: text
    • Value: “This is a long sentence that you want to shorten using AI.”
  3. Add the OpenAI node and connect it

    • Resource: Completion
    • Operation: Create
    • Model: gpt-3.5-turbo or gpt-4
    • Prompt: Summarize this: {{$json["text"]}}
  4. In the Credentials section, select the OpenAI API credential you created earlier

  5. Run the workflow

That’s it. You’ll receive a summarized response from OpenAI in your output.

You can modify the prompt to change how the AI reacts. Try “Rewrite in a professional tone” or “Translate to French”.

Common Use Cases After Integration

After you've completed the OpenAI API integration, here are some ideas for automation flows you can build:

Use Case Description
Email Assistant Write or proofread emails automatically using GPT
Chatbot Agent Build a chatbot responses using GPT models inside a Telegram or Slack workflow
AI Content Generator Generate SEO meta descriptions or social media captions
AI Planning Agent Use planning agents in n8n to intelligently handle tasks
YouTube Summarizer Automate YouTube video summaries with transcription + GPT

Check out the automated YouTube summary guide for a real implementation combining OpenAI with video workflows.

Tips for Managing API Usage and Costs

OpenAI’s API is powerful, but usage can quickly add up, especially when running GPT-4 models.

Here are some tips to keep things under control:

  • Start with GPT-3.5-Turbo: It’s cheaper and very capable for most tasks.
  • Set a monthly usage limit in your OpenAI account
  • Use concise prompts and limit token output
  • Add optional guards using n8n logic nodes to avoid overuse (e.g., stop if input is empty)

For detailed agent builds and OpenAI prompt tuning, CrewAI vs n8n provides a good comparison on how workflows scale with open-source vs prebuilt agents.

Troubleshooting: Why Isn’t My OpenAI Node Working?

If your OpenAI node throws an error, here are a few things to check:

  • Recheck your API key (sometimes extra spaces are accidentally copied)
  • Confirm your OpenAI account has active billing and no limits
  • Make sure models like gpt-4 are enabled for your account
  • Review the “Prompt” field — ensure it references existing fields correctly ({{$json["text"]}})

Still stuck? You can check our common n8n issues troubleshooting guide for advanced tips.

FAQ

How do I add OpenAI API key to n8n node securely?

You should never hardcode the key into individual nodes. Instead, go to the n8n credentials manager, search for "OpenAI", and store the key securely under a named credential. Then, select that credential when using any OpenAI node.

Can I use GPT-4 with n8n?

Yes, as long as your OpenAI account has access to GPT-4, you can select it in the “Model” dropdown in the OpenAI node. Just keep in mind it’s more expensive and may have usage caps.

What is the difference between OpenAI Completion and Chat operations in n8n?

  • Completion is for traditional prompt/response workflows (e.g., GPT-3).
  • Chat is designed for ChatGPT-style interactions that use messages and roles (e.g., GPT-3.5-Turbo, GPT-4).

Can I use OpenAI inside custom agents in n8n?

Absolutely. You can embed OpenAI calls as part of larger agent workflows in n8n. For example, you can build a conversational agent, coding agent, or voice-based assistant powered by OpenAI.

What should I do if my OpenAI requests are returning errors in n8n?

Check your API key, confirm your account is active, and verify the model name matches what your OpenAI account can access. Also, make sure your input is well-formatted and the prompt field does not contain invalid references.

By setting up your OpenAI API key properly in n8n, you’re opening the door to advanced AI-powered automations with very little code. Let your creativity take over and start experimenting!

Comments
Join the Discussion and Share Your Opinion
Add a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Newsletter
Get The Latest Agent Templates & Guides, Straight To Your Inbox.
Join the #1 AI Automation newsletter.