*Disclosure: I work on the APIGOTO team. APIGOTO is an independent OpenAI-compatible API gateway and isn’t affiliated with OpenAI, Anthropic or Google. I use it as the example below, but every step works with any OpenAI-compatible endpoint (a self-hosted proxy, LiteLLM, vLLM, LM Studio, etc.).*
I’ve seen a few threads asking how to use Claude- or Gemini-family models (or a local model) through n8n’s OpenAI nodes, so here’s what I’ve learned setting it up.
## 1. Set the Base URL on the credential
The built-in **OpenAI** credential has a **Base URL** field, not just API Key. It defaults to `https://api.openai.com/v1\`.
1. **Credentials → Add credential → OpenAI**
2. **API Key**: the key from your provider
3. **Organization ID (optional)**: leave it empty for non-OpenAI endpoints
4. **Base URL**: your endpoint, including `/v1`. For APIGOTO that’s `正在跳转 - APIGOTO
5. Save. n8n runs a quick test request against the endpoint.
The same credential is used by the **OpenAI** node, the **OpenAI Chat Model** sub-node (for AI Agent / Basic LLM Chain), **Embeddings OpenAI** and **LM OpenAI**.
There’s also an **Add Custom Header** toggle on the credential if your proxy wants an extra header.
## 2. Or override it per node
The **OpenAI Chat Model** sub-node has **Options → Base URL**. That’s handy if you want one credential but different endpoints in different workflows. The node option wins over the credential.
## 3. Picking the model
- **From List** calls `GET {base_url}/models`. When the Base URL isn’t `api.openai.com`, n8n doesn’t filter the list to `gpt-*` models, so you see everything the endpoint returns.
- If the endpoint returns a huge list or doesn’t implement `/models`, switch the Model field to **ID** and paste the exact model ID.
- With APIGOTO, use a model ID from your APIGOTO dashboard. I’ll write it as `MODEL_ID` here rather than guessing names.
## 4. Gotchas I ran into
**Tool calling depends on the model, not on n8n.** When you set a Base URL, n8n shows a notice that non-OpenAI models might not be chat-compatible or support tool calling or JSON response format. If your AI Agent ignores its tools or errors on the first tool call, test the same model with a plain Basic LLM Chain first. If that works, the model (or the route to it) probably doesn’t support `tools`.
**JSON / structured output.** Same story with **Response Format → JSON Schema / JSON Object**. Some models follow it, some don’t. A Structured Output Parser after the chain is more portable.
**Responses API toggle.** Newer node versions have **Use Responses API** and built-in tools (Web Search, File Search, Code Interpreter). Those are OpenAI-specific. With a third-party endpoint, leave them off unless your provider says it supports `/responses`.
**Streaming.** If you stream into the Chat Trigger, test it end to end. Some proxies buffer the whole response, and some models stream tool calls differently. If streaming gets flaky, turn it off first while you debug.
**Retries stack up.** Three layers can retry the same request:
- the OpenAI Chat Model node’s own **Options → Max Retries** (defaults to 2) and **Timeout**,
- the node’s **Settings → Retry On Fail** (Max Tries / Wait Between Tries),
- your gateway, if it does failover. APIGOTO retries a failed request on another route, at most 3 times.
Stack all three and one bad call can turn into a lot of attempts and a long wait before the workflow errors. I keep the gateway’s failover, set node Max Retries to 0 or 1, and only enable Retry On Fail on nodes where a late success is still useful. Also raise **Timeout** for long generations so n8n doesn’t give up while the gateway is still retrying.
**Debugging.** When something’s off, the per-request log on the gateway side is usually faster than n8n’s execution view. You see the exact payload, which model answered, and the error body. APIGOTO keeps per-request logs. Most self-hosted proxies can do this too.
## Minimal test
Before you build anything, check the endpoint with curl:
```bash
curl https://api.china-aiapi.com/v1/chat/completions \
-H “Authorization: Bearer $API_KEY” \
-H “Content-Type: application/json” \
-d ‘{“model”:“MODEL_ID”,“messages”:[{“role”:“user”,“content”:“ping”}]}’
```
If that works, an AI Agent → OpenAI Chat Model (Model: **ID** = `MODEL_ID`) → Chat Trigger should work too.
-–
About APIGOTO, since I mentioned it: one OpenAI-compatible `base_url` for Claude, GPT and Gemini model families, automatic failover (max 3 retries), per-request logs, BYOK supported, pay-as-you-go, and docs in English and Chinese. Details at [www.china-aiapi.com](正在跳转 - APIGOTO). Happy to answer setup questions here, including ones about other endpoints.