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.