LangChain.js

LangChain.js with an OpenAI-compatible uncensored API

Configure @langchain/openai ChatOpenAI for Abliterator with configuration.baseURL, stream tokens, run a createAgent tool agent and get Zod-typed structured output.

Reviewed LangChainJavaScript

Quick answer

Create new ChatOpenAI({ model: "kimi-k3.1-pro-abliterated", apiKey: process.env.ABL_API_KEY, configuration: { baseURL: "https://abliterator.ai/v1" } }). The base URL lives inside configuration, not at the top level.

In LangChain.js, OpenAI-compatible servers are reached through ChatOpenAI from @langchain/openai. The one detail that differs from Python: the base URL sits under configuration, as the LangChain.js ChatOpenAI docs show. Examples were run with langchain 1.6, @langchain/openai 1.8 and Node 22 as ES modules.

Install

npm install langchain @langchain/openai @langchain/core zod
export ABL_API_KEY="sk-abl-v1-..."

Connect ChatOpenAI to Abliterator

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

const llm = new ChatOpenAI({
  model: "kimi-k3.1-pro-abliterated",
  apiKey: process.env.ABL_API_KEY,
  configuration: { baseURL: "https://abliterator.ai/v1" },
  maxTokens: 1024,
});

const reply = await llm.invoke([
  ["system", "You are an application security reviewer."],
  ["human", "List the checks you would run on a JWT implementation during an authorized assessment."],
]);
console.log(reply.content);
console.log(reply.usage_metadata);

Streaming

.stream() yields AIMessageChunks. Concatenating them with .concat() gives one message whose usage_metadata comes from Abliterator's closing usage event:

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

const llm = new ChatOpenAI({
  model: "deepseek-v4.1-flash-abliterated",
  apiKey: process.env.ABL_API_KEY,
  configuration: { baseURL: "https://abliterator.ai/v1" },
});

let full;
for await (const chunk of await llm.stream("Explain the difference between EDR and XDR telemetry in five bullets.")) {
  process.stdout.write(typeof chunk.content === "string" ? chunk.content : "");
  full = full ? full.concat(chunk) : chunk;
}
console.log("\n", full.usage_metadata);

streamUsage defaults to true in LangChain.js, so you do not need to set it.

A tool agent with createAgent

createAgent from the langchain package runs the model-tool loop for you. Tools are defined with tool() and a Zod schema:

import { createAgent, tool } from "langchain";
import { ChatOpenAI } from "@langchain/openai";
import { z } from "zod";

const whois = tool(
  async ({ domain }) => `${domain}: registered 2026-11-20, privacy-protected, NS at a bulletproof host`,
  {
    name: "whois_lookup",
    description: "Return cached WHOIS facts for a domain.",
    schema: z.object({ domain: z.string() }),
  },
);

const llm = new ChatOpenAI({
  model: "kimi-k3.1-pro-abliterated",
  apiKey: process.env.ABL_API_KEY,
  configuration: { baseURL: "https://abliterator.ai/v1" },
});

const agent = createAgent({
  model: llm,
  tools: [whois],
  systemPrompt: "You triage suspicious domains for a phishing response team.",
});

const result = await agent.invoke({
  messages: [{ role: "user", content: "Should we block login-verify-account.example? Check it first." }],
});
console.log(result.messages.at(-1).content);

Structured output with Zod

withStructuredOutput returns parsed objects instead of messages:

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

const Advisory = z.object({
  title: z.string(),
  severity: z.enum(["low", "medium", "high", "critical"]),
  mitigations: z.array(z.string()),
});

const llm = new ChatOpenAI({
  model: "kimi-k3.1-pro-abliterated",
  apiKey: process.env.ABL_API_KEY,
  configuration: { baseURL: "https://abliterator.ai/v1" },
});

const advisory = await llm
  .withStructuredOutput(Advisory, { name: "advisory" })
  .invoke("Write a short internal advisory about an exposed Redis instance with no auth.");
console.log(advisory.severity, advisory.mitigations);

Use z.nullable() rather than z.optional() for fields the model may leave empty; strict JSON schemas cannot have optional properties.

Troubleshooting

  • The request goes to api.openai.com. baseURL was set at the top level of the constructor. Move it into configuration.
  • 404 on /v1/responses. ChatOpenAI switches to the Responses API when useResponsesApi: true is set, when you bind a built-in tool such as web search, or when you pass text, truncation, include, previous_response_id or reasoning.summary. Abliterator only serves Chat Completions, so drop those options.
  • OpenAIError: Missing credentials. apiKey was undefined because ABL_API_KEY is not exported in the process environment. LangChain then looked for OPENAI_API_KEY.
  • Agent stops with a recursion error. The model kept calling tools. Make tool outputs conclusive, or raise the limit with agent.withConfig({ recursionLimit: 50 }).
  • Deprecation warnings for modelName. It is an old alias. Use model, and apiKey instead of openAIApiKey.

Frequently asked questions

Where does the base URL go in LangChain.js?

Inside configuration: new ChatOpenAI({ configuration: { baseURL } }). configuration is passed straight to the OpenAI SDK client, so baseURL, defaultHeaders and timeout options all go there.

Does LangChain.js keep the reasoning text Abliterator returns?

Yes. The Chat Completions converter copies a reasoning_content field into additional_kwargs.reasoning_content on the message and on stream chunks, while content holds the answer.

Can I use createAgent from the langchain package with Abliterator?

Yes. createAgent calls the model with standard tool definitions and runs your tools between turns. Pass it the ChatOpenAI instance rather than a model string, so it uses your Abliterator base URL.