LangChain

LangChain Python with an OpenAI-compatible uncensored API

Use langchain-openai's ChatOpenAI with Abliterator: set base_url and api_key, stream with usage, build a create_agent tool agent, and keep requests on Chat Completions.

Reviewed LangChainPython

Quick answer

Build the model with ChatOpenAI(model="kimi-k3.1-pro-abliterated", base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"]). Chains, agents and structured output then run on Abliterator unchanged.

LangChain reaches OpenAI-compatible servers through ChatOpenAI in the langchain-openai package. Set base_url and api_key and every Runnable, chain and agent built on it uses Abliterator. Tested with langchain 1.5 and langchain-openai 1.8; the parameters are documented in LangChain's ChatOpenAI integration guide.

Install

pip install langchain langchain-openai
export ABL_API_KEY="sk-abl-v1-..."

Connect ChatOpenAI to Abliterator

import os

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="kimi-k3.1-pro-abliterated",
    base_url="https://abliterator.ai/v1",
    api_key=os.environ["ABL_API_KEY"],
    max_tokens=1024,
)

reply = llm.invoke(
    [
        ("system", "You write detection content for a SOC."),
        ("human", "Describe three log signals that suggest a web shell on an IIS server."),
    ]
)
print(reply.content)
print(reply.usage_metadata)

base_url is an alias for openai_api_base. Explicit arguments win over the OPENAI_API_BASE and OPENAI_BASE_URL environment variables.

Streaming

import os

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="deepseek-v4.1-flash-abliterated",
    base_url="https://abliterator.ai/v1",
    api_key=os.environ["ABL_API_KEY"],
    stream_usage=True,
)

total = None
for chunk in llm.stream("Explain how attackers abuse OAuth consent grants, for an awareness training."):
    print(chunk.content, end="", flush=True)
    total = chunk if total is None else total + chunk

print("\n", total.usage_metadata)

Adding chunks merges them into one AIMessageChunk, so total.usage_metadata holds the token counts from Abliterator's final usage event. astream and astream_events work the same way.

A tool-calling agent with create_agent

LangChain 1.x builds agents with create_agent. It loops between the model and your tools until the model answers in text:

import os

from langchain.agents import create_agent
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI


@tool
def lookup_ioc(indicator: str) -> str:
    """Look up an IP, domain or hash in the internal threat-intel store."""
    return f"{indicator}: seen in 3 incidents, last 2026-11-02, tagged 'commodity loader'"


llm = ChatOpenAI(model="kimi-k3.1-pro-abliterated", base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"])

agent = create_agent(
    llm,
    tools=[lookup_ioc],
    system_prompt="You are a threat-intel assistant. Use tools before answering.",
)

result = agent.invoke({"messages": [{"role": "user", "content": "Is 203.0.113.50 known to us?"}]})
print(result["messages"][-1].content)

For typed output without an agent, llm.with_structured_output(MyPydanticModel) defaults to the json_schema method on ChatOpenAI, which Abliterator passes through as response_format. See /docs/structured-outputs.

Troubleshooting

  • 404 on /v1/responses. ChatOpenAI switched to the Responses API. That happens when you set use_responses_api=True, reasoning={...}, output_version="responses/v1", include, truncation or use_previous_response_id, or bind a built-in tool such as web search. Remove those, or force use_responses_api=False.
  • Reasoning text is missing. ChatOpenAI keeps only standard OpenAI fields and drops provider extensions such as reasoning_content. The final answer in .content is unaffected. /docs/reasoning explains what Abliterator returns.
  • strict=True tools fail validation. Strict schemas cannot have optional arguments. Give every parameter a type and no default, or drop strict.
  • The request goes to api.openai.com. A ChatOpenAI built elsewhere (for example init_chat_model("openai:...") without base_url) ignores the client you configured. Pass base_url and api_key there too.
  • Many parallel calls hit 429. batch() and agents can fan out quickly. Set max_concurrency in the run config to stay under your plan's concurrent-request limit (/pricing).

Frequently asked questions

Why do I get no token usage when streaming from LangChain?

ChatOpenAI turns stream_usage on only for the default OpenAI URL. With a custom base_url it stays off, so pass stream_usage=True and the final chunk will carry usage_metadata.

How do I set reasoning effort without breaking the request?

Use the reasoning_effort field on ChatOpenAI. The reasoning={...} dict is a Responses API parameter, and setting it makes LangChain switch to /v1/responses, which Abliterator does not serve.

Does create_agent work with Abliterator models?

Yes. create_agent drives the model through standard tool calls on Chat Completions, which both Abliterator models support. The example on this page runs a one-tool agent end to end.