Anthropic SDK

Anthropic Python SDK with an uncensored Messages API

Use the anthropic Python package with Abliterator's Anthropic-compatible Messages API: set base_url without /v1, stream text, and run a tool-use loop.

Reviewed Anthropic SDKPython

Quick answer

Create the client with Anthropic(base_url="https://abliterator.ai", api_key=os.environ["ABL_API_KEY"]) and pass an Abliterator model ID to client.messages.create. Do not add /v1; the SDK appends /v1/messages.

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 ransomware 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": "Summarize the kill chain of a typical phishing-to-ransomware intrusion."}],
) 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. Use https://abliterator.ai exactly; the /v1 belongs only to the OpenAI-format base URL.
  • Requests go to api.anthropic.com. base_url was not passed and ANTHROPIC_BASE_URL is unset. Either pass it or export ANTHROPIC_BASE_URL=https://abliterator.ai and ANTHROPIC_API_KEY with your Abliterator key.
  • TypeError: Missing required arguments; Expected either ('max_tokens', 'messages' and 'model').... The SDK checks for max_tokens before 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.

Frequently asked questions

Why is this page under OpenAI-compatible if it uses the Anthropic SDK?

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.