CompactifAI.Client
1.1.0
This version has been superseded by version-aligned releases. Please upgrade to the version matching your .NET runtime:
• .NET 8: Use version 8.x.x
• .NET 9: Use version 9.x.x
• .NET 10: Use version 10.x.x
See https://github.com/GmausDev/CompactifAI.Client/blob/main/VERSIONING.md for details.
See the version list below for details.
dotnet add package CompactifAI.Client --version 1.1.0
NuGet\Install-Package CompactifAI.Client -Version 1.1.0
<PackageReference Include="CompactifAI.Client" Version="1.1.0" />
<PackageVersion Include="CompactifAI.Client" Version="1.1.0" />
<PackageReference Include="CompactifAI.Client" />
paket add CompactifAI.Client --version 1.1.0
#r "nuget: CompactifAI.Client, 1.1.0"
#:package CompactifAI.Client@1.1.0
#addin nuget:?package=CompactifAI.Client&version=1.1.0
#tool nuget:?package=CompactifAI.Client&version=1.1.0
CompactifAI.Client
A .NET 8 client library for the CompactifAI API. Easily integrate AI chat completions, text completions, and audio transcription into your .NET applications.
Installation
dotnet add package CompactifAI.Client
Quick Start
Simple Usage (without DI)
using CompactifAI.Client;
// Create client with API key
var client = new CompactifAIClient("your-api-key");
// Simple chat
var response = await client.ChatAsync("What is the capital of France?");
Console.WriteLine(response);
// Output: The capital of France is Paris.
// Chat with system prompt
var response = await client.ChatAsync(
message: "Explain quantum computing",
systemPrompt: "You are a helpful teacher. Explain concepts simply.",
model: CompactifAIModels.DeepSeekR1_Slim);
Dependency Injection (ASP.NET Core)
appsettings.json:
{
"CompactifAI": {
"ApiKey": "your-api-key",
"DefaultModel": "cai-llama-3-1-8b-slim"
}
}
Program.cs:
using CompactifAI.Client.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Option 1: From configuration
builder.Services.AddCompactifAI(builder.Configuration);
// Option 2: With API key directly
builder.Services.AddCompactifAI("your-api-key");
// Option 3: With full configuration
builder.Services.AddCompactifAI(options =>
{
options.ApiKey = "your-api-key";
options.DefaultModel = CompactifAIModels.Llama33_70B_Slim;
options.TimeoutSeconds = 180;
});
Using in a service:
public class MyService
{
private readonly ICompactifAIClient _client;
public MyService(ICompactifAIClient client)
{
_client = client;
}
public async Task<string> GetAnswerAsync(string question)
{
return await _client.ChatAsync(question);
}
}
Features
Chat Completions
using CompactifAI.Client;
using CompactifAI.Client.Models;
// Full control with ChatCompletionRequest
var request = new ChatCompletionRequest
{
Model = CompactifAIModels.Llama4Scout_Slim,
Messages = new List<ChatMessage>
{
ChatMessage.System("You are a helpful coding assistant."),
ChatMessage.User("Write a function to calculate fibonacci numbers in C#")
},
Temperature = 0.7,
MaxTokens = 1000
};
var response = await client.CreateChatCompletionAsync(request);
Console.WriteLine(response.Choices[0].Message?.Content);
Console.WriteLine($"Tokens used: {response.Usage?.TotalTokens}");
Text Completions
// Simple completion
var text = await client.CompleteAsync(
prompt: "The quick brown fox",
maxTokens: 50);
// Full control
var request = new CompletionRequest
{
Model = CompactifAIModels.Llama31_8B_Slim,
Prompt = "Once upon a time",
Temperature = 0.9,
MaxTokens = 200
};
var response = await client.CreateCompletionAsync(request);
Console.WriteLine(response.Choices[0].Text);
Audio Transcription
// Transcribe a file (MP3 recommended)
var text = await client.TranscribeFileAsync("audio.mp3", language: "en");
Console.WriteLine(text);
// Full control with TranscriptionRequest
var request = new TranscriptionRequest
{
FileContent = await File.ReadAllBytesAsync("meeting.mp3"),
FileName = "meeting.mp3",
Model = CompactifAIModels.WhisperLargeV3,
Language = "en"
};
var response = await client.TranscribeAsync(request);
Console.WriteLine($"Duration: {response.Duration}s");
Console.WriteLine($"Text: {response.Text}");
// Access segments for timestamps
foreach (var segment in response.Segments ?? new())
{
Console.WriteLine($"[{segment.Start:F2}s - {segment.End:F2}s] {segment.Text}");
}
List Available Models
var models = await client.ListModelsAsync();
foreach (var model in models.Data)
{
Console.WriteLine($"{model.Id} - {model.OwnedBy}");
}
// Get specific model info
var modelInfo = await client.GetModelAsync(CompactifAIModels.DeepSeekR1_Slim);
Console.WriteLine($"Parameters: {modelInfo.ParametersNumber}");
Available Models
| Model ID | Description |
|---|---|
cai-deepseek-r1-0528-slim |
Flagship model for complex reasoning tasks |
cai-llama-4-scout-slim |
Powerful model for long context tasks |
cai-llama-3-3-70b-slim |
Able to handle complex tasks |
cai-llama-3-1-8b-slim |
Good for simple tasks requiring low latency |
cai-mistral-small-3-1-slim |
Able to handle complex tasks |
whisper-large-v3 |
Speech-to-text (multilingual) |
Use the CompactifAIModels static class for strongly-typed model constants.
Error Handling
try
{
var response = await client.ChatAsync("Hello!");
}
catch (CompactifAIException ex)
{
Console.WriteLine($"API Error: {ex.StatusCode}");
Console.WriteLine($"Message: {ex.Message}");
Console.WriteLine($"Response: {ex.ResponseBody}");
}
Configuration Options
| Option | Default | Description |
|---|---|---|
ApiKey |
(required) | Your CompactifAI API key |
BaseUrl |
https://api.compactif.ai/v1 |
API base URL |
DefaultModel |
cai-llama-3-1-8b-slim |
Default model for requests |
TimeoutSeconds |
120 |
Request timeout |
Getting an API Key
- Subscribe through AWS Marketplace
- Wait for approval (typically 24 hours)
- Access your API key at MultiverseIAM Dashboard
License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.