OpenAI SDK
OpenAI Node SDK with an OpenAI-compatible uncensored API
Point the official openai npm package at Abliterator with baseURL and apiKey, stream tokens, run tools automatically with runTools, and read cost headers.
Create the client with new OpenAI({ baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY }) and call client.chat.completions.create with an Abliterator model ID.
The official openai package for Node.js and TypeScript works with Abliterator after you change two client options. The examples below were run with openai 7.65 on Node 22 as ES modules (save them as .mjs, or set "type": "module").
Install
npm install openai zod
export ABL_API_KEY="sk-abl-v1-..."
zod is only needed for the tool example. Get a key at /keys.
First request
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://abliterator.ai/v1",
apiKey: process.env.ABL_API_KEY,
});
const completion = await client.chat.completions.create({
model: "kimi-k3.1-pro-abliterated",
messages: [
{ role: "system", content: "You help a red team write rules of engagement." },
{ role: "user", content: "Draft the scope section for an authorized external pentest of example.com." },
],
max_tokens: 800,
});
console.log(completion.choices[0].message.content);
console.log("cost (USD):", completion.usage.cost);
usage.cost is an Abliterator extension. TypeScript does not know about it, so read it as (completion.usage as any).cost in .ts files.
Streaming
With stream: true the call returns an async iterable of chunks. The last chunk carries usage and an empty choices array:
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY });
const stream = await client.chat.completions.create({
model: "deepseek-v4.1-flash-abliterated",
messages: [{ role: "user", content: "Explain how DNS tunneling shows up in proxy logs." }],
stream: true,
});
for await (const chunk of stream) {
const text = chunk.choices[0]?.delta?.content;
if (text) process.stdout.write(text);
if (chunk.usage) console.log(`\n[${chunk.usage.completion_tokens} output tokens]`);
}
To cancel a stream early, break out of the loop or call stream.controller.abort(). The streaming guide covers the event format.
Automatic tool calls with runTools
runTools is specific to the Node SDK: it sends your tool schemas, validates the model's arguments with Zod, calls your function, appends the result and repeats until the model replies in text.
import OpenAI from "openai";
import { zodFunction } from "openai/helpers/zod";
import { z } from "zod";
const client = new OpenAI({ baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY });
const lookupCve = zodFunction({
name: "lookup_cve",
description: "Return the stored advisory for a CVE ID.",
parameters: z.object({ cve_id: z.string() }),
function: async ({ cve_id }) => ({
cve_id,
cvss: 9.8,
affected: "ExampleCMS < 4.2.1",
fixed_in: "4.2.1",
}),
});
const runner = client.chat.completions.runTools({
model: "kimi-k3.1-pro-abliterated",
messages: [{ role: "user", content: "Look up CVE-2024-0001 and tell me whether patching can wait a week." }],
tools: [lookupCve],
});
runner.on("functionToolCall", (call) => console.log("tool call:", call.name, call.arguments));
console.log(await runner.finalContent());
For one-shot calls without the loop, pass tools to create() and handle message.tool_calls yourself, as in /docs/tool-calling.
Read the Abliterator headers
.withResponse() returns the parsed body and the raw Response, so you can log X-Abl-Generation-Id and X-Abl-Cost-Usd:
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY });
const { data, response } = await client.chat.completions
.create({
model: "deepseek-v4.1-flash-abliterated",
messages: [{ role: "user", content: "Define lateral movement in one sentence." }],
})
.withResponse();
console.log(response.headers.get("x-abl-generation-id"), response.headers.get("x-abl-cost-usd"));
console.log(data.choices[0].message.content);
Troubleshooting
OpenAIError: Missing credentials. Please pass an apiKey....process.env.ABL_API_KEYwas undefined, so the SDK looked forOPENAI_API_KEYand found nothing. Export the key in the same shell, or load it withnode --env-file=.env.- Requests reach api.openai.com. Check the spelling
baseURL.baseUrlandbase_urlare silently ignored. - 404 from
client.responses.createorclient.embeddings.create. Those endpoints are not available on Abliterator; useclient.chat.completions. runToolsnever finishes. The model keeps calling tools. PassmaxChatCompletions(default 10) to cap the loop, and make each tool return a result the model can act on.- Edge runtimes. The SDK works on Cloudflare Workers, Vercel Edge, Deno and Bun with the same two options; read the key from the platform's env binding rather than
process.envwhere that does not exist.
Frequently asked questions
Is the option baseURL or base_url in JavaScript?
baseURL, camel case with a capital URL. The Python SDK uses base_url. A misspelled option is ignored at runtime, so the client silently falls back to OPENAI_BASE_URL or api.openai.com.
Does runTools work with Abliterator?
Yes. runTools sends standard Chat Completions tool definitions, runs your functions locally and loops until the model answers in text. Abliterator passes the tools to the model unchanged.
Can I run this in the browser?
Only with dangerouslyAllowBrowser: true, which exposes your key to every visitor. Call Abliterator from a server route instead and stream the result to the page.