OpenAI Node 授權無法運作

OpenAI 授權無法運作!!

描述問題/錯誤/問題

當我從自託管 n8n 連接到 Openai 節點時,它無法授權。

錯誤訊息是什麼(如果有的話)?

請分享您的工作流程

分享最後一個節點返回的輸出

關於您的 n8n 設定的資訊

  • n8n 版本: 2.23.4
  • 資料庫(預設: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS 設定(預設: own, main): main
  • 透過以下方式運行 n8n(Docker、npm、n8n cloud、桌面應用程式): Docker
  • 作業系統: Debian

@shivakrishna.karnati

如果你只是發送訊息,它能正常運作嗎?
如果可以運作的話,你可以忽略它

歡迎 @shivakrishna.karnati!既然您的認證測試通過了(「連線測試成功」),那麼問題可能出在節點本身,而不是 API 金鑰。當您實際執行該節點時,會顯示什麼錯誤訊息?最常見的原因是模型存取 - 例如,如果您使用的是 gpt-4ogpt-4,但您的 OpenAI 帳戶是免費層級,還沒有存取這些模型的權限。試著在節點設定中改用 gpt-3.5-turbo 進行快速測試來確認。

不,它不工作,當我發送訊息時。

我已在上方附加了截圖,顯示執行節點後的輸出錯誤 :slight_smile:

@shivakrishna.karnati 你能貼上截圖中的確切錯誤文本嗎?「send 時無法運作」這個訊息告訴我們它在執行時失敗,而不是認證——所以錯誤內容是關鍵。查看紅色橫幅或節點右側的輸出面板。它應該會顯示類似「401 Unauthorized」、「insufficient_quota」或「model_not_found」的內容。那個確切的措詞將指向我們根本原因。

你好 @nguyenthieutoan

以下是所需的資訊。

**
授權失敗 - 請檢查您的認證**

401 狀態碼(無本體)疑難排解 URL:MODEL_AUTHENTICATION - Docs by LangChain

錯誤詳細資訊

來自 AI Agent

完整訊息

401 status code (no body) Troubleshooting URL: https://docs.langchain.com/oss/javascript/langchain/errors/MODEL_AUTHENTICATION/
其他資訊

節點類型

@n8n/n8n-nodes-langchain.agent

節點版本

3.1 (Latest)

n8n 版本

2.27.4 (Self Hosted)

時間

26.6.2026, 07:47:13

堆疊追蹤

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

節點「AI Agent1」中的問題

授權失敗 - 請檢查您的認證

來自 AI Agent 的「401 no body」直接指向認證,而非模型。API 金鑰在 OpenAI 甚至處理請求之前就被拒絕了。

需要檢查三個項目:

  1. 在 n8n 中開啟 OpenAI 認證,刪除金鑰,貼上新的(沒有前後空格),然後點擊「保存並測試」- 確認顯示綠色勾號。
  2. 前往 platform.openai.com → API Keys 並驗證該金鑰仍然有效且未被撤銷。
  3. 確保附加到 AI Agent 子節點內的 OpenAI Chat Model 節點的認證與你剛剛測試的相同 - 有時會選到不同的認證。

如果認證測試通過但代理仍然失敗,請開啟「From AI Agent」錯誤詳情並分享內容 - 這樣會顯示哪個子呼叫失敗。

您好 @nguyenthieutoan,感謝您的回覆。API Key 的提供者不是直接的 OpenAI,而是一家提供 OpenAI 相容 API 供聊天完成使用的第三方廠商。同一個端點 URL 和 API Key 在 OpenWebUI 應用程式上已成功運行。

@shivakrishna.karnati
請檢查以下項目:

1)使用第三方 OpenAI 相容提供商時,Base URL 欄位極其敏感。

  • 常見錯誤: 許多使用者貼上完整的端點,例如 https://api.provider.com/v1/chat/completions
  • 正確做法: Base URL 應該只包含到版本前綴。通常應該是 https://api.provider.com/v1

