How to Connect ChatGPT API with n8n to Build AI Workflows

Short answer: Create an API key in your OpenAI platform account, add it as a credential in n8n, then drop an OpenAI node into any workflow: give it a prompt, map data from earlier nodes into it, and use the model's output in the steps that follow.
Connecting the OpenAI API to n8n turns ChatGPT from a chat window into a component: one step in workflows that read your data, think with a world-class model, and act on the result. This guide covers the connection and a first real build, checked against n8n's official documentation in December 2026.
What you need
- An OpenAI platform account with billing set up. API usage is billed per token, separate from any ChatGPT subscription.
- An n8n instance: n8n Cloud, or self-hosted (free and open source).
- Ten minutes.
Step 1: Create an OpenAI API key
- 1Log in to the OpenAI platform dashboard.
- 2Open the API keys section and create a new secret key.
- 3Copy it immediately; it is shown only once. Store it somewhere safe, ideally a password manager.
- 4Set a spending limit or budget alert in the billing section while you are here. It is the cheapest insurance in this whole guide.
Step 2: Add the credential in n8n
- 1In n8n, open the credentials area and create a new OpenAI credential.
- 2Paste the API key and save.
- 3The credential is now available to every OpenAI node in every workflow, stored encrypted by n8n rather than pasted into prompts or nodes.
Step 3: Your first AI workflow
Build the classic starter, "summarize new content":
- 1Trigger: a schedule, a webhook, or a new item in an RSS feed or spreadsheet.
- 2OpenAI node: choose the model and write the message. The prompt is a template: fixed instructions plus live data from earlier nodes, inserted with n8n's expression editor. Example: "Summarize the article below in three bullet points for a busy executive. Article: [article text field]".
- 3Action: send the result somewhere useful, an email, a Slack channel, a new row in a sheet.
Run it manually and inspect the output. Congratulations: ChatGPT is now a component in your system.

Step 4: Make prompts that survive production
Workflow prompts differ from chat prompts in one way that matters: they run thousands of times without you watching. So:
- Constrain the output. "Reply with exactly three bullets" or "return JSON with keys summary and category" makes the next node's job deterministic. Ask for structured output where the node supports it.
- Handle empty and weird input. "If the input is empty or irrelevant, reply with the word SKIP" gives the workflow a clean branch.
- Keep instructions in the system message and data in the user message, so the model never confuses content for commands. The prompt writing guide covers the underlying habits.
Step 5: Handle the failure modes
APIs fail; plan for it:
- Rate limits and errors: add n8n's error handling to the node so failures retry with backoff or route to an alert instead of silently dying.
- Cost control: smaller models for classification and extraction, larger ones only where quality demands it. Log token usage per run so the bill never surprises you.
- Data sensitivity: everything in the prompt goes to OpenAI's API. Check OpenAI's API data usage terms, redact what should not leave, and self-host n8n when your data rules require it.
Step 6: Grow into agents
The single OpenAI node answers one prompt. n8n's AI Agent node puts an OpenAI model in charge of a loop: it can call tools (a sheet lookup, an HTTP request, a search) before answering. Connect the same OpenAI credential, attach tools as nodes, and the model decides which to use per request. n8n's newer agents feature (in Preview) goes further: a standalone assistant with instructions, a knowledge base and schedules, powered by your chosen model. See our n8n guide for the full picture.

Builds to try next
- Inbox triage: classify and draft replies for incoming email. Our n8n email assistant guide builds it end to end.
- Content pipeline: turn one brief into drafts for every channel on a schedule.
- Data enrichment: classify or extract fields from records as they arrive in your CRM.
- Report writing: feed weekly metrics to the model and deliver a written summary, as in our automated reports guide.
FAQ
Is the ChatGPT API the same as a ChatGPT subscription?
No. The API is a separate developer product billed per token of usage, with its own platform dashboard. A ChatGPT Plus or Business subscription does not include API credits.
How much does API usage cost?
Per token, varying by model. Set a budget alert in the OpenAI billing dashboard, and use smaller models for routine steps to keep costs low.
Do I need to code to connect the API in n8n?
No. The OpenAI node takes a credential and a prompt through n8n's visual editor. Code nodes are optional extras.
Which OpenAI models can n8n use?
The models available to your API account, selectable in the node. Use capable small models for extraction and classification; reserve flagship models for steps where quality is visible.
Is my workflow data sent to OpenAI?
Yes, the content of each prompt is processed by the API. Review OpenAI's current API data usage terms, and keep sensitive data out of prompts or out of the cloud.
Sources
- n8n Docs, Build and manage agents: https://docs.n8n.io/build/build-and-manage-agents
- n8n Docs, AI Agent node: https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent
- OpenAI platform: https://platform.openai.com/
Key takeaways
- Create an API key on the OpenAI platform, store it as an n8n credential, and set a budget alert.
- Write production prompts: constrained output, empty-input handling, instructions separate from data.
- Plan for rate limits, costs and data sensitivity from day one.
- Grow from single OpenAI nodes to the AI Agent node when requests need tool-using judgment.
Want ChatGPT wired into your business workflows? Book a free 30 minute call with Tech AI Labs and we will build the first one together.
FAQ
Quick answers
Is the ChatGPT API the same as a ChatGPT subscription?
No. The API is a separate developer product billed per token of usage, with its own platform dashboard. A ChatGPT Plus or Business subscription does not include API credits.
How much does API usage cost?
Per token, varying by model. Set a budget alert in the OpenAI billing dashboard, and use smaller models for routine steps to keep costs low.
Do I need to code to connect the API in n8n?
No. The OpenAI node takes a credential and a prompt through n8n's visual editor. Code nodes are optional extras.
Which OpenAI models can n8n use?
The models available to your API account, selectable in the node. Use capable small models for extraction and classification; reserve flagship models for steps where quality is visible.
Is my workflow data sent to OpenAI?
Yes, the content of each prompt is processed by the API. Review OpenAI's current API data usage terms, and keep sensitive data out of prompts or out of the cloud.
IN THE DIRECTORY
See how this tool compares, what it costs and what it is best for.
Open the tool page →

