n8n OpenAI-Compatible API: Connect and Debug a Workflow

Connect n8n to an OpenAI-compatible API, choose the right endpoint, isolate item-mapping errors, and test a workflow before enabling agent tools.

Published 2026-09-29 · Updated 2026-09-29 · KeepRouter Editorial · 5 minute read

Layered responsibility map between an application, AI gateway, and model providers
An application connects to a model API through an explicit request boundary. Conceptual illustration.

Connect n8n to an OpenAI-compatible service with that service's base URL, API key and exact model ID. Start with one text request and Chat Completions. Move to an AI Agent only when the chosen model and route support its tool protocol. A successful credential check does not test the whole workflow.

For an operations team classifying incoming requests, the first useful result is a label attached to the correct ticket. This guide builds that small test before adding memory, tools or unattended actions.

Choose a node for the job

The n8n OpenAI Chat Model documentation distinguishes Chat Completions from its Responses API option. Keep the latter off for a Chat Completions-only route. Its built-in Responses tools have separate requirements; a custom URL does not make every OpenAI service available.

Starting pointUse it forWhat to inspect
HTTP RequestSeeing the exact request and responseStatus, response body and item mapping
Basic LLM Chain with a chat modelPrompt-driven text transformationsSelected model, prompt variables and output
AI Agent with a chat modelChoosing and invoking application toolsTool calls, results, stop conditions and permissions

For initial debugging, an HTTP Request node is useful even if the final workflow uses a chain. It removes hidden prompt assembly and makes the failing layer easier to identify. Keep credentials in n8n's credential store, following its credential documentation; do not paste a secret into a workflow export.

Make one request you can explain

For KeepRouter, use POST to https://keeprouter.com/v1/chat/completions, JSON content, and a stored Header Auth credential with an Authorization bearer value. The JSON body below contains no credential. The free model is a connectivity check, not a recommendation for production classification.

{
  "model": "free",
  "messages": [
    {"role": "system", "content": "Classify the ticket as billing, access, or other. Return only one label."},
    {"role": "user", "content": "I cannot sign in after resetting my password."}
  ],
  "stream": false
}

Read the returned content from the response's actual structure, normally choices[0].message.content for this route. Decide how to handle any label outside the three allowed values. Do not let an unexpected sentence become a new destination queue. If several categories apply, define a priority rule in your application before increasing prompt complexity.

When moving to a model node, its base URL is https://keeprouter.com/v1, without the final /chat/completions. Check the credential and node options in your installed version for its custom base URL setting. If that version does not expose it, the HTTP Request path remains explicit. Select the exact ID from the live model catalog, then check the node's request shape with the migration checker.

Test two tickets before testing two hundred

Create a fixture with ticket_id and text, including two visibly different tickets. Keep the ID outside the model-generated text and join results by that application-owned ID. A model should not be responsible for remembering which row it belongs to.

An important n8n-specific trap is sub-node expression resolution: the model-node documentation says expressions in sub-nodes resolve to the first item. If two tickets receive the same answer, inspect which text entered the prompt before blaming the model. Use an explicit per-item loop or place item-dependent prompt mapping in the appropriate root node. Never assume that a model sub-node independently resolves each incoming item.

An illustrative acceptance set could contain 12 tickets: four billing, four access and four deliberately ambiguous. The count is a starter fixture, not evidence of classification accuracy. Check the exact ticket-to-label association and whether ambiguous cases go to review. A second run should not create duplicate downstream tickets.

Diagnose the first failing boundary

ObservationFirst checkAvoid
401 before outputCredential attached to this node and destinationChanging the prompt
404Full HTTP URL versus model-node base URLAppending /v1 twice
Model not foundCatalog ID and account accessCopying another router's model prefix
Same text on every itemInput expression and loop scopeRaising the model temperature
Text works, Agent failsNative tool support and returned tool messagesAssuming text compatibility proves agent compatibility
Spend exceeds expectationNumber of model calls per workflow executionCounting only the final answer

Keep retries bounded while debugging. A node retry, workflow retry and queue redelivery can multiply the same ticket's model calls. Store a processing status for each ticket and make the downstream action idempotent independently of whether the model request can be repeated.

Promote the workflow with a useful comparison

Run the same fixture on a paid candidate only after confirming its route and price. Compare accepted labels, review count, total request charges and time until the ticket is ready, rather than token price alone. A cheaper model that sends more tickets to manual review can cost more to operate.

Use the API cost calculator with all model calls per execution, including retries. Then follow the quickstart to create a key and run the isolated connection test. Keep the old workflow deployable until the new one preserves ticket identity and its downstream actions.

Frequently asked questions

Should I enable Responses API in n8n?

Only when the destination route supports the Responses features your workflow uses. For the Chat Completions example here, leave it off and inspect the actual request URL.

Why does every item get the same model input?

Inspect sub-node expression resolution and loop scope. n8n documents first-item resolution in sub-nodes; this can repeat the first input even when the model itself works.

Does a free call prove the Agent will work?

No. It proves only the tested text request. Verify tool calling, the selected paid model, multi-item behavior and total workflow charges separately.

Sources reviewed

Article last reviewed 2026-09-29

  1. [1] n8n OpenAI Chat Model
  2. [2] n8n OpenAI credentials

Related guides

← All posts · Models & pricing · Get an API key