---
title: "Semantic Kernel OpenAI connector with a custom endpoint"
description: "Connect Microsoft Semantic Kernel to BroadNet Inference in Python with an AsyncOpenAI client, or in C# with a custom endpoint, for chat, plugins and agents."
url: https://broadrouter.com/guides/semantic-kernel-openai-compatible/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Use Semantic Kernel with BroadNet Inference

Updated 2026-11-16

In Python, create AsyncOpenAI with base\_url https://inference.broadnet.ai/v1 and your BroadNet key, then pass it as async\_client to OpenAIChatCompletion with ai\_model\_id set to a BroadNet ID such as broadnet/glm-5.3. In C#, call AddOpenAIChatCompletion with an endpoint Uri, which Microsoft marks experimental (SKEXP0010). Use GLM 5.3 or Qwen3.8 27B for plugins.

Semantic Kernel is Microsoft’s SDK for building AI apps and agents in C#, Python and Java. Its OpenAI connector works with other OpenAI-compatible services: Python takes your own OpenAI client, and C# takes a custom endpoint. BroadNet Inference serves standard chat completions at `https://inference.broadnet.ai/v1`, so either route works. BroadRouter is BroadNet’s own site; this follows Microsoft’s Semantic Kernel docs and the Python 1.47.0 source.

## Python

```bash
pip install semantic-kernel
export BROADNET_API_KEY='your-broadnet-key'
```

```python
import asyncio, 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://inference.broadnet.ai/v1", api_key=os.environ["BROADNET_API_KEY"])
chat = OpenAIChatCompletion(ai_model_id="broadnet/glm-5.3", async_client=client, service_id="broadnet")

async def main():
    history = ChatHistory()
    history.add_user_message("Give me three names for a billing microservice.")
    settings = OpenAIChatPromptExecutionSettings(max_tokens=4000)
    print(await chat.get_chat_message_content(chat_history=history, settings=settings))

asyncio.run(main())
```

`ai_model_id` is sent unchanged, so keep the `broadnet/` prefix. The `api_key` argument of `OpenAIChatCompletion` is not needed when you pass a client.

### Plugins and function calling

```python
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior
from semantic_kernel.functions import kernel_function

class Weather:
    @kernel_function(description="Get the weather for a city.")
    def get_weather(self, city: str) -> str:
        return f"21C in {city}"

kernel = Kernel()
kernel.add_service(chat)
kernel.add_plugin(Weather(), plugin_name="weather")
settings = OpenAIChatPromptExecutionSettings(
    max_tokens=4000,
    function_choice_behavior=FunctionChoiceBehavior.Auto(),
)
# await chat.get_chat_message_content(chat_history=history, settings=settings, kernel=kernel)
```

Semantic Kernel sends the plugin as a tool named `weather-get_weather`, runs it when the model asks, and sends the result back. Use `broadnet/glm-5.3` or `broadnet/qwen3.8-27b`; BroadNet’s docs list tools for these two only.

### Agents

```python
from semantic_kernel.agents import ChatCompletionAgent

agent = ChatCompletionAgent(service=chat, name="helper", instructions="Answer briefly.", plugins=[Weather()])
# response = await agent.get_response(messages="What's the weather in Dubai?")
```

## C# (.NET)

Microsoft’s docs give this pattern for “other AI service providers that support the OpenAI chat completion API”. We did not run the C# version.

```csharp
using Microsoft.SemanticKernel;

#pragma warning disable SKEXP0010
IKernelBuilder kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.AddOpenAIChatCompletion(
    modelId: "broadnet/glm-5.3",
    apiKey: Environment.GetEnvironmentVariable("BROADNET_API_KEY"),
    endpoint: new Uri("https://inference.broadnet.ai/v1")
);
Kernel kernel = kernelBuilder.Build();
```

Install the connector with `dotnet add package Microsoft.SemanticKernel.Connectors.OpenAI`.

## Which model to pick

| Use | Model |
| --- | --- |
| Plugins, function calling, agents | `broadnet/glm-5.3` |
| Plugins plus image input or Arabic text | `broadnet/qwen3.8-27b` |
| Chat and summaries without tools, flat-price plan | `broadnet/deepseek-v4.1-flash` |

