AIFlowPost

How to Connect OpenAI to n8n (Step-by-Step)

Updated 2026-10-07 · 1044 words

How to Connect OpenAI to n8n (Step-by-Step) — AIFlowPost cover

This page may contain affiliate links. If you buy through them we may earn a commission at no extra cost to you.

Direct answer: connecting OpenAI to n8n takes one credential and a few minutes: generate an API key at platform.openai.com, add an OpenAI credential in n8n with that key, and attach it to either the standalone OpenAI node for a single task or the Chat Model node for an AI Agent. The credential is shared across both node types, so you only set this up once per OpenAI account. The parts worth getting right are billing (separate from any ChatGPT subscription) and picking the right node for the job, covered step by step below.

Step 1: Get an API key from OpenAI

Log into platform.openai.com (not chat.openai.com, a separate billing surface even on the same account) and go to API keys under your account settings. Create a new secret key and copy it immediately; OpenAI shows it only once. Before it'll actually work, add a payment method under Billing, the API runs on pay-as-you-go usage, and a key with no funded billing will authenticate fine but fail on the first real request with a quota error.

Step 2: Add the OpenAI credential in n8n

In n8n, open Credentials, create a new credential, and search for OpenAI. Paste in the API key from Step 1. If your organization has multiple projects or sub-organizations on OpenAI's platform, double-check the key belongs to the one with billing enabled, a key from the wrong project authenticates but then fails on quota, which looks identical to a billing problem from n8n's side and wastes time pointing at the wrong fix.

Step 3: Use the OpenAI node for a single task

For a one-off call, summarizing a document, generating an image, transcribing audio, add the OpenAI node directly to your workflow, select your credential, and pick a resource (Text, Image, Audio) and operation. This runs as a linear step: input in, OpenAI's response out, passed to whatever node comes next. This is the right choice any time you don't need the model to hold a conversation or decide on its own what to do next, most data-extraction and content-generation workflows on this site, like our guides to automating data entry and content repurposing, use the node this way.

Step 4: Use the Chat Model node for an AI Agent instead

If you're building something conversational, an agent that uses tools, holds memory, or needs to decide between multiple possible actions, don't use the standalone OpenAI node. Add an AI Agent node and connect an OpenAI Chat Model node to its model input instead; it uses the same credential from Step 2 but plugs into the agent's reasoning loop rather than running as an isolated call. Our guide to building an AI agent in n8n covers the agent side of this in full, tools, memory, and system prompt design, once the OpenAI connection itself is working.

Step 5: Pick a model deliberately, don't leave it on default

The node lets you choose a specific model rather than whatever OpenAI defaults to. Pin one explicitly. OpenAI periodically updates default model aliases and behavior, and a workflow left on a default can shift tone or output format without any change on your end, a confusing thing to debug weeks later. Match the model to the task's actual difficulty: a smaller, cheaper model is usually enough for classification, extraction, or short drafting, and reserving a larger, more expensive model for genuinely complex reasoning keeps recurring cost down without hurting output quality where it matters.

Step 6: Test with a real payload before trusting it in production

Run the node with an actual example from your workflow, not a trivial "hello world" prompt, and inspect the full output, not just whether it returned something. For extraction or classification tasks especially, check the output against a handful of edge cases from your real data before wiring it into anything that writes to a live system; a model call that "looks right" on a clean test input can behave differently on the messier real-world version.

Common errors and what they actually mean

Error Most likely cause
401 Unauthorized Bad or revoked API key, or extra whitespace pasted into the credential
429 Rate limit / quota exceeded No payment method on file, or usage cap hit for your account's current tier
Model not found A model name that's been deprecated or isn't enabled for your account tier
Unexpected or malformed output Prompt doesn't constrain output format tightly enough; add explicit formatting instructions
Slow or timing out Token count too high for the task, or the destination model is at a higher-latency tier than needed

Cost and billing, separate from your n8n bill

n8n's own cost (free if self-hosted, or a cloud plan fee) and OpenAI's API usage are entirely separate bills on separate accounts. There's no bundled pricing between the two. Set a hard spending limit in OpenAI's billing dashboard as a backstop against a runaway loop or an unexpectedly high-volume workflow, this has saved more than one of our own test workflows from a misconfigured retry logic eating through budget overnight. Beyond that, the actual per-call cost for most text tasks at normal volume runs to fractions of a cent, and routing simpler tasks to a smaller model is the lever that matters most if a workflow runs at real scale.

When OpenAI isn't the right model provider for the job

If your team already has an Anthropic or another provider's API key and no specific reason to use OpenAI's models, n8n's Chat Model options support the major providers interchangeably in the same AI Agent setup, so there's no lock-in forcing OpenAI specifically. It's also worth reconsidering a direct API integration at all if you don't want to manage prompts and model selection yourself; a no-code agent platform trades that control for speed, see our best no-code AI agent builders roundup if that tradeoff fits your team better than building the connection in n8n.

For the API reference itself, OpenAI's platform documentation covers model-specific parameters and current pricing in more depth than a connection guide needs. Get the credential and billing right first, pick the node type that matches the task, and model selection is the one setting worth revisiting periodically as OpenAI's lineup changes faster than most other parts of a typical n8n workflow.

Frequently asked questions

Do I need a ChatGPT Plus subscription to use OpenAI in n8n?

No. n8n connects to OpenAI's API, which is billed separately and on a different system from a ChatGPT Plus subscription. You need an OpenAI platform account with billing set up and an API key, available even if you've never subscribed to ChatGPT Plus at all.

Why am I getting a 401 or authentication error in the OpenAI node?

Almost always an API key problem: either it was pasted with extra whitespace, it was revoked or regenerated on OpenAI's side after you saved the credential in n8n, or it belongs to a different OpenAI organization than the one with billing enabled. Regenerate the key on platform.openai.com and re-paste it into a fresh n8n credential to rule this out.

What's the difference between the OpenAI node and the Chat Model node?

The OpenAI node runs a single, direct call, text completion, image generation, audio transcription, and returns the result to the next node in a linear workflow. The Chat Model node doesn't run standalone; it plugs into an AI Agent node as its reasoning engine, enabling multi-turn conversation, tool calls, and memory. Use the plain OpenAI node for one-off tasks and the Chat Model node when you're building an agent.

How do I control how much an OpenAI-powered workflow costs?

Set a hard usage limit in your OpenAI account's billing settings as a backstop, then control cost at the workflow level by picking a smaller, cheaper model for tasks that don't need top-tier reasoning, and by keeping prompts and expected outputs short. A classification task rarely needs the same model as an open-ended drafting task, and routing each to an appropriately sized model is the single biggest lever on recurring API cost.

↑ Back to top