Adding your OpenAI API key to n8n takes three steps: generate the key in your OpenAI account, create a new credential in n8n, and paste the key into the credential form.
n8n is a workflow automation platform that lets you connect different services together. To use OpenAI's language models inside an n8n workflow, you need to authenticate n8n with your OpenAI account using an API key. The key acts as a password that tells OpenAI that n8n has permission to use your account.
This guide walks through getting that key and entering it into n8n so your workflows can send requests to OpenAI and receive responses.
Key Takeaways
- You must create an API key in your OpenAI account before n8n can connect to it.
- n8n stores API keys as credentials, which you can reuse across multiple workflows.
- The OpenAI credential type in n8n accepts only the API key itself, not your login password.
- Once saved, you can test the connection immediately by adding an OpenAI node to your workflow.
Generate an API key from your OpenAI account
Log into your OpenAI account at platform.openai.com. This is different from ChatGPT.com — you need the platform site where you manage billing and API access.
In the left sidebar, click API keys. On that page, click the button labeled Create new secret key. OpenAI will generate a string of characters that starts with "sk-". Copy this entire string and save it somewhere safe — you will not be able to view it again after you close the page.
If you have already created keys in the past and lost track of them, you can create a new one at any time. Old keys remain active unless you delete them manually, so creating a fresh key does not break existing workflows using the old one.
Open the credentials panel in n8n
In your n8n workspace, click the Credentials button in the left sidebar. This opens a panel showing all the credentials you have already stored.
Click the Create New button (or the plus icon, depending on your n8n version). A dropdown menu appears asking you to choose a credential type.
Scroll down or search for OpenAI in the list. Click it to select it.
Enter your API key into the credential form
n8n opens a form with a single field labeled API Key. Paste the key you copied from your OpenAI account into this field. Do not add any extra spaces or line breaks.
Give the credential a name in the Credential Name field at the top — something like "OpenAI Main" or "My OpenAI Key" helps you remember which account it belongs to if you have multiple keys later.
Click Save. n8n stores the credential and closes the form.
Test the connection by adding an OpenAI node
To confirm the key works, create a new workflow or open an existing one. Click the plus icon to add a node, search for OpenAI, and select the OpenAI node from the list.
In the node settings panel on the right, look for the Credential dropdown. Click it and select the credential you just created. If the dropdown shows your credential name, the connection is working.
You can now configure the node to send a prompt to OpenAI or perform other tasks. The node will use your API key automatically when the workflow runs.
Reusing the same credential across workflows
Once you save a credential, you do not need to enter your API key again. Every OpenAI node you add to any workflow can use the same credential. This saves time and reduces the risk of accidentally pasting the key in the wrong place.
If you need to rotate your API key for security reasons, you can edit the credential by going back to the Credentials panel, finding the OpenAI credential, and updating the key. All workflows using that credential will automatically use the new key the next time they run.
Troubleshooting common problems
If n8n shows an error when you test the connection, check that you copied the entire API key without extra spaces at the beginning or end. Even a single extra character will cause authentication to fail. Also confirm that the key you copied came from platform.openai.com and not from a different service.
If you see a message about billing or account status, log into your OpenAI account and check that you have set up a payment method and that your account is not suspended. Some OpenAI accounts require a paid plan to use the API, even if you have used the free ChatGPT interface.
If the node runs but returns an error about the model or request format, the credential itself is working — the problem is with how you configured the node settings, not with the API key.
Frequently Asked Questions
Can I use my ChatGPT login password as the API key?
No. The API key and your login password are separate. You must generate an API key from the platform.openai.com API keys page. Your ChatGPT password will not work in n8n.
What happens if someone gets my API key?
They can use your OpenAI account and incur charges on your billing account. If you think your key has been compromised, delete it immediately from the API keys page and create a new one. Deleted keys stop working right away.
Do I need a paid OpenAI account to use the API?
OpenAI requires a payment method on file to use the API, even if you only make a few requests. Free trial credits may be available when you first sign up. Check your OpenAI account billing page to see your current plan and usage.
Can I use the same API key in multiple n8n instances?
Yes. A single API key works anywhere you paste it. However, if you run multiple n8n instances, each one stores its own copy of the credential, so you will need to enter the key in each instance separately.
How do I know which OpenAI model to use in the node?
The OpenAI node in n8n shows a dropdown of available models. The list changes as OpenAI releases new models and retires old ones. Select the model that matches what you want to do — GPT-4 for complex reasoning, GPT-3.5-turbo for faster and cheaper responses.