[Prices for every model](https://broadrouter.com/pricing/).

## How we tested this

On 2026-11-15 we installed semantic-kernel 1.47.0 for Python in a clean virtual environment and ran plain chat, streaming, automatic function calling and a `ChatCompletionAgent` against a local mock server that speaks BroadNet’s chat-completions shape. We read the logged requests. All went to `/v1/chat/completions` with the BroadNet model ID unchanged and a Bearer key. `max_tokens` was sent under that name, streaming added `stream_options.include_usage`, and function calling sent `tool_choice: "auto"`. We had no BroadNet key, so we did not test real model output. The C# snippet is from Microsoft’s docs and was not run.

## Troubleshooting

-   **401.** The key is wrong, expired or out of allowance.
-   **404.** The client `base_url` must end in `/v1`. Check the model ID. Paid models need a top-up; the $5 credit covers only `broadnet/gemma-4-26b-a4b` and the two Transcribe models.
-   **Empty replies.** Reasoning counts toward `max_tokens` on DeepSeek V4.1 Flash, GLM 5.3 and Qwen3.8 27B. Raise it. [Why answers come back empty](https://broadrouter.com/guides/reasoning-tokens-empty-response/).
-   **Reasoning models and roles.** Microsoft’s docs suggest `instruction_role="developer"` for OpenAI reasoning models. BroadNet’s API reference doesn’t mention the `developer` role, so leave `instruction_role` at its default. Our agent test sent instructions in a `system` message.
-   **429.** A pay-as-you-go key allows 30 requests a minute and 4 in flight. See [errors and retries](https://broadrouter.com/guides/errors-and-retries/).

## Terms in this guide

[Tool calling](https://broadrouter.com/glossary/tool-calling/)

Tool calling, also called function calling, is an LLM API feature in which the model returns a structured request to run a function the developer has defined, with JSON arguments. The application runs the function and sends the result back; the model never runs code itself.

[Pay-as-you-go](https://broadrouter.com/glossary/pay-as-you-go/)

Pay-as-you-go is a pricing model in which you pay only for what you use, metered per unit such as tokens, requests or audio minutes, with no subscription or minimum commitment. Most LLM APIs bill this way, from a prepaid balance or a periodic invoice.

[Streaming](https://broadrouter.com/glossary/streaming/)

Streaming is a way of returning a language model response in small chunks while it is still being generated, instead of as one reply at the end. OpenAI-compatible APIs stream over server-sent events when the request sets stream to true.

[Chat Completions API](https://broadrouter.com/glossary/chat-completions-api/)

The Chat Completions API is OpenAI's HTTP endpoint, POST /v1/chat/completions, that takes a model name and a list of role-tagged messages and returns the model's next message. Its request and response shape became the common format that OpenAI-compatible providers and SDKs reuse.

[Concurrency](https://broadrouter.com/glossary/concurrency/)

Concurrency is the number of requests a client has in flight at the same time. LLM APIs often cap it per key or plan, separately from requests per minute, because each open request holds GPU capacity until its response has finished.

[Prepaid credit](https://broadrouter.com/glossary/prepaid-credit/)

Prepaid credit is money added to an API account before use. Each request deducts its cost from the balance, and when the balance runs out, metered requests stop until you top up. It caps spend at what you have paid in.

[Rate limit](https://broadrouter.com/glossary/rate-limit/)

A rate limit is a cap an API places on how much a client can use it in a time window, such as requests per minute or tokens per minute. Requests over the limit are refused, usually with HTTP 429 Too Many Requests, until usage falls back under it.

## Questions

### How do I set a custom base URL in Semantic Kernel for Python?

OpenAIChatCompletion has no base\_url argument in version 1.47. Create an openai.AsyncOpenAI client with base\_url and api\_key, and pass it as async\_client. That client then sends every request to BroadNet.

### Why does the C# custom endpoint need a pragma?

Microsoft's docs say using custom endpoints with the OpenAI connector is experimental, so the endpoint overload needs

### Does automatic function calling work with BroadNet?

It uses standard tool calls over chat completions, so use a model BroadNet lists with tools, GLM 5.3 or Qwen3.8 27B. In our mock test, Semantic Kernel sent the plugin as a tool and returned the result in a tool message.

### Does Semantic Kernel's ChatCompletionAgent work on BroadNet?

Yes. It takes the same OpenAIChatCompletion service. In our Python test it sent the agent instructions as a system message and called the plugin through chat completions.

## Related guides

-   [Use the OpenAI Python SDK with BroadNet Inference](https://broadrouter.com/guides/openai-python-sdk/)
-   [Run the OpenAI Agents SDK on BroadNet Inference](https://broadrouter.com/guides/openai-agents-sdk-custom-provider/)
-   [Why a reasoning model returns an empty answer](https://broadrouter.com/guides/reasoning-tokens-empty-response/)
-   [BroadNet Inference error codes and when to retry](https://broadrouter.com/guides/errors-and-retries/)
-   [All tools that work with BroadNet Inference](https://broadrouter.com/integrations/): SDKs, coding agents, chat UIs and automation tools, with exact settings for each

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-semantic-kernel-openai-compatible&utm_content=page-cta) ·

**Sources**

-   [Microsoft Learn, Add chat completion services to Semantic Kernel (updated 2026-05-26, checked 2026-11-15)](https://learn.microsoft.com/en-us/semantic-kernel/concepts/ai-services/chat-completion/)
-   [Semantic Kernel source, Python OpenAIChatCompletion at python-1.47.0 (checked 2026-11-15)](https://github.com/microsoft/semantic-kernel/blob/python-1.47.0/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_chat_completion.py)
-   [PyPI, semantic-kernel 1.47.0 (checked 2026-11-15)](https://pypi.org/project/semantic-kernel/)
-   [BroadNet Inference API reference (checked 2026-11-15)](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-semantic-kernel-openai-compatible&utm_content=sources)
