Anthropic SDK with Abliterator: Python and TypeScript
Use the official Anthropic Python and TypeScript SDKs with Abliterator's Messages API: base URL without /v1, streaming, tool use and forced tool output.
Python: Anthropic(base_url="https://abliterator.ai", api_key=os.environ["ABL_API_KEY"]). TypeScript: new Anthropic({ baseURL: "https://abliterator.ai", apiKey: process.env.ABL_API_KEY }). Pass an Abliterator model ID to messages.create. Do not add /v1; both SDKs append /v1/messages.
This page covers Python and TypeScript. Each section is complete on its own, with install steps, a first request, streaming and the Anthropic SDK-specific settings that trip people up.
Python
Abliterator implements the Anthropic Messages API, so the official anthropic Python SDK works by changing the base URL, key and model. Examples were run with anthropic 2.14. The request and response shapes are described in /docs/anthropic-messages-api.
Install
pip install anthropic
export ABL_API_KEY="sk-abl-v1-..."
Keys come from /keys.
First message
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://abliterator.ai",
api_key=os.environ["ABL_API_KEY"],
)
message = client.messages.create(
model="kimi-k3.1-pro-abliterated",
max_tokens=1024,
system="You are a senior incident responder.",
messages=[
{"role": "user", "content": "Write a containment checklist for a malware alert on one Windows file server."},
],
)
print(message.content[0].text)
print(message.usage.input_tokens, "in /", message.usage.output_tokens, "out")
The base URL is the site origin with no path. The SDK builds https://abliterator.ai/v1/messages itself. max_tokens is required by the Messages API, as with Anthropic's own service.
Streaming
client.messages.stream() is a context manager that parses the SSE events for you. text_stream yields only text deltas; get_final_message() returns the assembled message with usage:
import os
import anthropic
client = anthropic.Anthropic(base_url="https://abliterator.ai", api_key=os.environ["ABL_API_KEY"])
with client.messages.stream(
model="deepseek-v4.1-flash-abliterated",
max_tokens=1024,
messages=[{"role": "user", "content": "List the phases of incident response, from detection to post-incident review."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
final = stream.get_final_message()
print("\nstop_reason:", final.stop_reason, "output tokens:", final.usage.output_tokens)
anthropic.AsyncAnthropic has the same method with async with and async for. For raw events, call client.messages.create(..., stream=True) and iterate.
Tool use loop
Tools are declared with input_schema. When the model wants one, stop_reason is "tool_use" and the content holds tool_use blocks. Run the tool, send a tool_result block back, and call again:
import json
import os
import anthropic
client = anthropic.Anthropic(base_url="https://abliterator.ai", api_key=os.environ["ABL_API_KEY"])
tools = [
{
"name": "get_host_events",
"description": "Return recent EDR events for a hostname.",
"input_schema": {
"type": "object",
"properties": {"hostname": {"type": "string"}},
"required": ["hostname"],
},
}
]
def get_host_events(hostname: str) -> str:
return json.dumps([{"time": "09:14", "event": "new service installed", "host": hostname}])
messages = [{"role": "user", "content": "Check FS01 for persistence and tell me what you find."}]
while True:
response = client.messages.create(
model="kimi-k3.1-pro-abliterated", max_tokens=1024, tools=tools, messages=messages
)
if response.stop_reason != "tool_use":
break
messages.append({"role": "assistant", "content": response.content})
results = []
for block in response.content:
if block.type == "tool_use":
output = get_host_events(**block.input)
results.append({"type": "tool_result", "tool_use_id": block.id, "content": output})
messages.append({"role": "user", "content": results})
print("".join(b.text for b in response.content if b.type == "text"))
Keep the loop bounded in production (a counter or a deadline). The OpenAI-format equivalent is in /docs/tool-calling.
Troubleshooting
- 404 on
/v1/v1/messages. The base URL included/v1. Usehttps://abliterator.aiexactly; the/v1belongs only to the OpenAI-format base URL. - Requests go to api.anthropic.com.
base_urlwas not passed andANTHROPIC_BASE_URLis unset. Either pass it or exportANTHROPIC_BASE_URL=https://abliterator.aiandANTHROPIC_API_KEYwith your Abliterator key. TypeError: Missing required arguments; Expected either ('max_tokens', 'messages' and 'model').... The SDK checks formax_tokensbefore sending. Both Abliterator models allow large outputs (see /models), but set a real cap so a runaway answer cannot spend your balance.- 404 with "unknown model". A
claude-*ID is still in a config file or default argument. Search for it and replace it with an Abliterator model ID. - Unexpected 400 on Anthropic-only features. Abliterator supports text, image blocks, tools and streaming on this endpoint. Server-side tools such as web search, the Files API and batches are not available.
TypeScript
Abliterator answers the Anthropic Messages API at https://abliterator.ai/v1/messages, so the official TypeScript SDK needs only a new baseURL, key and model. These snippets were type-checked with tsc --strict and run on Node 22 with @anthropic-ai/sdk 1.14.
Install
npm install @anthropic-ai/sdk
export ABL_API_KEY="sk-abl-v1-..."
Create a key at /keys.
First message
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://abliterator.ai",
apiKey: process.env.ABL_API_KEY,
});
const message = await client.messages.create({
model: "kimi-k3.1-pro-abliterated",
max_tokens: 1024,
system: "You are a threat intelligence analyst.",
messages: [{ role: "user", content: "Which MITRE ATT&CK tactics should a small SOC cover first with detections, and why?" }],
});
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
}
console.log(message.usage);
Narrowing on block.type is required in strict mode because content is a union of text, tool-use and other block types.
Streaming
client.messages.stream() returns a MessageStream. Subscribe to text for deltas, then await finalMessage() for the assembled result:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://abliterator.ai", apiKey: process.env.ABL_API_KEY });
const stream = client.messages
.stream({
model: "deepseek-v4.1-flash-abliterated",
max_tokens: 1024,
messages: [{ role: "user", content: "Explain to a blue-team analyst which Windows event IDs record Kerberos service ticket requests." }],
})
.on("text", (delta) => process.stdout.write(delta));
const final = await stream.finalMessage();
console.log(`\n${final.stop_reason}, ${final.usage.output_tokens} output tokens`);
stream.abort() cancels the request. If you prefer raw events, client.messages.create({ ..., stream: true }) returns an async iterable of MessageStreamEvent.
Structured output with a forced tool
The Messages API returns structured data through tool calls. Force a single tool and read its input:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://abliterator.ai", apiKey: process.env.ABL_API_KEY });
type TicketLabel = { category: "billing" | "bug" | "account"; summary: string; tags: string[] };
const response = await client.messages.create({
model: "kimi-k3.1-pro-abliterated",
max_tokens: 1024,
// Kimi accepts a forced (named) tool only with reasoning off.
thinking: { type: "disabled" },
tools: [
{
name: "record_label",
description: "Record the category of a support ticket for a triage dataset.",
input_schema: {
type: "object",
properties: {
category: { type: "string", enum: ["billing", "bug", "account"] },
summary: { type: "string" },
tags: { type: "array", items: { type: "string" } },
},
required: ["category", "summary", "tags"],
},
},
],
tool_choice: { type: "tool", name: "record_label" },
messages: [
{
role: "user",
content: "Classify: 'I was charged twice for my November invoice and the second charge still shows as pending.'",
},
],
});
const call = response.content.find((b) => b.type === "tool_use");
if (call?.type === "tool_use") {
const result = call.input as TicketLabel;
console.log(result.category, result.tags);
}
Validate input before trusting it (with Zod, for example); the schema guides the model but the SDK does not enforce it. For an agent loop that sends tool results back, see the tool use loop in the Python section.
Troubleshooting
- 404 for
/v1/v1/messages. Remove/v1frombaseURL. Only the OpenAI-format base URL,https://abliterator.ai/v1, ends in/v1. Could not resolve authentication method.process.env.ABL_API_KEYwas undefined and neitherANTHROPIC_API_KEYnorANTHROPIC_AUTH_TOKENis set. Load your env file before constructing the client.- Calls still reach Anthropic. Another module created its own client from
ANTHROPIC_BASE_URL. ExportANTHROPIC_BASE_URL=https://abliterator.aiso every default client follows, or share one client instance. - 400 on server tools or files. Web search, code execution, the Files API and Message Batches are not available on Abliterator. Text, images, client tools and streaming are.
- Browser use. The SDK refuses to run in a browser unless you set
dangerouslyAllowBrowser: true, which would publish your key. Proxy through your own server.
Frequently asked questions
Can I use the Anthropic SDK and the OpenAI SDK with the same key?
Yes. Abliterator serves both formats from the same key. Code written for the anthropic package talks to POST /v1/messages; code written for openai talks to /v1/chat/completions. Pick whichever SDK your codebase already uses.
Should I use api_key or auth_token?
Either works. Current SDK versions send both as an Authorization: Bearer header, and older versions send api_key as x-api-key; Abliterator accepts both headers. Set one, not both.
Can I keep a claude model name in my code?
No. Abliterator only serves its own models, so a claude-* model ID returns 404. Replace it with kimi-k3.1-pro-abliterated or deepseek-v4.1-flash-abliterated, ideally from a config value so you can switch back.
Will TypeScript reject a non-Claude model ID?
No. The SDK's Model type lists Claude IDs for autocomplete but also accepts any string, so "kimi-k3.1-pro-abliterated" type-checks without a cast.
How do I get structured JSON from the Messages API on Abliterator?
Declare one tool whose input_schema is the shape you want and force it with tool_choice: { type: "tool", name }; on kimi-k3.1-pro-abliterated, also set thinking: { type: "disabled" }. The tool_use block's input is the parsed object, as in the example on this page.
Does the SDK's streaming helper work with Abliterator's SSE stream?
Yes. Abliterator emits the standard Messages event sequence (message_start, content_block_delta, message_delta, message_stop), so messages.stream(), its text event and finalMessage() behave as they do against Anthropic.