DEV Community

Pirate Prentice
Pirate Prentice

Posted on

How to connect n8n to ChatGPT (OpenAI) — build your first AI automation in 10 minutes

#ai

If you've been using n8n for automations but haven't connected it to ChatGPT yet, this is the tutorial for you.

n8n has a native OpenAI node that makes it surprisingly easy to add AI to any workflow — no custom API code required. In this post I'll walk you through building a real working AI automation from scratch.

What we're building

A workflow that:

  1. Receives a webhook (from a form, Slack, or anything)
  2. Passes the input to ChatGPT
  3. Returns the AI-generated response — to email, Slack, Google Sheets, wherever you need it

This is the foundation pattern for almost every AI automation in n8n. Once you have this wired up, you can swap in any trigger and any output.

Prerequisites


Step 1 — Create a new workflow and add a Webhook trigger

  1. In n8n, click + New Workflow
  2. Add a Webhook node as your trigger
  3. Set the HTTP method to POST
  4. Copy the webhook URL — you'll use it to send test data

The webhook will receive a JSON body with whatever input you want to send to ChatGPT. For this tutorial we'll use:

{
  "message": "Summarize the following in one sentence: n8n is an open-source workflow automation tool that lets you connect apps and automate tasks without writing code."
}
Enter fullscreen mode Exit fullscreen mode

Step 2 — Add the OpenAI node

  1. After the Webhook node, click + to add a new node
  2. Search for OpenAI and select it
  3. Choose the Message a Model operation
  4. Create a new credential: paste your OpenAI API key

Model settings:

  • Model: gpt-4o-mini (fast and cheap — ideal for automations)
  • User Message: {{ $json.message }} — this pulls the message from the webhook body
  • System Prompt (optional): You are a helpful assistant. Be concise.

That's it. n8n handles the API call, authentication, and response parsing automatically.

Step 3 — Use the response

The OpenAI node outputs the response text at:

{{ $json.message.content }}
Enter fullscreen mode Exit fullscreen mode

From here you can pipe it anywhere:

  • Send Email node → email the AI response
  • Slack node → post it to a channel
  • Google Sheets node → log it to a spreadsheet
  • Respond to Webhook node → return it to the caller as JSON

For testing, add a Respond to Webhook node at the end with body {{ $json.message.content }} — that way you can hit the webhook URL and get the AI response back in real time.

Step 4 — Test it

  1. Activate the workflow
  2. Send a POST request to your webhook URL with the JSON body above (use curl, Postman, or any HTTP tool)
  3. You should get back a clean one-sentence summary from ChatGPT in under 2 seconds

Real-world uses for this pattern

Once you have the base pattern working, here's what people actually build with it:

Use case Trigger What ChatGPT does
Auto-classify support tickets Email receive Tags tickets by urgency/topic
AI email drafts New CRM lead Drafts a personalized outreach email
Form response summarizer Tally/Typeform webhook Summarizes long-form answers
Slack Q&A bot Slack mention Answers questions from a knowledge base
Invoice data extraction Email attachment Extracts line items into Google Sheets

All of these use the same skeleton: trigger → OpenAI node → output node.

Common issues

"I get an authentication error" — double-check your OpenAI API key in n8n credentials. Make sure you're using a key from the project you have billing set up for.

"The response is empty" — check your expression path. In newer n8n versions the response is at {{ $json.message.content }}. In older versions it may be at {{ $json.choices[0].message.content }}.

"It's slow" — switch from gpt-4o to gpt-4o-mini. For most automation tasks the quality difference is negligible and latency drops from ~3s to ~0.5s.


Want pre-built workflows that already use this pattern?

I put together an n8n Workflow Starter Pack — 5 production-ready workflow JSONs you can import and run immediately, including a lead-capture AI workflow that uses OpenAI to score and categorize inbound leads automatically.

Get the n8n Workflow Starter Pack ($29) →

Drop a comment below if you get stuck on any of the steps and I'll help you debug it.

Top comments (1)

Collapse
 
pirateprentice profile image
Pirate Prentice

Here's the complete workflow JSON from the tutorial — paste this into n8n via Settings > Import Workflow:

{
  "name": "n8n + ChatGPT Starter",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ai-trigger",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-1",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "resource": "chat",
        "modelId": { "__rl": true, "value": "gpt-4o-mini", "mode": "list" },
        "messages": {
          "values": [
            {
              "content": "={{ $json.message }}"
            }
          ]
        },
        "options": {
          "systemMessage": "You are a helpful assistant. Be concise."
        }
      },
      "id": "openai-1",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [460, 300]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json.message.content }}",
        "options": {}
      },
      "id": "respond-1",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [680, 300]
    }
  ],
  "connections": {
    "Webhook": { "main": [[{ "node": "OpenAI", "type": "main", "index": 0 }]] },
    "OpenAI": { "main": [[{ "node": "Respond to Webhook", "type": "main", "index": 0 }]] }
  }
}
Enter fullscreen mode Exit fullscreen mode

Remember to add your OpenAI credential after importing. Let me know if you run into any issues!