Skip to main content

LangChain Integration

LangChain supports custom OpenAI-compatible endpoints. You can use Vexrail as the LLM provider in your LangChain application by configuring the base URL and custom headers.

JavaScript / TypeScript

Installation

npm install @langchain/openai

Setup

import { ChatOpenAI } from "@langchain/openai";

const model = new ChatOpenAI({
configuration: {
baseURL: "https://api.vexrail.com/v1",
defaultHeaders: {
"x-publishable-key": process.env.VEXRAIL_PUBLISHABLE_KEY,
"x-secret-key": process.env.VEXRAIL_SECRET_KEY,
"x-conversation-id": "your-conversation-id",
},
},
modelName: "gpt-4o-mini",
});

Usage

const response = await model.invoke("What tools can help me manage a remote team?");
console.log(response.content);

Streaming

const stream = await model.stream("Recommend a good project management tool.");

for await (const chunk of stream) {
process.stdout.write(chunk.content.toString());
}

Python

Installation

pip install langchain-openai

Setup

from langchain_openai import ChatOpenAI

model = ChatOpenAI(
base_url="https://api.vexrail.com/v1",
api_key="unused",
model="gpt-4o-mini",
default_headers={
"x-publishable-key": "pk_live_your_publishable_key",
"x-secret-key": "sk_live_your_secret_key",
"x-conversation-id": "your-conversation-id",
},
)

Usage

response = model.invoke("What tools can help me manage a remote team?")
print(response.content)

Streaming

for chunk in model.stream("Recommend a good project management tool."):
print(chunk.content, end="")

Using with Chains

Vexrail works with standard LangChain chains and agents. Any chain that uses a ChatOpenAI model can use Vexrail as its provider without modification to the chain logic.

import { ChatOpenAI } from "@langchain/openai";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";

const model = new ChatOpenAI({
configuration: {
baseURL: "https://api.vexrail.com/v1",
defaultHeaders: {
"x-publishable-key": process.env.VEXRAIL_PUBLISHABLE_KEY,
"x-secret-key": process.env.VEXRAIL_SECRET_KEY,
"x-conversation-id": "your-conversation-id",
},
},
modelName: "gpt-4o-mini",
});

const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful assistant."],
["human", "{input}"],
]);

const chain = prompt.pipe(model).pipe(new StringOutputParser());

const result = await chain.invoke({ input: "What is the best CRM for startups?" });
console.log(result);

Next Steps