There are two practical ways to build an n8n OpenAI integration: use n8n's OpenAI or OpenAI Chat Model nodes when your version supports the required credential fields, or call the compatible endpoint explicitly with an HTTP Request node. The second option is useful for ordinary chat, classification, and routing steps; it is not automatically interchangeable with an AI Agent's ai_languageModel input.
This tutorial connects n8n to LinkModel's OpenAI-compatible chat endpoint. The documented API root is https://api.linkmodel.ai/v1, and chat requests use bearer-authenticated POST /chat/completions. You can keep the same workflow shape while changing the model ID in the current LinkModel model catalog.
Choose the right n8n node
Use the built-in OpenAI Chat Model path when you need to connect a model to an AI Agent, chain, or other LangChain-style node. Use HTTP Request when you need a normal workflow step that sends JSON and handles a JSON response itself. n8n's OpenAI node documentation is the source for the current node operations and version notes.
| Requirement | Better starting point | Why |
|---|---|---|
| Agent with tools | OpenAI Chat Model or another compatible chat-model node | The Agent expects a model connection, not arbitrary JSON |
| One request and one response | HTTP Request | Full control over URL, headers, and body |
| Provider-specific fields | HTTP Request or a supported native node | You can inspect exactly what is sent |
| Model comparison | Either, with model ID in one variable | Keeps the evaluation input consistent |
n8n's OpenAI node documentation also notes that node versions can change. Check the node version in your instance before copying a workflow between deployments.
If the workflow includes image or video generation, route that work to the documented media endpoint rather than assuming a chat request can create an artifact. The n8n workflow templates for AI media page covers that separate pattern, while LinkModel CLI is useful for terminal and CI generation tasks.
Option A: configure a compatible OpenAI Chat Model
In n8n, add the OpenAI Chat Model node and create a credential with:
Base URL: https://api.linkmodel.ai/v1
API key: your LinkModel API key
Model: gpt-5.4-miniThe exact field names depend on your n8n release. If the credential editor has no custom base URL field, it will likely send requests to the default OpenAI host. Do not assume that a valid LinkModel key will work there. Upgrade to a supported configuration, use a compatible gateway, or use Option B for a non-agent request.
The gpt-5.4-mini ID is listed in LinkModel's current chat model reference. Verify the model ID, tool support, and endpoint availability at configuration time. Start with a low-risk prompt and no tools, then add capability tests one at a time.
Option B: call the API with HTTP Request
Add an HTTP Request node with:
Method: POST
URL: https://api.linkmodel.ai/v1/chat/completions
Authentication: Bearer token stored in an n8n credential
Content-Type: application/jsonUse an expression for the message rather than concatenating untrusted text into a system instruction:
{
"model": "gpt-5.4-mini",
"messages": [
{
"role": "system",
"content": "Classify the ticket as billing, technical, account, or other. Return JSON with keys category and reason."
},
{
"role": "user",
"content": "={{ $json.body.message }}"
}
]
}In the n8n UI, prefer a credential or header-auth object for the bearer token. Never paste a live key into a workflow JSON export, a Function/Code node, or a sample that will be committed.
The response follows the OpenAI-compatible chat shape for the standard text path. In a following Set or Code node, read the first choice defensively:
const choice = $json.choices?.[0];
const content = choice?.message?.content;
if (typeof content !== 'string') {
throw new Error('Model response did not contain text content');
}
return [{ json: { answer: content, model: $json.model ?? 'unknown' } }];If you request streaming, an HTTP Request node may receive a stream rather than one JSON object. Use non-streaming for the first workflow, or explicitly design the stream transport and parser before exposing it to users.
Connect the result to the rest of the workflow
A common pattern is:
Webhook → Normalize input → HTTP Request → Parse response → IF confidence → Ticket or human queueKeep validation after the model call. If the model returns malformed JSON, branch to a repair or human review path instead of letting an unvalidated string trigger a side effect. For a structured classifier, the safest action is to treat an unknown category as other and escalate.
Using the n8n OpenAI path with an AI Agent
An AI Agent needs a compatible model connection plus tools and, optionally, memory. An HTTP Request node that returns text is just a normal workflow node; it does not satisfy the Agent's language-model port by itself. If you need an agent, connect a supported OpenAI Chat Model node or another n8n chat-model integration.
The n8n AI Agent build guide covers the broader workflow, while the n8n Agent node tutorial focuses on model, tool, and memory wiring. Use those pages when the reader's task is agent construction rather than a single HTTP call.
Once the model is connected, add one read-only tool first. The tool should validate its inputs and perform its own authorization checks. Prompt instructions can say “never issue a refund,” but the tool implementation must enforce that rule too.
Error handling and retries
Add an error branch for authentication, rate limiting, timeout, and malformed response errors. Retry only transient failures, and use an idempotency key for any downstream write. If a ticket creation node follows the model, a model retry should not accidentally create two tickets.
Useful execution fields include:
- request ID and workflow execution ID;
- model ID and endpoint;
- HTTP status and error class;
- input/output usage when returned;
- latency and retry count;
- final business outcome.
Set a timeout appropriate to the user experience. For long-running image or video jobs, prefer an asynchronous task lifecycle and polling instead of holding one request open indefinitely.
Cost controls for multiple models
Put the chosen model in a workflow variable or environment variable, but allow only approved IDs. A practical routing policy is:
short classification → fast model
normal support answer → default model
complex escalation summary → higher-capability modelMeasure accepted results, not only API requests. If the fast model causes a human reviewer to rewrite every answer, its effective cost may be higher. Keep a small fixed test set and compare latency, failures, tool-call accuracy, and accepted-output cost before routing more volume.
Troubleshooting
401: confirm the bearer credential is attached to the HTTP Request node and that the key has not been copied with extra whitespace.
404: check whether the URL already contains /v1; avoid producing /v1/v1/chat/completions.
Model not found: copy the model ID from LinkModel's live catalog rather than the display name.
Agent rejects the model: confirm you used a chat-model node, not an HTTP Request node, and check tool-calling support.
JSON parsing fails: set a constrained output instruction, validate the result, and route failures to review. Do not parse with a brittle substring operation.
Next step
Use the built-in chat-model connection for agent workflows and HTTP Request for explicit, inspectable API calls. Test one model first, then swap model IDs behind configuration and compare real workflow outcomes. When your n8n automation needs media generation, continue with n8n workflow templates for AI media; when an agent needs a terminal-native media interface, use LinkModel CLI.
Sources: n8n OpenAI node documentation, n8n HTTP Request node documentation, LinkModel's first API call, and LinkModel's model reference.
