SDK MigrationUpdated 2026-01-22
Switch LangChain to abliteration.ai
Switch LangChain's ChatOpenAI to abliteration.ai by setting base_url. Keep your chains, agents, and tools unchanged.
LangChain's ChatOpenAI class supports any OpenAI-compatible endpoint via base_url.
Your chains, agents, memory, and tools work unchanged after the switch.
Definition
Switch LangChain to abliteration.ai
Switching LangChain's base URL means configuring ChatOpenAI to route requests through an alternative OpenAI-compatible provider.
Why it matters
- Keep your existing LangChain chains and agents unchanged.
- No code changes to prompts, memory, or tool definitions.
- Test alternative models without rebuilding your application.
- Works with LangChain Expression Language (LCEL) and LangGraph.
How it works
- 01Install
langchain-openaiif not already installed. - 02Set
base_url="https://api.abliteration.ai/v1"in ChatOpenAI. - 03Replace your OpenAI key with your abliteration.ai API key.
- 04Use a supported model id like
abliterated-model.
LangChain base URL switch
from langchain_openai import ChatOpenAI
# Before: OpenAI default
# llm = ChatOpenAI(model="gpt-4")
# After: abliteration.ai
llm = ChatOpenAI(
model="abliterated-model",
base_url="https://api.abliteration.ai/v1",
api_key="YOUR_ABLIT_KEY",
)
# Your chains work unchanged
response = llm.invoke("Summarize this document in three bullet points.")
print(response.content)
# Works with chains, agents, and LCEL
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant."),
("user", "{input}")
])
chain = prompt | llm
result = chain.invoke({"input": "What is abliteration?"})FAQ
Frequently asked questions.
Do my existing chains still work?
Yes. Chains, agents, and LCEL pipelines work unchanged after switching the LLM endpoint.
Does streaming work with LangChain?
Yes. Use llm.stream() or chain.stream() exactly like with OpenAI models.
Can I use this with LangGraph?
Yes. LangGraph agents use the same ChatOpenAI class, so the switch applies automatically.