OpenAI SDK with Abliterator: Python and JavaScript
Use the official OpenAI Python and Node SDKs with Abliterator: set the base URL and key, stream tokens, run tools, parse structured output and read cost.
Python: OpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"]). JavaScript: new OpenAI({ baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY }). Then call chat.completions.create with an Abliterator model ID; the rest of your code stays the same.
This page covers Python and JavaScript. Each section is complete on its own, with install steps, a first request, streaming and the OpenAI SDK-specific settings that trip people up. For what the OpenAI-compatible endpoint supports and which other clients work with it, see OpenAI-compatible uncensored API.
Python
The official openai Python package talks to any server that implements Chat Completions. Point base_url at Abliterator, pass your Abliterator key, and use an Abliterator model ID. These examples were run against openai 3.60.
Install
pip install openai
export ABL_API_KEY="sk-abl-v1-..."
Create a key at /keys. The examples read it from ABL_API_KEY so the key never lands in source control.
First request
import os
from openai import OpenAI
client = OpenAI(
base_url="https://abliterator.ai/v1",
api_key=os.environ["ABL_API_KEY"],
)
resp = client.chat.completions.create(
model="kimi-k3.1-pro-abliterated",
messages=[
{"role": "system", "content": "You are a malware analyst writing for a SOC team."},
{"role": "user", "content": "Explain what process hollowing is and which telemetry reveals it."},
],
max_tokens=800,
)
print(resp.choices[0].message.content)
print("cost (USD):", resp.usage.model_extra.get("cost"))
base_url must end in /v1. The SDK appends /chat/completions itself, so https://abliterator.ai/v1/chat/completions would produce a doubled path and a 404. Swap kimi-k3.1-pro-abliterated for deepseek-v4.1-flash-abliterated when you want the cheaper model; see /models for the differences.
Streaming
Pass stream=True and iterate. Abliterator always ends a stream with a usage chunk that has an empty choices list, so guard the index:
import os
from openai import OpenAI
client = OpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"])
stream = client.chat.completions.create(
model="deepseek-v4.1-flash-abliterated",
messages=[{"role": "user", "content": "List five Sigma rule ideas for detecting credential dumping."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage:
print(f"\n[{chunk.usage.prompt_tokens} in / {chunk.usage.completion_tokens} out]")
You do not need stream_options={"include_usage": True}; Abliterator adds it. AsyncOpenAI works the same way with async for. More on the event format in /docs/streaming.
Structured output with parse()
client.chat.completions.parse turns a Pydantic model into a json_schema response format and validates the reply for you:
import os
from openai import OpenAI
from pydantic import BaseModel
class Finding(BaseModel):
technique_id: str
name: str
severity: str
detection: str
class Triage(BaseModel):
summary: str
findings: list[Finding]
client = OpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"])
completion = client.chat.completions.parse(
model="kimi-k3.1-pro-abliterated",
messages=[
{"role": "system", "content": "Map the log excerpt to MITRE ATT&CK techniques."},
{"role": "user", "content": "powershell.exe -enc JABzAD0A... spawned by winword.exe, then rundll32 contacting a new domain"},
],
response_format=Triage,
)
triage = completion.choices[0].message.parsed
for f in triage.findings:
print(f.technique_id, f.name, f.severity)
Tool calling uses the standard tools parameter and works the same way; see /docs/tool-calling for a full loop.
Read the Abliterator headers
Every response carries X-Abl-Generation-Id, X-Abl-Model and, for non-streaming calls, X-Abl-Cost-Usd. The SDK hides headers unless you ask for the raw response:
import os
from openai import OpenAI
client = OpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"])
raw = client.chat.completions.with_raw_response.create(
model="deepseek-v4.1-flash-abliterated",
messages=[{"role": "user", "content": "One sentence on what a YARA rule is."}],
)
print(raw.headers.get("X-Abl-Generation-Id"), raw.headers.get("X-Abl-Cost-Usd"))
resp = raw.parse()
print(resp.choices[0].message.content)
Troubleshooting
- 401 that mentions platform.openai.com. The request went to OpenAI: the client was created without
base_urlandOPENAI_BASE_URLis unset, so the SDK used its default host. Passbase_urlexplicitly. - 404 on
client.responses.create,client.embeddings.createorclient.images.generate. Abliterator does not offer those endpoints. Only Chat Completions and the model list are available through this SDK. LengthFinishReasonErrorfromparse(). The model hitmax_tokensbefore closing the JSON. Raisemax_tokensor shrink the schema.- Type checker rejects
resp.usage.cost. The field works at runtime but is not in the SDK's type stubs, so mypy and Pyright flag it. Read it withresp.usage.model_extra.get("cost"). - Retries on 429. The SDK retries twice by default and honors
Retry-After. Setmax_retrieson the client if your plan's concurrency limit needs more headroom; limits are on /pricing.
JavaScript
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
Does client.responses.create work with Abliterator?
No. Abliterator serves Chat Completions, not the Responses API, so client.responses.create returns 404. Use client.chat.completions.create, or client.chat.completions.parse for typed output.
How do I see what a request cost from Python?
Every non-streaming response carries usage.cost in USD, which the SDK keeps as an extra field on resp.usage. Streams put the same usage object on the final chunk. The X-Abl-Cost-Usd header is available through client.chat.completions.with_raw_response.create.
Can I keep OPENAI_API_KEY set for other code?
Yes, as long as you pass api_key and base_url explicitly. The SDK only falls back to OPENAI_API_KEY and OPENAI_BASE_URL when those arguments are missing.
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.