Semantic Kernel on a custom OpenAI endpoint
Point Microsoft Semantic Kernel at UplinkSwitch in .NET or Python: the OpenAI connector endpoint setting, a worked kernel, and function-calling notes.
Microsoft's Semantic Kernel points at an OpenAI-compatible endpoint through its OpenAI connector's endpoint or HttpClient base address, so a .NET or Python kernel runs on the catalog with the base URL https://api.uplinkswitch.com/v1, the key and a catalog model id. The connector that ships for OpenAI already speaks the wire format the gateway exposes, so you reuse it rather than install a vendor-specific package, and the same kernel code then reaches Claude, GPT, DeepSeek or GLM, each by its own catalog id.
The connector in .NET
Install the OpenAI connector package and build a kernel. Redirecting that connector to a non-OpenAI host is gated behind an experimental flag, so the compiler wants #pragma warning disable SKEXP0010 before the call; without it the endpoint argument will not compile.
using Microsoft.SemanticKernel;
#pragma warning disable SKEXP0010
IKernelBuilder builder = Kernel.CreateBuilder();
builder.AddOpenAIChatCompletion(
modelId: "gpt-6.1-sol",
apiKey: "sk-uplink-live-...",
endpoint: new Uri("https://api.uplinkswitch.com/v1"));
Kernel kernel = builder.Build();The package is Microsoft.SemanticKernel.Connectors.OpenAI (dotnet add package Microsoft.SemanticKernel.Connectors.OpenAI). The standalone service constructor, OpenAIChatCompletionService, takes the same endpoint: argument if you would rather hold the service object yourself instead of registering it on a kernel. Keep the key in configuration or an environment variable; the string above is only there to show the sk-uplink-live- prefix the gateway issues.
The connector in Python
The Python OpenAIChatCompletion class has no endpoint argument of its own. Instead it accepts an async_client, an AsyncOpenAI instance, and that client is where the base URL lives. Point the client at the gateway and hand it to the connector:
import os
from openai import AsyncOpenAI
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
client = AsyncOpenAI(
base_url="https://api.uplinkswitch.com/v1",
api_key=os.environ["UPLINKSWITCH_API_KEY"],
)
chat = OpenAIChatCompletion(
ai_model_id="gpt-6.1-sol",
async_client=client,
)
kernel = Kernel()
kernel.add_service(chat)This routes every call the service makes through the gateway, because the connector never opens its own socket once you pass a client. The ai_model_id is the catalog id with no vendor prefix, so a Claude model reads as claude-sonnet-5-5, not a dotted or namespaced name.
Running a prompt
With the service on the kernel, a single turn looks the same in both languages. In .NET you ask the kernel for its IChatCompletionService and call GetChatMessageContentAsync against a ChatHistory; in Python you call get_chat_message_content on the service with a ChatHistory and an execution-settings object. Streaming has a sibling method in each case that yields incremental updates as they arrive from the gateway; a text chunk need not line up with a single token.
Function calling
Semantic Kernel's whole point is letting the model invoke your code, and that survives the redirect. Tools you register as kernel functions are serialised into the request in the OpenAI tools shape, the gateway forwards them, and the model's calls come back as tool calls with their arguments (whole on the reply message, or in pieces on a stream), which Semantic Kernel matches to your functions and runs when auto invocation is on and the kernel is passed. You switch it on through the execution settings rather than the connector: set the function-choice behaviour to automatic so the kernel offers its plugins to the model on each turn.
OpenAIPromptExecutionSettings settings = new()
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};
var answer = await chat.GetChatMessageContentAsync(history, settings, kernel);In Python the field is function_choice_behavior on OpenAIChatPromptExecutionSettings. Pick a model whose catalog entry advertises tool support before you rely on this, and confirm the execution-settings field names against the Semantic Kernel version you have pinned, since that surface has moved between releases.
Switching models and failover
Because the id is just a string, you keep more than one service on the kernel and select between them by service id (serviceId in .NET, service_id in Python), or you rebuild the service with a different model id (modelId in .NET, ai_model_id in Python) and nothing else changes. That makes a cheap-to-strong escalation a one-line edit rather than a rewrite. The gateway adds a second layer underneath: it retries a model across its own routes when one is unavailable, so your kernel only has to decide between whole models, not between providers of the same model. For a cross-model fallback chain and the id spread, see /openai-api-alternative and the broader /guides/sdks.
Models to start with
A reasonable pairing is a strong default for reasoning and tool loops and a lighter id for bulk classification. Prices render live from the keyless catalog; verify the ids before shipping.
| Model id | Price per 1M (in / out) | Context | Suited to |
|---|---|---|---|
gpt-6.1-sol | $0.582 / $2.91 | 1.1M | Planners, tool-using agents |
claude-sonnet-5-5 | $1.164 / $2.91 | 1M | Long-context drafting, review |
Set the catalog id string once, keep the base URL and key constant, and the rest of the kernel, plugins and prompts stay as they are.