Semantic Kernel with Abliterator: Python and C#
Run Semantic Kernel on Abliterator: pass an AsyncOpenAI client in Python, or a custom endpoint with the SKEXP0010 pragma in .NET, then stream and auto-call functions.
Python: build AsyncOpenAI(base_url="https://abliterator.ai/v1", api_key=...) and pass it to OpenAIChatCompletion as async_client, with ai_model_id="kimi-k3.1-pro-abliterated". C#: builder.AddOpenAIChatCompletion(modelId: "kimi-k3.1-pro-abliterated", apiKey: key, endpoint: new Uri("https://abliterator.ai/v1")) inside #pragma warning disable SKEXP0010.
This page covers Python and C# (.NET). Each section is complete on its own, with install steps, a first request, streaming and the Semantic Kernel-specific settings that trip people up.
Python
Semantic Kernel's chat completion docs cover custom OpenAI-compatible endpoints for C#, but in Python the OpenAIChatCompletion connector takes no endpoint. The supported route is to hand it your own AsyncOpenAI client. Tested with semantic-kernel 1.47.
Install
pip install semantic-kernel
export ABL_API_KEY="sk-abl-v1-..."
Register Abliterator as a chat service
import asyncio
import os
from openai import AsyncOpenAI
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, OpenAIChatPromptExecutionSettings
from semantic_kernel.contents import ChatHistory
client = AsyncOpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"])
chat = OpenAIChatCompletion(ai_model_id="kimi-k3.1-pro-abliterated", async_client=client, service_id="abliterator")
async def main() -> None:
history = ChatHistory(system_message="You are a vulnerability management lead.")
history.add_user_message("How should we prioritize 400 open findings when only 30 are internet-facing?")
settings = OpenAIChatPromptExecutionSettings(max_tokens=1024)
reply = await chat.get_chat_message_content(chat_history=history, settings=settings)
print(reply.content)
asyncio.run(main())
ai_model_id is required; Semantic Kernel sends it as model. The service_id lets you register both Abliterator models on one kernel and pick per call.
Streaming
get_streaming_chat_message_content returns an async generator of StreamingChatMessageContent chunks:
import asyncio
import os
from openai import AsyncOpenAI
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, OpenAIChatPromptExecutionSettings
from semantic_kernel.contents import ChatHistory
chat = OpenAIChatCompletion(
ai_model_id="deepseek-v4.1-flash-abliterated",
async_client=AsyncOpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"]),
)
async def main() -> None:
history = ChatHistory()
history.add_user_message("Write a short security-awareness quiz with answers for new hires.")
async for chunk in chat.get_streaming_chat_message_content(
chat_history=history, settings=OpenAIChatPromptExecutionSettings()
):
if chunk:
print(str(chunk), end="", flush=True)
print()
asyncio.run(main())
Auto-invoked kernel functions
Plugins are classes whose methods carry @kernel_function. With FunctionChoiceBehavior.Auto(), the kernel sends them as tools, runs the ones the model picks and feeds the results back:
import asyncio
import os
from typing import Annotated
from openai import AsyncOpenAI
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai import FunctionChoiceBehavior
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, OpenAIChatPromptExecutionSettings
from semantic_kernel.contents import ChatHistory
from semantic_kernel.functions import kernel_function
class AssetPlugin:
@kernel_function(description="Return owner and exposure for a hostname.")
def get_asset(self, hostname: Annotated[str, "The hostname to look up"]) -> str:
return f"{hostname}: owner=payments-team, internet-facing=yes, last patched 2026-08-14"
kernel = Kernel()
kernel.add_service(
OpenAIChatCompletion(
ai_model_id="kimi-k3.1-pro-abliterated",
async_client=AsyncOpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"]),
)
)
kernel.add_plugin(AssetPlugin(), plugin_name="assets")
async def main() -> None:
chat = kernel.get_service(type=OpenAIChatCompletion)
settings = OpenAIChatPromptExecutionSettings(function_choice_behavior=FunctionChoiceBehavior.Auto())
history = ChatHistory()
history.add_user_message("CVE-2026-1234 affects pay-gw-01. Who owns it and how urgent is the patch?")
reply = await chat.get_chat_message_content(chat_history=history, settings=settings, kernel=kernel)
print(reply.content)
asyncio.run(main())
Pass kernel=kernel on the call; without it the service has no functions to invoke. For multi-agent setups, the same service works as the service of a ChatCompletionAgent.
Troubleshooting
ServiceInitializationError: The OpenAI API key is required.Noasync_clientwas passed, so the connector looked forOPENAI_API_KEY(andOPENAI_CHAT_MODEL_IDfor the model). Passai_model_idandasync_clientexplicitly.- Requests go to api.openai.com. You passed
api_key=toOpenAIChatCompletioninstead of a client. The key alone cannot change the host; useasync_client. - Functions never run. Either
function_choice_behavioris missing from the settings orkernelwas not passed toget_chat_message_content. - Do not use
OpenAIResponsesAgent. It targets the Responses API, which Abliterator does not serve. UseChatCompletionAgentor the chat service directly. - Embedding services.
OpenAITextEmbeddingwill fail against Abliterator, which has no embeddings endpoint. Register a separate embedding service for memory and vector stores.
C# and .NET
Microsoft's chat completion guide covers "other" OpenAI-compatible providers under the OpenAI connector: you pass an endpoint and suppress the SKEXP0010 experimental warning. The examples below follow that guide for .NET 8 console apps with top-level statements.
Install
dotnet new console -n AblKernel
cd AblKernel
dotnet add package Microsoft.SemanticKernel
export ABL_API_KEY="sk-abl-v1-..."
Microsoft.SemanticKernel pulls in the OpenAI connector. Get a key at /keys.
Register Abliterator and send a chat
Replace Program.cs with:
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
var apiKey = Environment.GetEnvironmentVariable("ABL_API_KEY")
?? throw new InvalidOperationException("Set ABL_API_KEY");
var builder = Kernel.CreateBuilder();
#pragma warning disable SKEXP0010
builder.AddOpenAIChatCompletion(
modelId: "kimi-k3.1-pro-abliterated",
apiKey: apiKey,
endpoint: new Uri("https://abliterator.ai/v1"),
httpClient: new HttpClient { Timeout = TimeSpan.FromMinutes(10) });
#pragma warning restore SKEXP0010
Kernel kernel = builder.Build();
var chat = kernel.GetRequiredService<IChatCompletionService>();
var history = new ChatHistory("You are an application security engineer.");
history.AddUserMessage("Review this pattern: string sql = \"SELECT * FROM users WHERE id=\" + id; What is wrong and how do I fix it in C#?");
var reply = await chat.GetChatMessageContentAsync(history, kernel: kernel);
Console.WriteLine(reply.Content);
The endpoint is the full base URL including /v1; the OpenAI .NET client underneath appends /chat/completions.
Streaming
GetStreamingChatMessageContentsAsync returns an IAsyncEnumerable of chunks:
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
var builder = Kernel.CreateBuilder();
#pragma warning disable SKEXP0010
builder.AddOpenAIChatCompletion(
modelId: "deepseek-v4.1-flash-abliterated",
apiKey: Environment.GetEnvironmentVariable("ABL_API_KEY")!,
endpoint: new Uri("https://abliterator.ai/v1"));
#pragma warning restore SKEXP0010
Kernel kernel = builder.Build();
var chat = kernel.GetRequiredService<IChatCompletionService>();
var history = new ChatHistory();
history.AddUserMessage("Explain the difference between authentication and authorization bugs, with one example of each.");
await foreach (var chunk in chat.GetStreamingChatMessageContentsAsync(history, kernel: kernel))
{
Console.Write(chunk.Content);
}
Console.WriteLine();
Automatic function calling
Kernel functions are methods marked [KernelFunction]. With FunctionChoiceBehavior.Auto(), Semantic Kernel sends them as tools, invokes the ones the model calls and returns the final answer:
using System.ComponentModel;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
var builder = Kernel.CreateBuilder();
#pragma warning disable SKEXP0010
builder.AddOpenAIChatCompletion(
modelId: "kimi-k3.1-pro-abliterated",
apiKey: Environment.GetEnvironmentVariable("ABL_API_KEY")!,
endpoint: new Uri("https://abliterator.ai/v1"));
#pragma warning restore SKEXP0010
builder.Plugins.AddFromType<FirewallPlugin>("firewall");
Kernel kernel = builder.Build();
var settings = new OpenAIPromptExecutionSettings
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(),
MaxTokens = 1024,
};
var chat = kernel.GetRequiredService<IChatCompletionService>();
var history = new ChatHistory();
history.AddUserMessage("Is RDP open to the internet on any of our edge firewalls? Recommend a change.");
var reply = await chat.GetChatMessageContentAsync(history, settings, kernel);
Console.WriteLine(reply.Content);
public sealed class FirewallPlugin
{
[KernelFunction("list_inbound_rules")]
[Description("List inbound allow rules on the edge firewalls.")]
public string ListInboundRules() =>
"fw-edge-1: allow any -> 10.0.2.15:3389 (rule 114, created 2025-02-03); allow any -> 10.0.2.20:443";
}
In a top-level program, class declarations must come after the statements, as here. kernel.InvokePromptAsync("...", new KernelArguments(settings)) uses the same settings if you prefer prompt functions to chat history.
Troubleshooting
error SKEXP0010. Projects with warnings-as-errors fail on the endpoint overload. Keep the#pragmalines, or add<NoWarn>$(NoWarn);SKEXP0010</NoWarn>to the.csproj.- 404 Not Found. The endpoint is missing
/v1or ends in/chat/completions. Usehttps://abliterator.ai/v1exactly. TaskCanceledExceptionafter 100 seconds. HttpClient's default timeout hit a long answer. Pass anHttpClientwith a longerTimeout, as in the first example, or stream.- Functions are never called.
FunctionChoiceBehaviorwas not set, orkernelwas not passed toGetChatMessageContentAsync, so the service has no plugins to offer. - Embedding generators fail. Abliterator has no embeddings endpoint; register a separate embedding service for vector stores and memory.
Frequently asked questions
Where is the endpoint parameter in Semantic Kernel Python?
There isn't one on OpenAIChatCompletion. The connector accepts a ready-made openai.AsyncOpenAI client through async_client, and that client carries the base URL and key.
Does FunctionChoiceBehavior.Auto work with Abliterator models?
Yes. Semantic Kernel advertises your kernel functions as Chat Completions tools, Abliterator passes them to the model, and the kernel invokes whatever the model calls before asking it to continue.
Can I set reasoning effort from Semantic Kernel?
OpenAIChatPromptExecutionSettings has a reasoning_effort field that is sent as the reasoning_effort request parameter. Which values the Abliterator models accept is covered in the reasoning guide.
What is SKEXP0010 and is it safe to suppress?
It is Semantic Kernel's experimental-API diagnostic for the OpenAI connector overloads that take a custom endpoint. Suppressing it is the documented way to use OpenAI-compatible services; it only means the overload's signature may change in a future release.
Should I use the Azure OpenAI connector for Abliterator?
No. AddAzureOpenAIChatCompletion builds Azure deployment URLs and auth headers. Abliterator speaks the plain OpenAI format, so use AddOpenAIChatCompletion with endpoint.
Why do long answers time out after 100 seconds?
That is HttpClient's default Timeout. Pass your own HttpClient with a longer Timeout through the httpClient parameter, or stream the response so tokens arrive continuously.