OpenAI Node Authorization is not working

OpenAI Authorization is not working!!

Describe the problem/error/question

When I connect to Openai node from the self hosted n8n, it is unable to authorize.

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 2.23.4
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Debian

Hi @shivakrishna.karnati

If you just send a message, does it work?
You may ignore it if it can work

Welcome @shivakrishna.karnati! Since your credential test passes (“Connection tested successfully”), the issue is likely in the node itself, not the API key. What error message shows when you actually run the node? The most common cause here is model access - for example if you’re using gpt-4o or gpt-4 but your OpenAI account is on a free tier that doesn’t have access to those models yet. Try switching to gpt-3.5-turbo in the node config as a quick test to confirm.

No, it’s not working when I send the message.

I have attached the screenshot above which shows the output error after running the node :slight_smile:

@shivakrishna.karnati can you paste the exact error text from the screenshot? The message “not working when I send” tells us it’s failing at execution, not auth - so the error content is key. Look for a red banner or the output panel on the right side of the node. It should show something like “401 Unauthorized”, “insufficient_quota”, or “model_not_found”. That exact wording will point us to the root cause.

Hello @nguyenthieutoan ,

here is the required info.

**
Authorization failed - please check your credentials**

401 status code (no body) Troubleshooting URL: MODEL_AUTHENTICATION - Docs by LangChain

Error details

From AI Agent

Full message

401 status code (no body) Troubleshooting URL: https://docs.langchain.com/oss/javascript/langchain/errors/MODEL_AUTHENTICATION/
Other info

Node type

@n8n/n8n-nodes-langchain.agent

Node version

3.1 (Latest)

n8n version

2.27.4 (Self Hosted)

Time

26.6.2026, 07:47:13

Stack trace

NodeOperationError: Authorization failed - please check your credentials at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_b494726bf990c8f5fe0c4c40e025f969/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts:118:11 at Array.forEach (<anonymous>) at executeBatch (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_b494726bf990c8f5fe0c4c40e025f969/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts:107:15) at processTicksAndRejections (node:internal/process/task_queues:104:5) at ExecuteContext.toolsAgentExecute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_b494726bf990c8f5fe0c4c40e025f969/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/execute.ts:93:8) at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_b494726bf990c8f5fe0c4c40e025f969/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/V3/AgentV3.node.ts:155:10) at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_cf5896492347c4895f0373f4acc773d7/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1067:8) at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_cf5896492347c4895f0373f4acc773d7/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1367:11) at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_cf5896492347c4895f0373f4acc773d7/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1829:27 at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_cf5896492347c4895f0373f4acc773d7/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2521:11

Problem in node ‘AI Agent1‘

Authorization failed - please check your credentials

A “401 no body” from the AI Agent points directly at the credential, not the model. The API key is being rejected before OpenAI even processes the request.

Three things to check:

  1. Open the OpenAI credential in n8n, delete the key, paste it fresh (no leading/trailing spaces), and click “Save & Test” - confirm it shows a green checkmark.
  2. Go to platform.openai.com → API Keys and verify the key is still active and hasn’t been revoked.
  3. Make sure the credential attached to the OpenAI Chat Model node inside your AI Agent sub-node is the same one you just tested - sometimes a different credential gets selected.

If the credential test passes but the agent still fails, open the “From AI Agent” error detail and share what’s inside - that will show which sub-call is failing.

Hello @nguyenthieutoan , Thank you for your reply. The API Key provider is not directly OpenAI, rather a 3rd party vendor who exposes OpenAI Compatible API for Chat completions. The same endpoint URL along with the API Key is successfully running on OpenWebUI application.

@shivakrishna.karnati
Please check for the following:

1)When using 3rd party OpenAI-compatible providers, the Base URL field is extremely sensitive.

  • The Mistake: Many users paste the full endpoint, e.g., https://api.provider.com/v1/chat/completions.
  • The Correct Way: The Base URL should only go up to the version prefix. It should typically be https://api.provider.com/v1.

2)To determine if the problem is with the n8n OpenAI Node or your Credentials/URL​, perform this test:

  1. Add an HTTP Request node to your workflow.
  2. Set Method to POST.
  3. Set URL to the full endpoint (e.g., https://api.provider.com/v1/chat/completions).
  4. Under Authentication​, select Header Auth.
  5. Create new credentials:
    • Name: Authorization
    • Value: Bearer YOUR_API_KEY_HERE
  6. In the Body Parameters​, send a simple JSON: {"model": "openai/gpt-oss-120b", "messages": [{"role": "user", "content": "hi"}]}.
  • If this works: The issue is how the n8n OpenAI node is constructing the request (likely the Base URL issue mentioned in Step 1).
  • If this fails with 401: The issue is definitely your API Key or the provider’s requirement for a specific header (some providers require api-key instead of Authorization: Bearer).

3)Some providers are strict about trailing slashes. If https://api.provider.com/v1 fails, try https://api.provider.com/v1/ (with a slash) or vice versa.

