Guides10 min readPublished 2026-08-03

How to Call an OpenAI-Compatible API from n8n

Build a reusable n8n HTTP Request workflow for an OpenAI-compatible API, with stored credentials, response mapping, retries and cost controls.

By LumeAPI Engineering Team

LLM API Gateway hub → Production LLM API →

Short path: LLM API gateway · Production LLM API · OpenAI-compatible API · Usage logs

Last verified: August 3, 2026

To call an OpenAI-compatible API from n8n reliably, use the HTTP Request node with a stored Bearer credential, POST to the provider's /v1/chat/completions endpoint, and map choices[0].message.content into the next node. This avoids depending on whether a particular n8n OpenAI node version exposes a custom Base URL or defaults to the Responses API.

For LumeAPI, the request URL is https://api.lumeapi.site/v1/chat/completions. Keep the inference key in n8n Credentials, not in the workflow JSON.

Build the minimum working workflow

text
Manual Trigger
    ↓
Set Input
    ↓
HTTP Request: LumeAPI Chat Completions
    ↓
Set Output

The minimum flow is intentionally small. First prove authentication, model selection and response mapping. Add retries, branches and external actions only after the baseline execution succeeds.

Store the Bearer credential

Create a generic Header Auth credential in n8n:

Credential fieldValue
NameAuthorization
ValueBearer <your LumeAPI inference key>

Select that credential in the HTTP Request node. n8n's HTTP Request implementation supports generic credential types; using the credential store keeps the secret out of exported workflow JSON and screenshots.

Do not use the Research ingest key. It publishes articles and is not a model-inference credential.

Configure the HTTP Request node

Use these settings:

SettingValue
MethodPOST
URLhttps://api.lumeapi.site/v1/chat/completions
AuthenticationGeneric Credential Type → your Header Auth credential
Send HeadersOn
HeaderContent-Type: application/json
Send BodyOn
Body Content TypeJSON
Response FormatJSON

Enter this JSON body. The expression reads a prompt created by the preceding Set node:

json
{
  "model": "gpt-5.6-terra",
  "messages": [
    {
      "role": "system",
      "content": "Answer briefly and do not invent missing facts."
    },
    {
      "role": "user",
      "content": "={{ $json.prompt }}"
    }
  ],
  "temperature": 0
}

In Set Input, create a string field named prompt. For the first run, use Reply with exactly: n8n connection ok.

Map the result without passing the full response downstream

Add a Set node after the request and create:

text
answer = {{ $json.choices[0].message.content }}
model  = {{ $json.model }}
request_id = {{ $json.id }}
prompt_tokens = {{ $json.usage?.prompt_tokens ?? null }}
completion_tokens = {{ $json.usage?.completion_tokens ?? null }}

This mapping is a useful contract boundary. Downstream Slack, email, database or ticket nodes receive only the fields they need, while the raw provider response can remain in execution data for debugging according to your retention policy.

Add failure handling before scheduling the workflow

FailureWhat n8n should doWhat it should not do
400 invalid bodyStop and send the validation message to an error branchRetry the same malformed JSON
401 unauthorizedStop, alert the credential owner and rotate or correct the keyPut the key into a Set node
404 model or routeRecheck /v1, endpoint path and model IDKeep retrying a stale model name
429 rate limitWait with bounded exponential backoff and jitterLaunch parallel retries from every item
5xx or timeoutRetry a small number of times, then use a controlled fallback or dead-letter branchLoop indefinitely
Empty choicesPreserve the raw response and fail the mapping step clearlyConvert missing output to an empty successful message

In production, configure a timeout, cap attempts and record the n8n execution ID with the provider request ID. If the workflow performs an irreversible action after the model call, add an idempotency key before that action. A model retry must not send the same email, ticket or payment twice; see the agent tool-call idempotency guide.

Why not rely on the native OpenAI node?

The native node is convenient when its API surface matches the provider. However, n8n versions and AI nodes can differ in Base URL support and whether they call Chat Completions or Responses. A public n8n feature request documented the absence of a custom Base URL in at least one OpenAI node path. The HTTP Request node makes the route, headers and JSON visible, which is better for a gateway tutorial and easier to debug.

Use the native node if your installed version explicitly supports the endpoint and operation you need. Use HTTP Request when you require a precise OpenAI-compatible URL, a stable Chat Completions payload, or provider-specific response logging.

Turn the baseline into a reusable sub-workflow

After the manual test passes:

  1. Replace Manual Trigger with Execute Workflow Trigger.
  2. Define inputs such as prompt, model, temperature and request_context.
  3. Validate model against an allowlist rather than accepting arbitrary input.
  4. Return only normalized answer, model, token fields and request ID.
  5. Set a maximum prompt length before sending the request.
  6. Route 429 and 5xx errors to bounded retry logic.
  7. Add a human approval step before high-impact downstream tools.

This creates one controlled gateway sub-workflow instead of copying credentials and request bodies into every automation.

Cost and privacy controls users usually miss

An n8n loop can turn one trigger into hundreds of API calls. Count input items before the model node, batch when the task allows it, and stop unexpectedly large runs. Avoid saving sensitive prompts forever in n8n execution history. Redact or shorten retained data according to your security requirements.

The exact-query research signal for n8n openai api is small, but the parent topic n8n ai is materially larger. That is why this page solves a narrow task while also covering credential storage, mapping, retry behavior and reusable workflow design rather than publishing multiple near-duplicate n8n pages.

Sources and testing boundary

The node field map and JSON payload were statically checked on August 3, 2026. No customer inference key or live n8n instance was available in this editorial workspace, so readers should run the exact manual-trigger test before enabling a schedule.

Ready to call these models?

Create a LumeAPI key in under a minute — one OpenAI-compatible gateway for GPT, Claude, Gemini, and more.