n8n 串接 OpenAI 教學│建立 n8n 節點串接 ChatGPT 語言 Chat Model 與圖片模型完整教學

前言

這個 n8n 串接 OpenAI 教學教學我會分享 2 種不同節點分別串接 Open AI 的語言模型及生成圖片的方法。

  1. Open AI 節點串接 ChatGPT 語言模型
  2. HTTP 節點串接 ChatGPT Image-1 製作圖片模型

建立 AI Agent、OpenAI 與 HTTP Request 節點

先把以下 3 個節點建立起來

  1. AI Agent
  2. Open AI
  3. HTTP Request
1.1-create-n8n-nodes.jpeg
n8n 串接 OpenAI 教學

申請 OpenAI API 金鑰

  • Open AI 官網
  • API Keys → Create new secret key
  • 先把這個 Key 保留下來

設定 HTTP Request 節點

  • URL: https://api.openai.com/v1/images/generations
  • Authentication: Generic Credential Type
  • Generic Auth Type: Header Auth
  • Header Auth: Create New Credential
    • Name: Authorization
    • Value: Bearer Your API KEY (Bearer 後面要空一格後才把你 Open AI 的 API Key 貼上去)
  • Send Body 打開
    • Body Content Type: JSON
    • Specify Body: Using JSON
    • JSON: 貼上 ↓
    { "model": "gpt-image-1", "prompt": "Generate a high-quality image with this prompt: {{ $json.prompt }}", "size": "1536x1024", "quality": "high", "moderation": "low", "output_format": "jpeg", "background": "opaque", "output_compression": 50 }

設定 OpenAI 節點串接語言模型

  • Credential to connect with: Create New Credential
  • API Key: Your API KEY

需要協助?加入 Discord 社群尋求支援

如果你遇到任何問題的話,歡迎你進來 Discord 找我。

Discord 討論區

延伸閱讀:  n8n 自動化工具介紹:開源、低代碼的工作流程革命