OpenAI SDK

OpenAI Python SDK with an OpenAI-compatible uncensored API

Use the official openai Python package with Abliterator: set base_url and api_key, stream tokens, parse structured outputs and read per-request cost.

Reviewed OpenAI SDKPython

Quick answer

Create the client with OpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"]) and call client.chat.completions.create with an Abliterator model ID. Everything else in your code stays the same.

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_url and OPENAI_BASE_URL is unset, so the SDK used its default host. Pass base_url explicitly.
  • 404 on client.responses.create, client.embeddings.create or client.images.generate. Abliterator does not offer those endpoints. Only Chat Completions and the model list are available through this SDK.
  • LengthFinishReasonError from parse(). The model hit max_tokens before closing the JSON. Raise max_tokens or 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 with resp.usage.model_extra.get("cost").
  • Retries on 429. The SDK retries twice by default and honors Retry-After. Set max_retries on the client if your plan's concurrency limit needs more headroom; limits are on /pricing.

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.