AutomationBeginner

How to Add OpenAI Credentials to n8n

Create an OpenAI API key, store it as a reusable credential in n8n, and verify it with a one-node test before building real AI workflows.

6 minBeginner

Every LLM node in n8n needs a credential to authenticate. Doing this once, properly, means dozens of later nodes just pick the same credential from a dropdown. This guide creates an OpenAI key and wires it into n8n so it is ready to reuse everywhere.

What you need

  • A running n8n instance
  • An OpenAI account with billing enabled (the API is pay as you go, separate from ChatGPT Plus)
  • Two minutes on platform.openai.com

Step 1: Create an API key

Go to platform.openai.com/api-keys, click Create new secret key, name it n8n, and copy the value immediately. OpenAI shows the full key only once, so paste it somewhere temporary before leaving the page.

Use a project-scoped key
Create the key inside a dedicated OpenAI project so you can track spend from n8n separately and revoke just that key if it ever leaks.

Step 2: Open the credentials manager in n8n

In n8n, open the Credentials section from the left sidebar, click Add credential, search for OpenAI, and select the OpenAI API credential type. Paste your secret key into the API Key field.

n8n - New credential
Credential type: OpenAI API
API Key [ sk-proj-************************ ]
Organization [ (optional) ]
Base URL [ https://api.openai.com/v1 ]
[ Save ] Connection: not tested
The OpenAI API credential form before saving.

Step 3: Save and let n8n test the connection

Click Save. n8n calls the OpenAI API in the background and shows a green Connection tested successfully banner if the key works. If it fails, the most common causes are a typo in the key or no billing set up on the account.

Step 4: Verify with a one-node test

Create a new workflow, add an OpenAI node, choose your credential, pick the Message a Model action with gpt-4o-mini, and type a short prompt. Click Test step and confirm a reply comes back.

n8n - OpenAI node test output
You
Prompt: Say hello in five words.
Agent
Hello there, nice to meet.
A successful single-node test confirms the credential works.

Result

You now have a reusable OpenAI credential. Any future OpenAI, AI Agent, or LangChain node in this n8n instance can select it from a dropdown instead of asking for the key again.

Watch related tutorials

Tags
#n8n#openai#credentials#api-key