4)In your JSON, the model is set to openai/gpt-oss-120b. Ensure this string is exactly what the provider expects. Even a small typo or an extra space will cause some providers to return an authorization/not found error.

Hello @kjooleng ,

Thank you for your reply! Yes, it’s working when I checked with the HTTP Request Node.

I changed the URL from v1 to https://api_endpoint_url/v1/chat/completions

Do you think OpenAI Node is not sending v1/chat/completions while running the node?

What did you do for step 1?

In the Step 1: I tried URL with https://api.provider.com/v1 and it is able to authenticate when I add the credentials but giving 401 Error when I send the request.

and also with https://api.provider.com/v1/chat/completions, it is unable to authenticate when I add the API Key.

vs

So which is which? Your reply is confusing. Is it working, or not working?

This is step 2:

Okay, when I checked with HTTP Request Node with https://api_endpoint_url/v1/chat/completions as URL it was working (Chat completion is being done).

But when I try the same in OpenAI Node with the endpoint URL (https://api_endpoint_url/v1/chat/completions) or the endpoint URL (https://api_endpoint_url/v1), it’snot working.

I asked/am asking if the problem persists in the OpenAI Node or the 3rd party vendor endpoint.

To confirm if the problem is the OpenAI Node’s internal logic:

  1. Check the Execution Log: Open the execution of the failed OpenAI Node. Look at the “Request” tab (if available in your version) or the error message. If the error is a 404, it is almost certainly a URL construction issue (the wrong path is being called).
  2. Try the Base URL without /v1: Some vendors expect the Base URL to be just https://api_endpoint_url. The node then adds /v1/chat/completions automatically.
  3. Compare the JSON Payloads: Compare the “Body” of the request sent by the HTTP Request Node (which worked) with the “Body” sent by the OpenAI Node. Even a small difference in how the messages array is structured can cause a 3rd party vendor to reject the request.
  1. There is no Request tab, and below is the strack trace error details.

    NodeApiError: Authorization failed - please check your credentials
        at ExecuteContext.requestWithAuthentication (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_cf5896492347c4895f0373f4acc773d7/node_modules/n8n-core/src/execution-engine/node-execution-context/utils/request-helpers/authentication.ts:263:10)
        at processTicksAndRejections (node:internal/process/task_queues:104:5)
        at ExecuteContext.requestWithAuthentication (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_cf5896492347c4895f0373f4acc773d7/node_modules/n8n-core/src/execution-engine/node-execution-context/utils/request-helpers/factory.ts:176:11)
        at ExecuteContext.apiRequest (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_b494726bf990c8f5fe0c4c40e025f969/node_modules/@n8n/n8n-nodes-langchain/nodes/vendors/OpenAi/transport/index.ts:56:19)
        at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_b494726bf990c8f5fe0c4c40e025f969/node_modules/@n8n/n8n-nodes-langchain/nodes/vendors/OpenAi/v2/actions/text/response.operation.ts:621:18)
        at ExecuteContext.router (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_b494726bf990c8f5fe0c4c40e025f969/node_modules/@n8n/n8n-nodes-langchain/nodes/vendors/OpenAi/v2/actions/router.ts:58:25)
        at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_b494726bf990c8f5fe0c4c40e025f969/node_modules/@n8n/n8n-nodes-langchain/nodes/vendors/OpenAi/v2/OpenAiV2.node.ts:93:10)
        at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_cf5896492347c4895f0373f4acc773d7/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1067:8)
        at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_cf5896492347c4895f0373f4acc773d7/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1367:11)
        at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_cf5896492347c4895f0373f4acc773d7/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1829:27
    
  2. Without /v1 it is unable to authenticate the API Key.

Can you try these?

Option A: Ignore the “Couldn’t connect” warning (The “Just Try It” method) If you are sure your API key is correct:

  1. Set the Base URL to https://openai.inference.de-txl.ionos.com (without /v1).
  2. Ignore the red “Couldn’t connect” warning in the credentials screen and click Save anyway.
  3. Go to your workflow, add the OpenAI node, and try to run a “Chat” operation. If the vendor doesn’t support the /models endpoint, the credential test fails, but the actual chat request might still work.

Option B: Use the HTTP Request Node (The “Stable” method) If Option A fails, it means the vendor requires a header format that the OpenAI node cannot provide. In this case, the HTTP Request node is actually your best tool​.

To make the HTTP node feel like an AI node, you can:

  1. Create a Sub-workflow that takes a prompt as input and returns the AI response via the HTTP Request node.
  2. Call this sub-workflow whenever you need an AI completion.

Option A: it is not working

Option B: It is working!!

Thank you!

You are welcome