API Keys5 min

OpenAIAPISetupforn8n

Get an OpenAI API key and connect it to n8n for AI-powered workflows. Covers account setup, credential configuration, model selection, and cost management.

OpenAI's GPT models power many n8n workflow templates. This guide gets you from zero to a working OpenAI credential in n8n -- about 5 minutes total.

Get Your API Key

  1. Go to platform.openai.com and create an account (or sign in)
  2. Navigate to API Keys in the left sidebar (or go directly to platform.openai.com/api-keys)
  3. Click Create new secret key and name it something recognizable -- "n8n workflows" works
  4. Copy the key immediately. OpenAI shows it once and never again. If you lose it, you'll need to create a new one.

Your key starts with sk-. If it doesn't look like that, you're looking at the wrong thing.

Billing Setup

OpenAI requires a payment method for API access. Go to Settings > Billing and add a credit card. You can set a monthly spending limit to avoid surprises -- $5/month is more than enough for most n8n automation.

The API is pay-per-use. No monthly subscription required. You only pay for the tokens your workflows actually consume.

Add the Credential in n8n

  1. In n8n, go to Credentials (left sidebar)
  2. Click Add Credential
  3. Search for OpenAI and select it
  4. Paste your API key into the API Key field
  5. Click Save

Every OpenAI node in your workflows (Chat Model, LLM Chain, AI Agent) can now use this credential.

If you're importing a workflow template that uses OpenAI, the template will prompt you to connect this credential when you first open it.

Choosing a Model

OpenAI offers several models. The right choice depends on the task.

ModelBest forInput / Output (per 1M tokens)Speed
GPT-4o-miniBatch processing, summaries, structured extraction$0.15 / $0.60Fastest
GPT-4oComplex analysis, multi-step reasoning$2.50 / $10.00Fast
o1-miniMath, logic, code analysis$1.10 / $4.40Medium

For most n8n automation workflows, GPT-4o-mini is the right default. It's fast, cheap, and handles summarization, classification, and structured output reliably.

Use GPT-4o when you need higher quality reasoning -- like the final synthesis step in a report, or analyzing complex multi-dimensional data.

What This Actually Costs

Real numbers from running a daily Homelab Health Dashboard:

  • Per daily analysis (GPT-4o-mini): ~$0.0002-0.001
  • Monthly total (daily runs): Under $0.05
  • Even with GPT-4o: Under $1/month

Set a usage limit in the OpenAI dashboard under Usage Limits to cap spending. $5/month gives you enormous headroom.

Using OpenAI in n8n Workflows

Three ways to use OpenAI in n8n:

Chat Model node (most common) -- Drop an "OpenAI Chat Model" node into an LLM Chain or AI Agent. Select your credential and model. The node handles message formatting and response parsing.

LLM Chain -- Connect a Chat Model to a Basic LLM Chain node for simple prompt-in, text-out flows. Perfect for batch processing where you don't need tool calling.

AI Agent -- Connect a Chat Model to an AI Agent node for multi-step reasoning with tools. The agent can call other n8n nodes as tools, making decisions on the fly.

Configuration Tips

  • Temperature: Default 0.7 works for creative tasks. Drop to 0.2-0.3 for classification, extraction, and structured JSON output (you want consistency). The Homelab Health Dashboard uses 0.3.
  • Max tokens: Controls the maximum response length. For structured JSON responses, 1024-2048 is usually enough. For longer analysis, bump to 4096.
  • JSON mode: If your workflow asks the LLM to return JSON, instruct it clearly in the system prompt ("respond with ONLY valid JSON") and keep temperature low.

Troubleshooting

"Incorrect API key provided" -- Double-check you pasted the full key starting with sk-. Common mistake: copying the key name instead of the key value.

"You exceeded your current quota" -- Your account needs a payment method or has hit its spending limit. Go to platform.openai.com/settings/organization/billing to add credits.

"Rate limit reached" -- You're sending too many requests per minute. In n8n, set Retry on Fail to 3 with a 5-second wait between tries on the node. GPT-4o-mini has generous rate limits, so this usually only happens during batch processing.

"This model does not exist" -- Model IDs change. Check platform.openai.com/docs/models for current model names. Common gotcha: gpt-4o-mini is the correct ID (not gpt-4-o-mini or gpt4o-mini).

Response truncated or invalid JSON -- Increase max_tokens in the Chat Model node. If the model runs out of tokens mid-response, JSON output gets cut off and downstream parsing fails.


This guide covers OpenAI setup for the Homelab Health Dashboard and any n8n workflow that uses GPT models. See the n8n OpenAI integration docs for detailed node configuration.