2)要確定問題出在 n8n OpenAI Node 還是 認證資訊/URL,請執行此測試:

  1. 在工作流程中新增 HTTP Request 節點。
  2. 將 Method 設定為 POST
  3. 將 URL 設定為完整端點(例如 https://api.provider.com/v1/chat/completions)。
  4. Authentication 下,選擇 Header Auth
  5. 建立新認證資訊:
    • Name: Authorization
    • Value: Bearer YOUR_API_KEY_HERE
  6. Body Parameters 中,傳送一個簡單的 JSON:{"model": "openai/gpt-oss-120b", "messages": [{"role": "user", "content": "hi"}]}
  • 如果成功: 問題在於 n8n OpenAI node 如何構造請求(很可能是第 1 步提到的 Base URL 問題)。
  • 如果失敗並顯示 401: 問題肯定是您的 API Key 或提供商要求特定標頭(有些提供商需要 api-key 而不是 Authorization: Bearer)。

3)有些提供商對尾部斜線很敏感。如果 https://api.provider.com/v1 失敗,請嘗試 https://api.provider.com/v1/(帶斜線)或反之亦然。

4)在您的 JSON 中,model 設定為 openai/gpt-oss-120b。確保此字串完全符合提供商的預期。即使是微小的拼寫錯誤或多餘的空格,某些提供商也會傳回授權/找不到錯誤。

您好 @kjooleng

感謝您的回覆!是的,我用 HTTP Request Node 檢查時它能正常運作。

我將 URL 從 v1 改為 https://api_endpoint_url/v1/chat/completions

你認為 OpenAI Node 在執行該節點時沒有發送 v1/chat/completions 嗎?

What did you do for step 1?

在步驟 1 中:我試用了 https://api.provider.com/v1 這個 URL,當我新增認證憑證時能夠進行驗證,但在傳送請求時卻收到 401 錯誤。

還有,使用 https://api.provider.com/v1/chat/completions 時,當我新增 API 金鑰時無法進行驗證。

vs

那麼哪個是哪個?你的回覆令人困惑。它是有效還是無效?

這是步驟2:

好的,當我用 HTTP Request Node 檢查 https://api_endpoint_url/v1/chat/completions 這個 URL 時,它是有效的(聊天完成功能正常運作)。

但當我在 OpenAI Node 中嘗試使用相同的端點 URL(https://api_endpoint_url/v1/chat/completions)或端點 URL(https://api_endpoint_url/v1)時,它無法運作

我詢問/正在詢問這個問題是出現在 OpenAI Node 還是 第三方廠商的端點上。

若要確認問題是否來自 OpenAI Node 的內部邏輯:

  1. **檢查執行日誌:開啟失敗的 OpenAI Node 的執行紀錄。查看「Request」**分頁(如果您的版本有此分頁)或錯誤訊息。如果錯誤是 404,幾乎肯定是 URL 構造問題(呼叫了錯誤的路徑)。
  2. **嘗試不含 /v1 的基礎 URL:**某些廠商預期基礎 URL 只是 https://api_endpoint_url。Node 之後會自動新增 /v1/chat/completions
  3. **比較 JSON 承載:**比較 HTTP Request Node(可正常運作)發送的請求「Body」與 OpenAI Node 發送的「Body」。messages 陣列結構中的微小差異都可能導致第三方廠商拒絕請求。
  1. 沒有 Request 分頁,以下是堆棧追蹤錯誤詳細資訊。

    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. 沒有 /v1 時無法驗證 API 金鑰。

你可以試試這些方法嗎?

選項 A:忽略「無法連接」警告(「直接試試」方法) 如果你確定你的 API 金鑰正確:

  1. 將基礎 URL 設定為 https://openai.inference.de-txl.ionos.com(不含 /v1)。
  2. 忽略認證畫面上的紅色「無法連接」警告,並直接點擊保存
  3. 進入你的工作流程,新增 OpenAI 節點,並嘗試執行「Chat」操作。如果供應商不支援 /models 端點,認證測試會失敗,但實際的聊天請求仍可能成功。

選項 B:使用 HTTP 請求節點(「穩定」方法) 如果選項 A 失敗,表示供應商需要 OpenAI 節點無法提供的標頭格式。在此情況下,HTTP 請求節點實際上是你最佳的工具

為了讓 HTTP 節點看起來像 AI 節點,你可以:

  1. 建立一個子工作流程,接受提示作為輸入,並透過 HTTP 請求節點返回 AI 回應。
  2. 每當你需要 AI 完成時,呼叫這個子工作流程。

選項 A: 無法運作

選項 B:可以運作了!!

謝謝!

不客氣