Authorization failed - please check your credentials Missing bearer or basic authentication in header

My OpenAI Nodes is not working any more

Authorization failed - please check your credentials
Missing bearer or basic authentication in header

In Credentials the OpenAI API Key is valid and test is “green”.

What’s going on? n8n Version

1.123.20

@holgerdeha

which exact node is throwing this error? (like the regular OpenAI node, the AI Chat Model, or an HTTP Request node?) knowing that will help narrow down the fix.

it’s the regular OpenAI Node

Hi @holgerdeha Most probably this issue is because your n8n instance is too old, consider updating your n8n instance to the latest stable version and your issue would be resolved!

I’m at the latest 1.x Version according to the release notes.

For testing: i created a new workflow with the same credentials and tried to select a model from the list. I get this error:

Could not load list

401 - Authorization failed

Missing bearer authentication in header

Check your credential

If i click on “Check your credentials”, the Credentials open and i can see this:

Connection tested successfully
—-
Transition to 2.x is not easily possible at the moment due to read/write issues in the /data volume.

I mean the 2.x version of n8n:

It has a lot of issues fixed related to auth.

check these inside your openai credential settings:

1. if you are using a custom api base url, check the very end of it. make sure it does not end with a slash (like .../v1/). delete it if it’s there.

2. the organization id field: make sure this box is completely empty. sometimes invisible spaces or the gray placeholder text gets accidentally saved in there.

after checking both, go back into your openai node and manually re-select the credential from the dropdown to force it to refresh.

The credentials test passing but the node itself failing is a weird one, usually that points to something in the credential config being off. The custom API base URL ending with a slash is actually a common gotcha, same with invisible characters in the organization ID field. Worth double-checking both of those even if they look empty at first glance. If that doesn’t do it, try creating a completely fresh credential with a brand new API key from OpenAI’s dashboard rather than reusing the same key, sometimes keys get into a weird state on OpenAI’s end.

this didn’t work

  1. i didn’t use this
  2. i didn’t have the organzition filed

So this didn’t work either.

both things didn’t work

You should consider updating n8n to the latest stable version.

i updated to n8n@1.123.25
this is the latest stable 1.x version. Problem still occurs.

Same error with 2.11.4. stable 2.x version

Sorry, but this makes n8n unusable

Hey @holgerdeha

The volume read/write issue you mentioned is likely the root cause. if n8n can’t reliably read its /data directory at runtime, credentials fail to decrypt during node execution even though the test passes.

Fix the permissions first then restart the container after, then retry.

Permission problem is not the reason. I’d referred not to the “data” folder of n8n itself but to a external “data” volume where i’d like to store output data (like csv-files) or read data from.

Every other credentials are working fine. I can also use HTTP Node to query OpenAI API with the same bearer token. And LLM Chain Node or AI Agent node with the same open AI Credentials working fine, too. The OpenAI node has a Bug. That’s a fact.

I don’t know, if pasting my test workflow above had worked. “Message a model”: Error 401. Basic LLM Chain with same credentials: Works fine.

@holgerdeha , did you try adding this environment variable to your n8n container and restart? :

N8N_USE_PERSISTENT_OPENAI_API_KEY=true

It was not set. I set this in my env-file and restarted.
i checked that it’s set inside the container:

docker inspect n8n-n8n-1 --format=‘{{range .Config.Env}}{{println .}}{{end}}’ | grep OPENAI

N8N_USE_PERSISTENT_OPENAI_API_KEY=true

Unfortunately it doesn’t help. I still get 401 in the openAI node.