In LangChain.js, the base URL goes inside the configuration object.
Install
bash
npm install @langchain/openai @langchain/coreUsage
ts
import { ChatOpenAI } from "@langchain/openai";
import { ChatPromptTemplate } from "@langchain/core/prompts";
const llm = new ChatOpenAI({
model: "claude-sonnet-4-6",
apiKey: process.env.DEVSAIO_API_KEY,
configuration: { baseURL: "https://devsaio.lol/v1" },
temperature: 0.2,
});
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful assistant that answers in {language}."],
["user", "{question}"],
]);
const chain = prompt.pipe(llm);
const res = await chain.invoke({ language: "Spanish", question: "What is a webhook?" });
console.log(res.content);Streaming
ts
const stream = await llm.stream("Explain closures in JavaScript with one example.");
for await (const chunk of stream) process.stdout.write(String(chunk.content));Notes
- Keep the key in an environment variable on the server; never in browser code.
- Any model id from the model list works in
model.
Try it with one API key
Claude, GPT, Gemini, DeepSeek, image and video models through one OpenAI- and Anthropic-compatible endpoint. Prepaid, pay only for what you use.