> ## 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 自訂端點聊天完成服務（chat completion service）呼叫 TokenLab。

<Note>
  **類型**: SDK / Agent Framework

  **主要路徑**: 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 會在此連接器內部自動附加聊天完成路徑。
