CompactifAI.Client
10.0.0
dotnet add package CompactifAI.Client --version 10.0.0
NuGet\Install-Package CompactifAI.Client -Version 10.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CompactifAI.Client" Version="10.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CompactifAI.Client" Version="10.0.0" />
<PackageReference Include="CompactifAI.Client" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CompactifAI.Client --version 10.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CompactifAI.Client, 10.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CompactifAI.Client@10.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CompactifAI.Client&version=10.0.0
#tool nuget:?package=CompactifAI.Client&version=10.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CompactifAI.Client
A .NET client library for the CompactifAI API. Easily integrate AI chat completions, text completions, and audio transcription into your .NET applications.
.NET Version Support
| Your .NET Version | Package Version | Install Command |
|---|---|---|
| .NET 10.0 (LTS) | 10.x.x | dotnet add package CompactifAI.Client --version 10.* |
| .NET 9.0 | 9.x.x | dotnet add package CompactifAI.Client --version 9.* |
| .NET 8.0 (LTS) | 8.x.x | dotnet add package CompactifAI.Client --version 8.* |
See VERSIONING.md for the complete versioning strategy.
Installation
# For .NET 10 (latest)
dotnet add package CompactifAI.Client --version 10.*
# For .NET 9
dotnet add package CompactifAI.Client --version 9.*
# For .NET 8
dotnet add package CompactifAI.Client --version 8.*
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 | net10.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Http (>= 10.0.1)
- Microsoft.Extensions.Options (>= 10.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.