One base URL change, three frameworks
n8n, LangChain, and LlamaIndex all speak the OpenAI-compatible API. That means you can point them at any OpenAI-compatible gateway by changing the base URL and API key — no custom integration code. This guide shows the exact setting in each, using APIVAI (which resells Claude and GPT at a steep discount) as the endpoint.
The APIVAI base URL is https://api.apivai.com/v1. Pick a model from /v1/models before hardcoding a name.
n8n
In n8n, the OpenAI nodes (and the AI Agent / Chat Model nodes) accept a custom credential. Create an "OpenAI" credential and set:
- API Key: your APIVAI key
- Base URL:
https://api.apivai.com/v1
Then choose a model ID returned by /v1/models in the node. Existing n8n OpenAI nodes and agent workflows keep working — only the credential changed. This is the fastest way to run cheaper models inside automation flows.
LangChain (Python)
LangChain's ChatOpenAI takes a base_url and api_key. Set them and you are done.
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(base_url="https://api.apivai.com/v1", api_key="YOUR_APIVAI_API_KEY", model="claude-sonnet-4-6")
print(llm.invoke("Write one sentence about API gateways.").content)
The same pattern works for chains, agents, and tool calling — anything built on ChatOpenAI inherits the endpoint.
LangChain (JavaScript)
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({ model: "claude-sonnet-4-6", apiKey: "YOUR_APIVAI_API_KEY", configuration: { baseURL: "https://api.apivai.com/v1" } });
const res = await llm.invoke("Write one sentence about API gateways.");
console.log(res.content);
LlamaIndex (Python)
LlamaIndex's OpenAI-compatible LLM wrapper accepts an api_base.
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(model="claude-sonnet-4-6", api_base="https://api.apivai.com/v1", api_key="YOUR_APIVAI_API_KEY", is_chat_model=True)
print(llm.complete("Write one sentence about API gateways."))
Verify before you build
Whatever framework you use, run a tiny request first to confirm the endpoint, key, and model are wired correctly. A 401 means the key is not being read; a 404 usually means the base URL is missing /v1; a model error means the configured name is not in the current /v1/models response.
Get started
Create an APIVAI key, drop the base URL into your n8n credential or your ChatOpenAI / OpenAILike config, pick a model from /v1/models, and your existing framework code runs against cheaper models with no rewrite.
Top comments (0)