---
title: "n8n OpenAI compatible API setup"
canonical: https://relayswitch.io/guides/n8n
generated: 2026-11-02T10:51:21.195Z
source: https://api.relayswitch.io/v1/catalog
base_url: https://api.relayswitch.io/v1
---

Checked 2026-10-30

# n8n OpenAI compatible API setup

n8n's OpenAI credential has a Base URL field. Point it at RelaySwitch and every OpenAI node in your workflows, the OpenAI Chat Model under an AI Agent included, calls Claude, GPT, Gemini and open models on one prepaid key.

An n8n OpenAI compatible API connection is one credential: an API key and a Base URL. Set the Base URL to `https://api.relayswitch.io/v1` and the nodes that use the credential send their requests to RelaySwitch, where all 338 per-token models on the [Models page](https://relayswitch.io/models) answer in OpenAI's format, billed per token to a prepaid balance.

The field is easy to miss: n8n's credential page in the docs lists only the API key and Organization ID, while the credential itself carries **Base URL** as its third field, prefilled with OpenAI's address. This guide sets the credential up, wires it to an AI Agent, gives the workflows a key with its own budget and prices a day of runs.

## 01What you need

-   n8n, on n8n Cloud or self-hosted, with a version that has the AI Agent node. The credential is the same on both.
-   A RelaySwitch key. Sign in with an email code at the [console](https://app.relayswitch.io/console), open Keys and create one; it starts with `sk-relay-`. The section on a key for n8n alone below shows how to give it a budget.
-   Optional: check the key from a terminal first. A list of models means the key works:
    
    bash
    
    1`curl https://api.relayswitch.io/v1/models -H "Authorization: Bearer sk-relay-..."`
    

## 02Create the OpenAI credential with the RelaySwitch Base URL

In n8n, open **Credentials**, create a credential and pick **OpenAI**. Fill it in like this:

| Field | Value |
| --- | --- |
| API Key | `sk-relay-...` |
| Organization ID (optional) | Leave empty |
| Base URL | `https://api.relayswitch.io/v1` |
| Add Custom Header | Off |

Keep `/v1` at the end of the Base URL and no slash after it: n8n adds the path of each call to it. On save, n8n tests the credential with `GET https://api.relayswitch.io/v1/models`; a green check means the key and the URL are right. The credential sends the key as `Authorization: Bearer`, which is what RelaySwitch reads.

Name the credential something you will recognise in a node, such as _RelaySwitch_. Every node that picks it uses this key, so a second credential with a second key is how one n8n instance keeps two teams' spend apart.

## 03Use it in an AI Agent with the OpenAI Chat Model

1.  Add an **AI Agent** node. It needs a chat model and at least one tool sub-node connected.
2.  As its chat model, add **OpenAI Chat Model** and select the RelaySwitch credential.
3.  **Model**: the list is loaded from `/models` on the credential's Base URL, so it shows the catalog. Type to filter by id, for example `claude-haiku-5-5`.
4.  Leave **Use Responses API** off. The node then sends Chat Completions, which every chat model on the key answers. The built-in tools behind that toggle (Web Search, File Search, Code Interpreter) run on OpenAI's side; give the agent n8n's own tool nodes instead.
5.  Under options, set **Maximum Number of Tokens** for the answer length and **Max Retries** to 2. Raise **Timeout** for long answers from reasoning models.

The AI Agent works as a tools agent, so pick a model that calls tools, such as the ones in the table below. The same credential works in the **OpenAI** app node (Text, Generate a Chat Completion) for a single prompt without an agent, and in the **HTTP Request** node as the predefined OpenAI credential for an endpoint the nodes do not cover, such as `https://api.relayswitch.io/v1/catalog`.

A request the node would send, from a terminal:

bash

1`curl -i https://api.relayswitch.io/v1/chat/completions \`

2 `-H "Authorization: Bearer sk-relay-..." \`

3 `-H "Content-Type: application/json" \`

4 `-d '{"model": "claude-haiku-5-5", "max_tokens": 16, "messages": [{"role": "user", "content": "Say ok."}]}'`

## 04Which model to pick for a workflow

An agent execution in a workflow is short and frequent: a system message, tool definitions and one tool result in, a few hundred tokens out. At 4,000 tokens in and 400 out, one execution costs:

| Model | One execution | 1,000 a day |
| --- | --- | --- |
| [Claude Haiku 5.5](https://relayswitch.io/models/claude-haiku-5-5) | $0.0003 | $0.30 |
| [GLM 5.3](https://relayswitch.io/models/glm-5.3) | $0.0017 | $1.72 |
| [Gemini 3.8 Flash](https://relayswitch.io/models/gemini-3.8-flash) | $0.0029 | $2.87 |
| [DeepSeek V4 Pro 0423](https://relayswitch.io/models/deepseek-v4-pro) | $0.0041 | $4.12 |
| [Claude Sonnet 5.5](https://relayswitch.io/models/claude-sonnet-5-5) | $0.006 | $6.00 |
| [GPT-5.5](https://relayswitch.io/models/gpt-5.5) | $0.0108 | $10.80 |

Start routing, classification and extraction steps on the lowest-priced row, [Claude Haiku 5.5](https://relayswitch.io/models/claude-haiku-5-5): 1,000 executions cost $0.30. Move a step to a larger model only where its answers fall short.

| Model | Input | Cached | Output | Developer list in / out | Context |
| --- | --- | --- | --- | --- | --- |
| [Claude Sonnet 5.5](https://relayswitch.io/models/claude-sonnet-5-5) | $1.20 (40% under) | $0.075 | $3.00 (70% under) | $2.00 / $10.00 | 1M tokens |
| [GPT-5.5](https://relayswitch.io/models/gpt-5.5) | $1.80 (64% under) | $0.16 | $9.00 (70% under) | $5.00 / $30.00 | 1.1M tokens |
| [Gemini 3.8 Flash](https://relayswitch.io/models/gemini-3.8-flash) | $0.4925 (34% under) | $0.0493 | $2.25 (40% under) | $0.75 / $3.75 | 1M tokens |
| [DeepSeek V4 Pro 0423](https://relayswitch.io/models/deepseek-v4-pro) | $0.792 (40% under) | $0.0264 | $2.376 (40% under) | $1.32 / $3.96 | 1M tokens |
| [GLM 5.3](https://relayswitch.io/models/glm-5.3) | $0.3276 (70% under) | $0.068 | $1.0296 (70% under) | $1.092 / $3.432 | 1M tokens |
| [Claude Haiku 5.5](https://relayswitch.io/models/claude-haiku-5-5) | $0.06 (40% under) | $0.01 | $0.15 (70% under) | $0.10 / $0.50 | 1M tokens |

USD per million tokens, read from the RelaySwitch catalog when this page was built. Developer list: the catalog's record of the developer's own price.

## 05A key for n8n alone, with a budget

Give n8n its own key instead of the one you use elsewhere. A key carries a prepaid budget in USD, an allowed-model list, a Requests / min and tokens / min limit, a monthly cap and an expiry. The budget is a hard stop for that key: the balance is what is debited, and when the key reaches its budget it answers `402` while every other key on the account keeps running. In the [console](https://app.relayswitch.io/console), open Keys, create a key named `n8n`, set its budget and tick the models it may call. Or do the whole thing by API with an admin key:

bash

1`# $ADMIN_KEY is an admin key, created once in the console (Keys, "Admin key").`

2`curl https://api.relayswitch.io/v1/keys \`

3 `-H "Authorization: Bearer $ADMIN_KEY" \`

4 `-H "Content-Type: application/json" \`

5 `-d '{"name": "n8n", "budget_usd": 20, "rpm": 60, "monthly_cap_usd": 100,`

6 `"allowed_models": ["claude-sonnet-5-5", "gpt-5.5", "gemini-3.8-flash"]}'`

7

8`# 201: the full key, once, with its record.`

9`# {"key": "sk-relay-...", "data": {"id": "k7m2...", "budget_micro": 20000000,`

10`# "budget_spent_micro": 0, "budget_remaining_micro": 20000000, ...}}`

An admin key manages keys through `GET`, `POST`, `PATCH` and `DELETE https://api.relayswitch.io/v1/keys` and cannot call a model, so a leaked admin key spends nothing. Put the key the call returns where n8n reads it, and watch the agent's spend on its own line:

bash

1`# Requests and spend today, this month and in all, and what is left of the budget.`

2`curl https://api.relayswitch.io/v1/keys/KEY_ID/usage -H "Authorization: Bearer $ADMIN_KEY"`

3

4`# Raise the budget (never under what is spent), narrow the models, pause or resume.`

5`curl -X PATCH https://api.relayswitch.io/v1/keys/KEY_ID \`

6 `-H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \`

7 `-d '{"budget_usd": 40, "status": "active"}'`

`POST https://api.relayswitch.io/v1/keys` takes `name` and, optionally, `allowed_models`, `rpm`, `tpm`, `monthly_cap_usd`, `budget_usd` and `expires_at` (Unix milliseconds). `PATCH` takes the same fields plus `status`; a budget may go up or down but never under what the key has spent, and `null` removes it. The shapes are in the [docs](https://relayswitch.io/docs#key-api) and in the OpenAPI document under the `keys` tag.

## 06Sessions, caps and tools for long runs

Tag a run with an `x-session-id` header and the API groups its requests into one session: `GET https://api.relayswitch.io/v1/sessions/:id` lists every step with its model, tokens, cost and latency, and log export sends the run to Langfuse or any OTLP backend as one trace. In n8n, an HTTP Request node can call `https://api.relayswitch.io/v1/chat/completions` directly with the header set from the execution id, so each workflow run is one session, and with `web_search_options` in the body the model searches the web inside that call:

json

1`// HTTP Request node: POST https://api.relayswitch.io/v1/chat/completions`

2`// Headers: Authorization = Bearer sk-relay-...`

3`// x-session-id = {{ $execution.id }}`

4`// Body (JSON):`

5`{`

6 `"model": "claude-sonnet-5-5",`

7 `"web_search_options": {},`

8 `"messages": [{ "role": "user", "content": "{{ $json.question }}" }]`

9`}`

With a session id on the requests, the key's session caps apply to each run: `session_max_requests` per sliding hour, `session_max_spend_usd` per UTC day, and `loop_guard`, which refuses a session's sixth identical call inside 10 minutes. A stuck n8n run stops there; the rest of the key keeps working.

bash

1`# Session caps and the loop guard on the agent's key (admin key).`

2`curl -X PATCH https://api.relayswitch.io/v1/keys/KEY_ID \`

3 `-H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \`

4 `-d '{"session_max_requests": 300, "session_max_spend_usd": 5, "loop_guard": true}'`

Any request that declares web search ($0.01 a search), web fetch, a code sandbox ($0.05 a container-hour, 1-minute minimum) or a remote MCP server in the OpenAI or Anthropic tool shape has the tool run by the API inside the same call, with citations and a receipt per round. Details on [agent tools](https://relayswitch.io/features/agent-tools) and [observability](https://relayswitch.io/features/observability).

## 07Check the model is the one on the label

Every model in the catalog gets the same canary prompt each day and its answer is compared with the last one. The result is public at [https://api.relayswitch.io/v1/proof](https://api.relayswitch.io/v1/proof), no key needed, so before a long n8n run you can see whether the id you set answered as it did yesterday.

305 / 339Models unchanged on today’s check21 changed, 13 not reached; read 2026-11-02T10:05 UTC

Every request n8n sends has a signed receipt with the model, the billed tokens and the charge in USD, streamed or not. Fetch it by the request id from the response headers, and check the signature on the [Verify page](https://relayswitch.io/statements/verify):

bash

1`curl https://api.relayswitch.io/v1/requests/REQUEST_ID/receipt \`

2 `-H "Authorization: Bearer $RELAYSWITCH_API_KEY"`

## 08Errors and fixes

-   The credential test fails: the Base URL is missing `/v1`, has a trailing slash, or the key field still holds an OpenAI key. Run the curl above from the machine n8n runs on.
-   `401`: the key is wrong or revoked. Paste it again into the credential; keys start with `sk-relay-`.
-   `402`: the balance is empty, or the key reached its budget or monthly cap. Top up in the console or raise the key's budget.
-   `404` "No such model": the model id was typed by hand and does not match the catalog. Pick it from the list or copy it from the [Models page](https://relayswitch.io/models).
-   `429`: the key's Requests / min limit. Lower the workflow's concurrency or raise the limit on the key.
-   The agent answers with an empty message: a reasoning model spent Maximum Number of Tokens thinking. Raise it, or pick a non-reasoning model for that step.

## 09Sources

Field names and node options are from n8n's own docs and source, read 2026-10-30: [OpenAI credentials](https://docs.n8n.io/integrations/builtin/credentials/openai/), the credential's [definition in n8n's repository](https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/credentials/OpenAiApi.credentials.ts) (API Key, Organization ID, Base URL defaulting to `https://api.openai.com/v1`, Add Custom Header, and the `/models` test), [OpenAI Chat Model](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatopenai/), [AI Agent](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/) and the [OpenAI node](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/). The [Workflows page](https://relayswitch.io/workflows) covers chains of model calls run on the key itself.

## Questions

Can n8n use an OpenAI compatible API?

Yes. n8n's OpenAI credential has a Base URL field. Set it to https://api.relayswitch.io/v1 with a RelaySwitch key and the OpenAI Chat Model, the OpenAI node and the HTTP Request node send their calls there.

Where is the Base URL in n8n?

In the OpenAI credential, below API Key and Organization ID. It is prefilled with https://api.openai.com/v1; replace it with your provider’s address, keeping the /v1.

Can I use Claude or Gemini in n8n through the OpenAI node?

Yes, on RelaySwitch. The key answers OpenAI's Chat Completions format for every chat model in the catalog, so pick claude-sonnet-5-5 or gemini-3.8-flash in the OpenAI Chat Model's list like any GPT model.

How much does an n8n AI workflow cost?

The tokens it sends and receives, at the model's per-token price. At 4,000 tokens in and 400 out per agent execution, 1,000 executions a day cost $0.30 on claude-haiku-5-5. There is no subscription; the balance is prepaid.

Why does the AI Agent node need a tool?

n8n requires at least one tool sub-node on an AI Agent, and the agent works as a tools agent. For a single prompt with no tools, use the OpenAI node (Text, Generate a Chat Completion) or a Basic LLM Chain instead.

Related

-   [All guides](https://relayswitch.io/guides)
-   [LiteLLM](https://relayswitch.io/guides/litellm)
-   [Hermes Agent](https://relayswitch.io/guides/hermes-agent)
-   [SDKs](https://relayswitch.io/guides/sdks)
-   [Models and prices](https://relayswitch.io/models)
-   [Cost calculator](https://relayswitch.io/tools/llm-cost-calculator)
-   [How pricing works](https://relayswitch.io/pricing)
-   [Pay by card or crypto](https://relayswitch.io/pay-with-crypto)
-   [Docs](https://relayswitch.io/docs)

## Every model in one n8n credential

Prepaid from $10 by card or crypto. No KYC, no subscription.

[Models](https://relayswitch.io/models)[Get a key](https://app.relayswitch.io/console)

