n8n OpenAI: 5 Workflow Patterns for GPT-4o
Ready to automate?
Browse 5,600+ copy-paste n8n workflow templates.
Most teams that connect n8n to OpenAI start with the same setup: a Webhook Trigger, an OpenAI node set to Chat model, and a Slack or Gmail node at the end. That works. But it leaves most of the API's capability untouched.
GPT-4o handles structured JSON extraction, function calling, and multi-turn Assistants with persistent thread state. Each capability unlocks a distinct class of automation that a generic chat completion won't reach. This guide covers five specific patterns you can build in n8n today, with the exact nodes and configuration steps for each.
Setting Up the OpenAI Credential
Before building any of these patterns, add your OpenAI credential in n8n. Go to Settings, then Credentials, and create a new OpenAI credential using your API key from platform.openai.com. The built-in OpenAI node uses this credential for Patterns 1 through 3 and part of Pattern 5. Pattern 4 uses HTTP Request nodes to reach Assistants API endpoints that the built-in node does not yet expose — those requests require you to pass the API key as a Bearer token header manually.
Pattern 1: Text Classification with GPT-4o
Use case: Incoming support tickets, form submissions, or emails arrive as unstructured text and need to be sorted before they can be routed or acted on.
Workflow steps:
- A Webhook Trigger or Gmail Trigger delivers the raw text to the workflow.
- An OpenAI node receives the text. Set the model to
gpt-4o-mini— it handles classification reliably and costs far less than the full GPT-4o model. - Write a System Message that defines the expected output: "Classify the following text as exactly one of: billing, technical, account, or other. Return the category name only."
- A Switch node reads the OpenAI node output and branches on the returned category string.
- Each branch routes to the appropriate action — a Zendesk node creates a support ticket, a Jira node opens a bug report, an Airtable node logs the entry.
Key nodes: Webhook Trigger → OpenAI node → Switch node → destination nodes.
For high-volume workflows, wrap the OpenAI node inside a Loop Over Items node to process batches of incoming items in a single execution rather than triggering a separate workflow run for each one.
Pattern 2: Batch Email and Document Summarization
Use case: A daily digest of customer emails, a weekly summary of Linear issues, or a periodic roll-up of Slack messages in a monitored channel.
Workflow steps:
- A Schedule Trigger fires at the target interval.
- A data source node pulls the items for the period. Use a Gmail node with the Get Many operation, a Linear node, or an HTTP Request node against whichever source holds your data.
- A Loop Over Items node iterates over the returned list.
- Inside the loop, an OpenAI node receives each item's body. Use a concise System Message: "Summarize the following in two sentences. Be specific — include any mentioned names, decisions, or numbers."
- Outside the loop, an Aggregate node collects all summaries into a single array.
- A Slack node or Gmail node sends the aggregated list to the relevant person or channel.
Key nodes: Schedule Trigger → data source node → Loop Over Items → OpenAI node → Aggregate node → Slack node.
For documents stored in Google Drive, pair a Google Drive node with an HTTP Request node to download the file content. For PDFs, an Extract from File node pulls the raw text before it reaches the OpenAI node.
Pattern 3: Structured Data Extraction from Unstructured Text
Use case: Incoming invoices, contracts, email threads, or scanned documents contain field values — amounts, dates, names, addresses — that need to land in a spreadsheet, CRM, or database row.
Workflow steps:
- A trigger delivers the document or raw text. For email attachments, use a Gmail Trigger. For form uploads, use a Webhook Trigger.
- If the input is a file, an Extract from File node pulls the plain text from PDFs, DOCX files, or other supported formats.
- An OpenAI node receives the text using model
gpt-4o. Write an explicit System Message: "Extract the following fields and return valid JSON only: invoice_number, vendor_name, total_amount, due_date, line_items (as an array). Use null for any field not present in the text." - In the OpenAI node's Advanced Options, set Response Format to JSON Object. This forces the model to return parseable JSON rather than prose.
- A Set node maps the extracted keys to the target schema your destination expects.
- A Google Sheets node, Airtable node, or HubSpot node writes the structured row.
Key nodes: Trigger → Extract from File node → OpenAI node → Set node → database node.
Add an IF node after the Set node to check for null fields. Route incomplete extractions to a Slack notification for manual review rather than writing a partial record that will be difficult to find and fix later.
Pattern 4: Assistants API with Persistent Thread State
Use case: A conversational interface that remembers prior messages across multiple user turns — a customer support bot, an internal FAQ assistant, or a document-aware agent that references uploaded files.
The built-in OpenAI node handles single-turn completions. Multi-turn Assistants with thread persistence require direct calls to the Assistants API via HTTP Request nodes.
Workflow steps:
- A Webhook Trigger receives the user's message and a user identifier (email address, Slack user ID, or session token).
- A Google Sheets node or Supabase node looks up whether a thread ID already exists for this user identifier.
- An IF node branches on whether a thread ID was found.
- If no thread exists: an HTTP Request node calls
POST https://api.openai.com/v1/threadswith your API key as a Bearer token and the headerOpenAI-Beta: assistants=v2. The response contains the newthread.id. A Google Sheets node or Supabase node stores it against the user identifier. - If a thread exists: retrieve the stored
thread.idfrom the lookup result. - An HTTP Request node calls
POST https://api.openai.com/v1/threads/{thread_id}/messageswith the user's message as the request body. - An HTTP Request node calls
POST https://api.openai.com/v1/threads/{thread_id}/runswith yourassistant_idto start a run. - A Wait node pauses briefly, then an HTTP Request node polls
GET https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}until the returnedstatusfield equalscompleted. - A final HTTP Request node calls
GET https://api.openai.com/v1/threads/{thread_id}/messagesand extracts the latest assistant message. - A Respond to Webhook node returns the response to the calling application.
Key nodes: Webhook Trigger → Google Sheets node → IF node → HTTP Request nodes → Respond to Webhook node.
This pattern requires more nodes than a simple chat completion, but it enables stateful conversations across sessions, assistant-level tool definitions, and context from files attached via the OpenAI Files API.
Pattern 5: Function Calling for API Orchestration
Use case: A natural language interface to your internal tools — a user sends a plain-text instruction and the workflow determines which APIs to call, calls them, and returns a confirmation.
Workflow steps:
- A Webhook Trigger receives the natural language instruction: for example, "Add Elena Torres to HubSpot as a new contact and schedule an intro call for Friday at 10am."
- An OpenAI node is configured with model
gpt-4o. In the Tools section, define the functions available to the model:create_hubspot_contact(name, email, company)andcreate_calendar_event(title, date_time, attendees). Each function definition includes a description and a JSON Schema for its parameters. - The model reads the instruction and returns a
tool_callsarray in its response, identifying which function to invoke and with what arguments. - An IF node checks whether the response contains
tool_calls. - A Switch node routes each tool call to the correct action node — a HubSpot node for contact creation, a Google Calendar node for event creation.
- The action nodes execute and return results.
- A second OpenAI node receives the original messages plus a new message of role
toolcontaining the function results. This allows the model to compose a final natural language confirmation. - A Respond to Webhook node or Slack node delivers the response.
Key nodes: Webhook Trigger → OpenAI node (function definitions) → IF node → Switch node → action nodes → OpenAI node (follow-up) → Respond to Webhook.
Function calling turns the model into a router: it reads intent, selects the right action, provides structured arguments, and confirms completion. The pattern scales to any number of defined functions. Add a Code node between the Switch and action nodes to normalize arguments or apply business logic before the API call fires.
Choosing the Right Pattern
These five patterns cover a range from simple single-step classification to multi-turn stateful agents. Most production workflows combine two or more:
- A classifier (Pattern 1) routes to a summarizer (Pattern 2) for specific ticket categories.
- An extractor (Pattern 3) feeds structured data to a function-calling orchestrator (Pattern 5) for downstream CRM updates.
- A persistent assistant (Pattern 4) uses tool calls internally to fetch live data before generating its response.
The right starting point depends on whether your automation needs to make a decision (classification), reduce information (summarization), convert format (extraction), remember context (Assistants), or take action based on language (function calling).
For ready-to-import template workflows covering these patterns, visit the OpenAI integration library on n8nresources.dev. For more complex multi-step agent patterns, the AI agents use case library covers memory, tool use, and conditional branching in depth.
All templates are available at n8nresources.dev/templates.
Enjoyed this article?
Share it with others who might find it useful