EN ▾
Get API key

OpenAI Compatible API in n8n: Setup Guide

If you searched for openai compatible api n8n, the short answer is that you only change two values in the OpenAI credential, the Base URL and the API key. The rest of the workflow stays the same as with any OpenAI node.

Updated

Isometric automation workflow with connected blocks sending data to an API terminal

Key points

What you need before you start

An n8n instance (cloud or self-hosted) and an API key from this service. If you do not have a key yet, the API key page walks you through sign-up with Google or email and password. New users can claim $0.50 of trial credit with one click on that page, valid for 7 days and without a card.

Three values go into n8n:

  • Base URL: https://api.onekeyllmapi.com/v1
  • API key: sent as Authorization: Bearer <key>, which n8n does for you
  • Model ID: uncensored

The service is a hosted, text-only LLM API that follows the OpenAI request format for /v1/chat/completions, /v1/responses and /v1/models. It is not the official API of any model vendor, so anything n8n sends to OpenAI's chat endpoint works here as long as it is a text request.

Step 1: Create the credential

In n8n open Credentials, choose Create credential and search for OpenAI API. Fill it in like this:

  1. Paste your key into the API Key field.
  2. Leave Organization ID empty.
  3. Replace the default Base URL with https://api.onekeyllmapi.com/v1. Keep the /v1 at the end and do not add /chat/completions.
  4. Save. n8n runs a small test call when you save; if it fails, jump to the troubleshooting section below.

Keep one credential per environment. If you run a staging and a production n8n, give each its own key so you can see spend separately and revoke one without touching the other.

Step 2: Build a simple chat workflow

Start with the smallest thing that proves the connection: a manual trigger and one model call.

  1. Add a Manual Trigger node.
  2. Add an OpenAI node (or the OpenAI Chat Model sub-node inside a Basic LLM Chain, depending on your n8n version) and select the credential from step 1.
  3. For the model, look for a way to enter an ID by hand. Recent n8n versions offer a By ID mode next to the list. Type uncensored there. The list may be empty or show only OpenAI names, because n8n filters it on its side.
  4. Add a prompt such as Summarize this support ticket in two sentences and run the node.

If your n8n version insists on picking from a list, use the HTTP Request approach in the next section. It always works because you control the whole request.

Calling the API with the HTTP Request node

The HTTP Request node is the most predictable way to call this API from n8n, and it exposes every parameter the API accepts, including seed, stop, top_p and tools. Configure it like this:

  • Method: POST
  • URL: https://api.onekeyllmapi.com/v1/chat/completions
  • Authentication: Generic Credential Type with Header Auth, name Authorization, value Bearer YOUR_KEY
  • Send Body: on, content type JSON

Body (switch the field to Expression if you want to insert data from earlier nodes):

{
  "model": "uncensored",
  "messages": [
    {"role": "system", "content": "You are a concise assistant."},
    {"role": "user", "content": "Summarize this support ticket in two sentences."}
  ],
  "temperature": 0.4
}

The reply text lives at choices[0].message.content. In the next node you can reference it with {{ $json.choices[0].message.content }}.

To test the same request outside n8n first, run this in a terminal:

curl https://api.onekeyllmapi.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"Say hello in five words."}]}'

If curl works and n8n does not, the problem is in the node settings, not in your key or balance.

JSON mode for workflows that parse the output

Workflows break when a model wraps data in friendly prose. JSON mode asks the API to return a valid JSON object, which you can pass straight to a Set or IF node. Add response_format to the body:

{
  "model": "uncensored",
  "response_format": {"type": "json_object"},
  "messages": [
    {"role": "system", "content": "Reply only with a JSON object with keys sentiment and summary."},
    {"role": "user", "content": "The delivery was late but support fixed it fast."}
  ]
}

Two habits make this reliable. First, say the word JSON and name the keys in the prompt, because JSON mode guarantees syntax, not your schema. Second, the reply still arrives as a string in message.content, so add a Code node or an expression with JSON.parse() before you read fields. In the OpenAI node, the same switch appears as a Response Format option under the node options.

Handling 429 and other errors

n8n runs items in parallel, so a batch of 50 rows can hit limits quickly. A full key allows 8 concurrent requests and 300 requests per minute; a trial key allows 2 and 60. When you go over, the API answers HTTP 429 with the code rate_limited (too many per minute) or concurrency (too many at once). On temporary overload you get 429 with a Retry-After: 5 header.

Practical settings in n8n:

  • Open the node, go to Settings, enable Retry On Fail, set Max Tries to 3 or 4 and Wait Between Tries to 5000 ms.
  • Put a Loop Over Items node (batch size 4 to 6) before the model call so you stay below 8 parallel requests.
  • Under node Settings, On Error can be set to continue with an error output, so one bad row does not stop the run.

For a deeper look at the two kinds of limit, read the API documentation. Other errors are simple: a 401 means the key is wrong or the header is missing the word Bearer, and a 404 usually means the Base URL has a typo or an extra path segment.

Troubleshooting checklist

Most failures come from a short list of causes. Work through it from top to bottom before you suspect the service.

SymptomLikely causeFix
401 on save or runWrong key, or the header lacks BearerPaste the key again; in Header Auth the value must start with Bearer
404Base URL has a typo or an extra pathUse exactly https://api.onekeyllmapi.com/v1 in the credential
Model not foundModel ID not typed as uncensoredSwitch to By ID, or use the HTTP Request node
429 with concurrencyMore than 8 parallel runs (2 on a trial key)Batch with Loop Over Items and add retries
JSON parse error downstreamReply is a string, or the prompt did not name the keysParse with JSON.parse() and describe the keys in the system prompt

When you contact support, include the X-Request-Id response header from the failing call. In n8n you can see headers by turning on Include Response Headers and Status in the HTTP Request node options.

Testing without spending much

Use the trial credit while you build. At 2 concurrent requests and 60 requests per minute a trial key is slow for batches, but plenty for checking a credential, a prompt and the parsing logic. Switch to a full key when you move the workflow to a schedule.

Cost and a sensible workflow design

Pricing is pay as you go: $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit. A workflow that classifies 1,000 emails a day with 600 input and 100 output tokens each uses 0.6M input tokens ($0.09) and 0.1M output tokens ($0.05), about $0.14 per day. Failed or refused requests are not charged, so retries on errors do not double the bill. Details are on the pricing page.

Keep prompts short, send only the fields the model needs, and set max_tokens when you know the answer is brief. If you also run models on your own machine, see the article on using a local LLM through an OpenAI-style API, which uses the same client settings.

Questions and answers

Which n8n nodes work with a custom base URL?

Any node that uses the OpenAI credential can use it, because the Base URL field belongs to the credential. If a node does not expose a parameter you need, use the HTTP Request node.

Why is the model list empty or wrong in n8n?

n8n loads and filters the list on its side. Enter the model ID uncensored by hand, or use the HTTP Request node where the model is just a field in the body.

Can I use streaming in n8n?

The API supports streaming over SSE, but most n8n nodes wait for the full reply before passing data on. For workflows, a normal non-streamed call is simpler.

How do I check my balance from a workflow?

Call GET /v1/balance, or read the X-Balance-USD header on any response, and add an IF node that alerts you when it drops below a threshold.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.