Haystack

Haystack pipelines with an OpenAI-compatible uncensored API

Run Haystack's OpenAIChatGenerator on Abliterator with api_base_url and Secret.from_env_var, stream with print_streaming_chunk, and build a tool-using Agent.

Reviewed HaystackPython

Quick answer

Create OpenAIChatGenerator(api_key=Secret.from_env_var("ABL_API_KEY"), api_base_url="https://abliterator.ai/v1", model="kimi-k3.1-pro-abliterated"). Use it alone, in a Pipeline or as the chat_generator of an Agent.

Haystack talks to OpenAI-compatible servers with the same component it uses for OpenAI: OpenAIChatGenerator, configured with api_base_url. Tested with haystack-ai 3.5.

Install

pip install haystack-ai
export ABL_API_KEY="sk-abl-v1-..."

Configure the generator

from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret

generator = OpenAIChatGenerator(
    api_key=Secret.from_env_var("ABL_API_KEY"),
    api_base_url="https://abliterator.ai/v1",
    model="kimi-k3.1-pro-abliterated",
    generation_kwargs={"max_tokens": 1024},
)

result = generator.run(
    [
        ChatMessage.from_system("You write training material for a security operations center."),
        ChatMessage.from_user("Explain how to tell a real brute-force attack from a misconfigured service account."),
    ]
)
reply = result["replies"][0]
print(reply.text)
print(reply.meta["usage"])

Secret.from_env_var keeps the key out of serialized pipelines: generator.to_dict() stores the variable name, not its value. generation_kwargs takes any Chat Completions parameter, such as temperature, stop or reasoning_effort.

Streaming

Set a streaming_callback. Haystack's print_streaming_chunk prints text, tool calls and tool results as they arrive:

from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.components.generators.utils import print_streaming_chunk
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret

generator = OpenAIChatGenerator(
    api_key=Secret.from_env_var("ABL_API_KEY"),
    api_base_url="https://abliterator.ai/v1",
    model="deepseek-v4.1-flash-abliterated",
    streaming_callback=print_streaming_chunk,
)

generator.run([ChatMessage.from_user("Summarize the OWASP Top 10 for LLM applications in plain language.")])

Write your own callback (a function that takes a StreamingChunk) to push chunk.content to a websocket or SSE response instead. Streaming works for one reply at a time, so leave n unset.

A tool-using Agent

The Agent component wraps a chat generator, calls tools and loops until the model is done. The @tool decorator builds the schema from type hints and the docstring:

from typing import Annotated

from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.tools import tool
from haystack.utils import Secret


@tool
def search_tickets(query: Annotated[str, "Words to search for in incident tickets"]) -> str:
    """Search past incident tickets."""
    return "INC-2291 (2026-10-03): same AnyDesk binary, installed by a fake 'IT support' caller; contained in 40 min."


agent = Agent(
    chat_generator=OpenAIChatGenerator(
        api_key=Secret.from_env_var("ABL_API_KEY"),
        api_base_url="https://abliterator.ai/v1",
        model="kimi-k3.1-pro-abliterated",
    ),
    tools=[search_tickets],
    system_prompt="You are an incident-response assistant. Check past tickets before advising.",
    max_agent_steps=6,
)

result = agent.run(messages=[ChatMessage.from_user("A user reports an unexpected AnyDesk install. Have we seen this before?")])
print(result["messages"][-1].text)

The agent and generator also drop into a Pipeline next to retrievers and prompt builders; connect a ChatPromptBuilder's prompt output to the generator's messages input.

Troubleshooting

  • ValueError: None of the following authentication environment variables are set: ('OPENAI_API_KEY',). Raised on the first run(), because the generator was built without api_key. Pass Secret.from_env_var("ABL_API_KEY").
  • 404 from Abliterator. api_base_url must be https://abliterator.ai/v1, including /v1; Haystack hands it to the OpenAI client, which adds /chat/completions.
  • Do not use OpenAIResponsesChatGenerator. It calls the Responses API, which Abliterator does not serve. OpenAIChatGenerator is the right component.
  • response_format with a Pydantic model fails while streaming. Pass the model's model_json_schema() wrapped in a {"type": "json_schema", ...} dict instead, or turn streaming off.
  • Embedders and rankers. Abliterator has no embeddings endpoint, so keep document and text embedders on a separate provider; only chat generation runs on Abliterator.

Frequently asked questions

Why does Haystack ask for OPENAI_API_KEY when I only set ABL_API_KEY?

OpenAIChatGenerator's api_key defaults to Secret.from_env_var("OPENAI_API_KEY") and raises ValueError on the first run if that variable is unset. Pass api_key=Secret.from_env_var("ABL_API_KEY") explicitly.

Can I stream structured output from Haystack with Abliterator?

Yes, but Haystack requires a JSON schema dict rather than a Pydantic class in generation_kwargs["response_format"] when a streaming_callback is set.

Does the Haystack Agent work with Abliterator's tool calling?

Yes. Agent sends the tools as standard Chat Completions function definitions through OpenAIChatGenerator, invokes them and loops until the model answers without a tool call.