> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Semantic Kernel

> 通过自定义 OpenAI 兼容端点将 Microsoft Semantic Kernel 连接到 TokenLab

## 概述

Semantic Kernel 可以通过其 OpenAI 自定义端点聊天补全服务调用 TokenLab。

<Note>
  **类型**: SDK / 代理框架

  **主要路径**: OpenAI 兼容的聊天补全 (chat completions)

  **支持置信度**: 支持自定义端点路径
</Note>

## 环境

```bash theme={null}
export TOKENLAB_API_KEY="sk-your-tokenlab-key"
```

## .NET Kernel Builder

Semantic Kernel 的自定义端点应指向 OpenAI 兼容的根端点 `/v1`，而不是 `/v1/chat/completions`。

```csharp theme={null}
using Microsoft.SemanticKernel;

#pragma warning disable SKEXP0010

var builder = Kernel.CreateBuilder();

builder.AddOpenAIChatCompletion(
    modelId: "gpt-5.4-mini",
    endpoint: new Uri("https://api.tokenlab.sh/v1"),
    apiKey: Environment.GetEnvironmentVariable("TOKENLAB_API_KEY"));

var kernel = builder.Build();
```

## 基础 Prompt

```csharp theme={null}
var result = await kernel.InvokePromptAsync(
    "Give me a concise checklist for evaluating an LLM gateway.");

Console.WriteLine(result);
```

## 端点注意事项

使用：

```text theme={null}
https://api.tokenlab.sh/v1
```

请勿使用：

```text theme={null}
https://api.tokenlab.sh/v1/chat/completions
```

对于此连接器，Semantic Kernel 会在内部自动附加聊天补全路径。
