Learn how to fix the “invalid API key” OpenAI error in n8n with simple steps to restore workflow automation and ensure smooth API connections.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
The “invalid API key” error from OpenAI in n8n is almost always caused by a wrong or outdated key in your n8n Credentials, the wrong Authentication method selected, or sending the key in the wrong header when using an HTTP Request node. The fastest fix is: open your OpenAI credential in n8n, paste a fresh API key from platform.openai.com (or the new API Dashboard if your org uses it), make sure the credential type is set to Header Auth with key name Authorization and value format Bearer YOUR\_KEY, save it, and then re-run the workflow.
n8n simply forwards whatever API key you gave it. If the key is wrong, expired, revoked, or formatted incorrectly, OpenAI immediately responds with “invalid API key”. This is not n8n logic failing — it’s OpenAI rejecting the request.
Common root causes:
These steps assume you’re using the real OpenAI integration in n8n or a manual HTTP Request node.
{
"Authorization": "Bearer YOUR_OPENAI_KEY"
}
Make sure your configuration looks like this:
// Method
POST
// URL (example for Chat Completions)
https://api.openai.com/v1/chat/completions
// Auth
None // You handle the header manually
// Headers
Authorization: Bearer {{$credentials.openAIApiKey}}
Content-Type: application/json
// Body (JSON)
{
"model": "gpt-4o",
"messages": [
{ "role": "user", "content": "Hello!" }
]
}
If the “Authorization” header is missing or the Bearer format is wrong, OpenAI rejects it immediately.
If you follow the steps above — fresh key, correct header, correct credentials — the “invalid API key” error disappears 100% of the time in a production n8n environment.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.