DEV Community

OpenUncensored Team
OpenUncensored Team

Posted on Fully Autonomous

An OpenAI-compatible API for abliterated models: Python and Node SDK code for streaming and tools

Yes, there is an OpenAI-compatible API for abliterated models. OpenUncensored serves 61 uncensored text models at https://api.openuncensored.com/v1, 25 of them abliterated (plain abliteration, heretic, derestricted or orthogonalized), and the official openai packages for Python and Node work unchanged. This post is the code: setup, streaming, a full tool loop, the Responses API and error handling.

Setup

Get a prepaid key on the credits page (card or crypto, no account), then:

pip install openai     # Python
npm install openai     # Node
export OU_API_KEY=ou-...

# every model id, free, no key needed
curl https://api.openuncensored.com/v1/models
Enter fullscreen mode Exit fullscreen mode
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.openuncensored.com/v1", api_key=os.environ["OU_API_KEY"])
MODEL = "inkling-2-small-uncensored"  # orthogonalized Inkling 2 Small, #3 on our leaderboard
Enter fullscreen mode Exit fullscreen mode
// main.mjs (Node 18+)
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.openuncensored.com/v1", apiKey: process.env.OU_API_KEY });
const MODEL = "inkling-2-small-uncensored";
Enter fullscreen mode Exit fullscreen mode

Streaming

Server-sent events in the OpenAI format, with token usage in the last chunk.

stream = client.chat.completions.create(
    model=MODEL,
    messages=[{"role": "user", "content": "Explain how a stack buffer overflow is exploited, step by step."}],
    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]")
Enter fullscreen mode Exit fullscreen mode
const stream = await client.chat.completions.create({
  model: MODEL,
  messages: [{ role: "user", content: "Write a noir scene where a safecracker explains his craft." }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
  if (chunk.usage) console.log(`\n[${chunk.usage.prompt_tokens} in, ${chunk.usage.completion_tokens} out]`);
}
Enter fullscreen mode Exit fullscreen mode

Tool calling

Tools go in the standard tools field. Both loops below run a real DNS lookup: the model calls the tool, you run it, send the result back, and repeat until it answers.

import json, socket

tools = [{"type": "function", "function": {
    "name": "dns_lookup",
    "description": "Resolve a domain to its IPv4 addresses",
    "parameters": {"type": "object", "properties": {"domain": {"type": "string"}}, "required": ["domain"]},
}}]

def dns_lookup(domain: str) -> dict:
    return {"domain": domain, "a": socket.gethostbyname_ex(domain)[2]}

messages = [{"role": "user", "content": "Which IPs do example.com and example.org resolve to?"}]
while True:
    msg = client.chat.completions.create(model=MODEL, messages=messages, tools=tools).choices[0].message
    if not msg.tool_calls:
        print(msg.content)
        break
    messages.append(msg)
    for call in msg.tool_calls:
        result = dns_lookup(**json.loads(call.function.arguments))
        messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)})
Enter fullscreen mode Exit fullscreen mode
import { resolve4 } from "node:dns/promises";

const tools = [{
  type: "function",
  function: {
    name: "dns_lookup",
    description: "Resolve a domain to its IPv4 addresses",
    parameters: { type: "object", properties: { domain: { type: "string" } }, required: ["domain"] },
  },
}];

const messages = [{ role: "user", content: "Which IPs do example.com and example.org resolve to?" }];
while (true) {
  const r = await client.chat.completions.create({ model: MODEL, messages, tools });
  const msg = r.choices[0].message;
  if (!msg.tool_calls?.length) { console.log(msg.content); break; }
  messages.push(msg);
  for (const call of msg.tool_calls) {
    const { domain } = JSON.parse(call.function.arguments);
    const result = { domain, a: await resolve4(domain) };
    messages.push({ role: "tool", tool_call_id: call.id, content: JSON.stringify(result) });
  }
}
Enter fullscreen mode Exit fullscreen mode

tool_choice and parallel tool calls pass through, and tool call arguments stream in the OpenAI delta format if you add stream: true.

The Responses API

/v1/responses is there too, for code and agents built on OpenAI's newer API (the Codex CLI uses it):

resp = client.responses.create(model=MODEL, input="Summarise how phishing kits work, for a security awareness deck.")
print(resp.output_text)
Enter fullscreen mode Exit fullscreen mode

It is stateless: send the whole conversation in input each turn.

Errors and credit

Errors come back in the OpenAI shape, so the SDK's exceptions work as usual:

import openai

try:
    client.chat.completions.create(model=MODEL, messages=[{"role": "user", "content": "Hello"}])
except openai.APIStatusError as e:
    if e.status_code == 402:    # insufficient_quota: the prepaid credit is used up
        print("Top up the same key at https://openuncensored.com/credits")
    elif e.status_code == 429:  # rate limit, or more than 32 requests in flight on one key
        print("Back off and retry")
    else:
        raise
Enter fullscreen mode Exit fullscreen mode

Check what is left with curl https://api.openuncensored.com/v1/credits -H "Authorization: Bearer $OU_API_KEY", which returns remaining_usd. A prepaid key cannot overspend: when the credit runs out, requests stop with 402.

Pick an abliterated model

Model id Method Rank (score) Answered (of 36) $ / 1M in · out
inkling-2-small-uncensored Orthogonalized #3 (79.0) 34 $0.60 · $2.40
kimi-k3.1-pro-uncensored Abliterated #4 (78.1) 34 $1.50 · $3.00
inkling-2-mini-uncensored Orthogonalized #6 (75.7) 33 $0.15 · $0.60
abliterated-large-flash Abliterated #7 (74.5) 33 $1.00 · $2.00
deepseek-v4.1-flash-1017-heretic Heretic #11 (73.1) 34 $0.20 · $0.79
gemma-4-26b-a4b-it-chimeraxheretic Heretic #22 (56.1) 36 $0.12 · $0.38

Rank is on our uncensored LLM leaderboard. "Answered" is how many of 36 edgy test requests the model answered.

Everything built on the OpenAI SDK

  • LangChain: ChatOpenAI(model=MODEL, base_url="https://api.openuncensored.com/v1", api_key=os.environ["OU_API_KEY"])
  • LiteLLM: litellm.completion(model="openai/inkling-2-small-uncensored", api_base="https://api.openuncensored.com/v1", api_key=...)
  • Vercel AI SDK: createOpenAICompatible({ name: "openuncensored", baseURL: "https://api.openuncensored.com/v1", apiKey: process.env.OU_API_KEY })
  • Routing: most models have several hosts. Add extra_body={"routing": {"strategy": "cheapest"}} in Python (or routing: { strategy: "cheapest" } in the Node request) to try the cheapest first, with fallback to the next.

Claude Code and the Anthropic SDKs use the Anthropic Messages API on the same key, with base URL https://api.openuncensored.com.

More: OpenAI-compatible uncensored API, API docs, every model and price.

Originally published at openuncensored.com.

Top comments (0)