LlamaIndex with Abliterator: Python and TypeScript
Connect LlamaIndex and LlamaIndex.TS to Abliterator: OpenAILike in Python, the OpenAI class with baseURL in TypeScript, context window settings and tool agents.
Python: OpenAILike(model="kimi-k3.1-pro-abliterated", api_base="https://abliterator.ai/v1", api_key=..., is_chat_model=True, is_function_calling_model=True, context_window=1048576). TypeScript: new OpenAI({ model: "kimi-k3.1-pro-abliterated", baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY }) from @llamaindex/openai, with metadata.contextWindow overridden.
This page covers Python and TypeScript. Each section is complete on its own, with install steps, a first request, streaming and the LlamaIndex-specific settings that trip people up.
Python
LlamaIndex ships a wrapper for OpenAI-compatible servers, OpenAILike, in its own package. It reuses the OpenAI client but lets you declare the model's capabilities yourself. Tested with llama-index-core 0.14 and llama-index-llms-openai-like 0.9.
Install
pip install llama-index-core llama-index-llms-openai-like
export ABL_API_KEY="sk-abl-v1-..."
Configure OpenAILike
import os
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="kimi-k3.1-pro-abliterated",
api_base="https://abliterator.ai/v1",
api_key=os.environ["ABL_API_KEY"],
is_chat_model=True,
is_function_calling_model=True,
context_window=1048576,
max_tokens=2048,
)
response = llm.chat(
[
ChatMessage(role="system", content="You are a digital forensics instructor."),
ChatMessage(role="user", content="Walk through the order of volatility for evidence collection on a live Linux host."),
]
)
print(response.message.content)
Three flags matter:
| Setting | Why |
|---|---|
is_chat_model=True |
Sends /chat/completions. The default False calls /completions, which Abliterator does not serve. |
is_function_calling_model=True |
Lets agents and structured_predict use native tool calls. |
context_window=1048576 |
Both Abliterator models take 1,048,576 tokens. The default of 3,900 makes LlamaIndex truncate retrieved context and chat memory far too early. |
To make it the default for indexes and query engines, assign it once: Settings.llm = llm (from llama_index.core import Settings).
Streaming
stream_chat yields responses whose delta is the new text:
import os
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="deepseek-v4.1-flash-abliterated",
api_base="https://abliterator.ai/v1",
api_key=os.environ["ABL_API_KEY"],
is_chat_model=True,
context_window=1048576,
)
for part in llm.stream_chat([ChatMessage(role="user", content="Explain how a SIEM correlation rule differs from a single-event alert.")]):
print(part.delta, end="", flush=True)
print()
Use astream_chat with async for inside async code. Query engines stream the same way with as_query_engine(streaming=True).
A FunctionAgent with tools
FunctionAgent from the workflow agents module calls tools through the model's native function calling. Plain Python functions become tools from their signature and docstring:
import asyncio
import os
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai_like import OpenAILike
def get_open_ports(host: str) -> str:
"""Return the open ports recorded for a host in the last authorized scan."""
return f"{host}: 22/tcp OpenSSH 8.9, 443/tcp nginx 1.24, 6379/tcp Redis (no auth)"
llm = OpenAILike(
model="kimi-k3.1-pro-abliterated",
api_base="https://abliterator.ai/v1",
api_key=os.environ["ABL_API_KEY"],
is_chat_model=True,
is_function_calling_model=True,
context_window=1048576,
)
agent = FunctionAgent(
tools=[get_open_ports],
llm=llm,
system_prompt="You prioritize findings from authorized network scans.",
)
async def main() -> None:
result = await agent.run(user_msg="What is the riskiest exposure on 10.0.4.12, and why?")
print(result)
asyncio.run(main())
FunctionAgent streams by default; iterate handler.stream_events() on the object returned by agent.run(...) to show tokens and tool calls as they happen.
Troubleshooting
ValueError: Unknown model 'kimi-k3.1-pro-abliterated'. Please provide a valid OpenAI model name. You usedllama_index.llms.openai.OpenAI. Switch toOpenAILike.NotFoundError: 404on/v1/completions.is_chat_modelis missing orFalse.- Answers ignore most of your documents.
context_windowis still the 3,900-token default, so the prompt helper drops chunks to fit. Set it to 1048576 or to the budget you want to pay for. ValueError: LLM must be a FunctionCallingLLMfrom FunctionAgent. Addis_function_calling_model=True.- Embeddings. Abliterator does not serve an embeddings endpoint. Keep a separate embedding model (local or another provider) in
Settings.embed_model; only the LLM points at Abliterator.
TypeScript
LlamaIndex.TS reaches OpenAI-compatible servers through the OpenAI class in @llamaindex/openai, which takes a baseURL option as shown in the LlamaIndex.TS OpenAI guide. Examples were type-checked with tsc --strict and run on Node 22 with llamaindex 0.12, @llamaindex/openai 0.4 and @llamaindex/workflow 1.1.
Install
npm install llamaindex @llamaindex/openai @llamaindex/workflow zod
export ABL_API_KEY="sk-abl-v1-..."
Configure the LLM
import { OpenAI } from "@llamaindex/openai";
import { Settings } from "llamaindex";
class AblOpenAI extends OpenAI {
get metadata() {
return { ...super.metadata, contextWindow: 1_048_576 };
}
}
Settings.llm = new AblOpenAI({
model: "kimi-k3.1-pro-abliterated",
baseURL: "https://abliterator.ai/v1",
apiKey: process.env.ABL_API_KEY,
maxTokens: 2048,
});
const response = await Settings.llm.chat({
messages: [
{ role: "system", content: "You are a cloud security reviewer." },
{ role: "user", content: "List the IAM misconfigurations you would check first in an AWS account audit." },
],
});
console.log(response.message.content);
Why the subclass: for model names it does not know, the OpenAI class reports contextWindow: 1024. Memory sizes itself at 75% of that, so an agent forgets everything past about 768 tokens of history. Both Abliterator models accept 1,048,576 tokens, and overriding metadata fixes every component that reads it.
Streaming
Pass stream: true to chat() and iterate. Each chunk's delta is the new text:
import { OpenAI } from "@llamaindex/openai";
const llm = new OpenAI({
model: "deepseek-v4.1-flash-abliterated",
baseURL: "https://abliterator.ai/v1",
apiKey: process.env.ABL_API_KEY,
});
const stream = await llm.chat({
messages: [{ role: "user", content: "Explain what a canary token is and where to plant them in a network." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.delta);
}
process.stdout.write("\n");
A tool agent with @llamaindex/workflow
agent() builds a single-agent workflow that calls tools through native function calling. tool() takes a Zod schema for the arguments:
import { OpenAI } from "@llamaindex/openai";
import { agent, agentStreamEvent, agentToolCallEvent } from "@llamaindex/workflow";
import { tool } from "llamaindex";
import { z } from "zod";
class AblOpenAI extends OpenAI {
get metadata() {
return { ...super.metadata, contextWindow: 1_048_576 };
}
}
const llm = new AblOpenAI({ model: "kimi-k3.1-pro-abliterated", baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY });
const findSecrets = tool({
name: "scan_repo_for_secrets",
description: "Return findings from the last secret-scanning run on a repository.",
parameters: z.object({ repo: z.string() }),
execute: ({ repo }) => `${repo}: 2 AWS access keys in config/old.env (commit 4f2a9c1), 1 Slack webhook in README`,
});
const reviewer = agent({
llm,
tools: [findSecrets],
systemPrompt: "You triage secret-scanning results and recommend rotation steps.",
});
const events = reviewer.runStream("Check acme/payments-api and tell me what to rotate first.");
for await (const event of events) {
if (agentToolCallEvent.include(event)) console.log(`\n[tool] ${event.data.toolName}`);
if (agentStreamEvent.include(event)) process.stdout.write(event.data.delta);
}
process.stdout.write("\n");
Use await reviewer.run(...) instead of runStream when you only need the final answer; it resolves to an event whose data.result holds the reply.
Troubleshooting
- Agent loses earlier turns. The context window override is missing, so memory is capped near 768 tokens. Use the
AblOpenAIsubclass or setSettings.llmto an instance of it. - 404 on
/v1/responses. You usedopenaiResponses(). Switch tonew OpenAI(...). baseURLignored. It must be a top-level option on theOpenAIclass (unlike LangChain.js, which nests it underconfiguration).OPENAI_BASE_URLin the environment is used only when the option is absent.- Embeddings fail. Abliterator has no embeddings endpoint. Set
Settings.embedModelto a separate embedding provider and keepSettings.llmon Abliterator. reasoningEfforttype errors. The class types it as"low" | "medium" | "high" | "minimal". See /docs/reasoning for how Abliterator handles reasoning effort.
Frequently asked questions
Why not use llama_index.llms.openai.OpenAI with api_base?
That class looks the model name up in a table of OpenAI models to find its context window, and raises ValueError: Unknown model for anything else. OpenAILike skips the lookup and takes the context window from you.
What happens if I forget is_chat_model=True?
OpenAILike defaults to the legacy completions endpoint and flattens your messages into one prompt. Abliterator has no /v1/completions route, so you get a 404. Set is_chat_model=True.
Does FunctionAgent need anything extra for Abliterator?
Only is_function_calling_model=True on the LLM. Without it LlamaIndex treats the model as unable to call tools, and FunctionAgent fails with ValueError: LLM must be a FunctionCallingLLM.
Does LlamaIndex.TS need an OpenAILike class like Python?
No. The TypeScript OpenAI class accepts any model string and a baseURL. It only uses its built-in model table for metadata, which is why the context window needs the override shown on this page.
Will agents use native tool calling with Abliterator models?
Yes. supportToolCall is true for any model name that is not an old OpenAI snapshot or o1, so agent() sends tools through Chat Completions function calling.
Can I use openaiResponses() from @llamaindex/openai?
No. openaiResponses targets the OpenAI Responses API, which Abliterator does not serve. Use the OpenAI class, which calls Chat Completions.