# C# / .NET & Semantic Kernel — API Store Hub

> VI: Cấu hình `OpenAIClientOptions { Endpoint = new Uri("https://apistorehub.com/v1") }` trong .NET 8/9 và Semantic Kernel để dùng Claude, GPT, Gemini trong ứng dụng doanh nghiệp.
> EN: Point `OpenAIClientOptions` and Microsoft Semantic Kernel to `https://apistorehub.com/v1` in .NET 8/9 for enterprise AI services, plugins, and streaming.

- Canonical VI: https://apistorehub.com/vi/tich-hop/csharp-dotnet-semantic-kernel
- Canonical EN: https://apistorehub.com/en/tich-hop/csharp-dotnet-semantic-kernel
- Language: C#
- Runtime: .NET 8 / .NET 9, Microsoft.SemanticKernel, OpenAI .NET SDK
- Protocol: OpenAI Compatible (/v1/chat/completions)
- Install: `dotnet add package Microsoft.SemanticKernel`
- Auth Env Var: `API_KEY` (prefix `sk-ash-`)

## Step-by-Step Setup
1. Add `Microsoft.SemanticKernel` or the official `OpenAI` NuGet package.
2. Instantiate `OpenAIClient` with `Endpoint = new Uri("https://apistorehub.com/v1")`.
3. Register `AddOpenAIChatCompletion` inside ASP.NET Core dependency injection.
4. Attach `Polly` retry policies and propagate `CancellationToken` on every async request.

## Production Code Sample
```
using System;
using System.ClientModel;
using Microsoft.SemanticKernel;
using OpenAI;

var apiKey = Environment.GetEnvironmentVariable("API_KEY") ?? throw new InvalidOperationException();
var client = new OpenAIClient(
    new ApiKeyCredential(apiKey),
    new OpenAIClientOptions { Endpoint = new Uri("https://apistorehub.com/v1") }
);

var builder = Kernel.CreateBuilder();
builder.AddOpenAIChatCompletion(modelId: "gpt-6.2-sol", openAIClient: client);
var kernel = builder.Build();

var reply = await kernel.InvokePromptAsync("List 3 enterprise API governance controls.");
Console.WriteLine(reply);
```

## Quick cURL Check
```bash
curl https://apistorehub.com/v1/chat/completions \
  -H "Authorization: Bearer sk-ash-your_key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-6.2-sol","messages":[{"role":"user","content":"Explain dependency injection in .NET"}]}'
```

## Recommended Models (Live ST Pricing)
| Model | Live Price | Context | Datasheet |
|---|---|---|---|
| `gpt-6.2-sol` | 6,700 ST / 1M tokens | 1.1M | https://apistorehub.com/llms/models/gpt-6-2-sol.md |
| `claude-sonnet-5-5` | 7,700 ST / 1M tokens | 1M | https://apistorehub.com/llms/models/claude-sonnet-5-5.md |
| `gemini-4-neon` | 20,400 ST / 1M tokens | 2M | https://apistorehub.com/llms/models/gemini-4-neon.md |

## FAQ
- **Does Semantic Kernel `AutoInvokeKernelFunctions` work on API Store Hub?**: Yes. OpenAI-compatible tool calling works directly with Semantic Kernel plugins.
- **Is `Microsoft.Extensions.AI` (`IChatClient`) supported?**: Yes. Wrap the configured `OpenAIClient` with `.AsChatClient()`.
- **Can one .NET service switch between GPT and Claude models?**: Yes. Register keyed chat services pointing to the same `https://apistorehub.com/v1` endpoint with different `modelId`s.
