Sdks
C# / .NET SDK
Official C# / .NET client library for Unii platform with async/await and IAsyncEnumerable streaming.
Overview
The Unii .NET SDK (Unii.Sdk) provides a modern C# client for .NET 8 and .NET 9 applications, featuring async/await methods, real-time token streaming with IAsyncEnumerable, and structured error handling.
Installation
Install Unii.Sdk via the .NET CLI:
dotnet add package Unii.SdkInitialize and use the client
Initialize the client with your API key, then verify credentials or send chat completions:
using Unii.Sdk;
var client = new UniiClient(Environment.GetEnvironmentVariable("UNII_API_KEY")!);
// 1. Verify credentials
var auth = await client.VerifyAuthAsync();
Console.WriteLine("Key: " + auth.KeyName);
// 2. Synchronous chat completion
var response = await client.CreateChatCompletionAsync(new ChatCompletionRequest
{
Messages = new List<ChatMessage>
{
ChatMessage.User("What is the return policy?")
}
});
Console.WriteLine(response.Choices[0].Message.Content);
// 3. Real-time streaming with IAsyncEnumerable
await foreach (var chunk in client.StreamChatCompletionAsync(new ChatCompletionRequest
{
Messages = new List<ChatMessage> { ChatMessage.User("Explain warranty terms.") }
}))
{
Console.Write(chunk.Choices[0].Delta.Content);
}
// 4. Exception handling
try
{
await client.VerifyAuthAsync();
}
catch (UniiApiException ex)
{
Console.WriteLine($"API error ({ex.StatusCode}): {ex.Message}");
}