LangChain
Configure ChatOpenAI with a TheRouter key and the TheRouter base URL. Keep the key on your server and choose a model supported by your account.
TypeScript
bash
npm install @langchain/openai @langchain/coretypescript
import { ChatOpenAI } from "@langchain/openai";
const model = new ChatOpenAI({
model: "openai/gpt-4o-mini",
apiKey: process.env.THEROUTER_API_KEY,
configuration: { baseURL: "https://api.therouter.ai/v1" },
maxTokens: 64,
});
const result = await model.invoke("Hello!");
console.log(result.content);The example was checked with a local mock endpoint; the underlying Chat Completions API was separately tested against TheRouter. See the LangChain documentation and model catalog. Test advanced parameters with your model.