PrimusSaaS.AI
2.0.0
dotnet add package PrimusSaaS.AI --version 2.0.0
NuGet\Install-Package PrimusSaaS.AI -Version 2.0.0
<PackageReference Include="PrimusSaaS.AI" Version="2.0.0" />
<PackageVersion Include="PrimusSaaS.AI" Version="2.0.0" />
<PackageReference Include="PrimusSaaS.AI" />
paket add PrimusSaaS.AI --version 2.0.0
#r "nuget: PrimusSaaS.AI, 2.0.0"
#:package PrimusSaaS.AI@2.0.0
#addin nuget:?package=PrimusSaaS.AI&version=2.0.0
#tool nuget:?package=PrimusSaaS.AI&version=2.0.0
Primus.AI SDK
AI integration SDK for .NET applications. Provides unified abstraction over Azure OpenAI and GitHub Models with tenant isolation, token budgets, prompt injection detection, and structured outputs.
Installation
dotnet add package Primus.AI
Quick Start
Basic Setup (Azure OpenAI)
using Primus.AI;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddPrimusAI(ai =>
{
ai.UseAzureOpenAI(opts =>
{
opts.Endpoint = builder.Configuration["AzureOpenAI:Endpoint"];
opts.ApiKey = builder.Configuration["AzureOpenAI:ApiKey"];
opts.DefaultDeployment = "gpt-4o";
});
ai.ConfigureDefaults(opts =>
{
opts.MaxTokens = 4096;
opts.Temperature = 0.7f;
});
// Enable safety features
ai.EnablePromptInjectionDetection();
ai.EnableTokenBudgets(budget =>
{
budget.DefaultDailyLimit = 100_000;
budget.EnforceLimits = true;
});
});
Using GitHub Models
builder.Services.AddPrimusAI(ai =>
{
ai.UseGitHubModels(opts =>
{
opts.Token = builder.Configuration["GitHub:Token"];
opts.DefaultModel = "gpt-4o";
});
});
Chat Completion
public class ChatController : ControllerBase
{
private readonly IAIClient _aiClient;
public ChatController(IAIClient aiClient)
{
_aiClient = aiClient;
}
[HttpPost("chat")]
public async Task<IActionResult> Chat([FromBody] ChatRequest request)
{
var response = await _aiClient.ChatAsync(new ChatCompletionRequest
{
Messages =
[
ChatMessage.System("You are a helpful assistant."),
ChatMessage.User(request.Message)
],
MaxTokens = 1000
});
return Ok(new { response.Content, response.TokensUsed });
}
}
Multi-Tenant with Token Budgets
builder.Services.AddPrimusAI(ai =>
{
ai.UseAzureOpenAI(opts => { /* config */ });
ai.ConfigureTenantIsolation(opts =>
{
opts.Enabled = true;
opts.TenantIdClaimType = "tenant_id";
});
ai.EnableTokenBudgets(budget =>
{
budget.DefaultDailyLimit = 50_000;
budget.DefaultMonthlyLimit = 1_000_000;
budget.EnforceLimits = true;
budget.TrackByTenant = true;
});
});
// In your service:
public class TenantAwareAIService
{
private readonly IAIClient _aiClient;
private readonly ITenantContext _tenantContext;
public async Task<string> GenerateAsync(string prompt)
{
// Token usage is automatically tracked per tenant
var response = await _aiClient.ChatAsync(
new ChatCompletionRequest { /* ... */ },
tenantId: _tenantContext.TenantId);
return response.Content;
}
}
Prompt Injection Detection
builder.Services.AddPrimusAI(ai =>
{
ai.UseAzureOpenAI(opts => { /* config */ });
ai.EnablePromptInjectionDetection(opts =>
{
opts.BlockSuspiciousPrompts = true;
opts.LogDetections = true;
opts.CustomPatterns =
[
@"ignore\s+(previous|all)\s+instructions",
@"you\s+are\s+now\s+DAN"
];
});
});
Structured Outputs (JSON Mode)
public record ProductDescription(string Title, string Summary, string[] Features);
var response = await _aiClient.ChatAsync<ProductDescription>(new ChatCompletionRequest
{
Messages =
[
ChatMessage.System("Generate a product description in JSON format."),
ChatMessage.User("Describe a wireless gaming mouse.")
],
ResponseFormat = ResponseFormat.Json
});
// response.Content is a deserialized ProductDescription
Console.WriteLine(response.Content.Title);
Streaming Responses
await foreach (var chunk in _aiClient.StreamChatAsync(request))
{
Console.Write(chunk.Content);
}
Configuration
appsettings.json
{
"PrimusAI": {
"Provider": "AzureOpenAI",
"AzureOpenAI": {
"Endpoint": "https://your-resource.openai.azure.com/",
"ApiKey": "your-api-key",
"DefaultDeployment": "gpt-4o"
},
"Defaults": {
"MaxTokens": 4096,
"Temperature": 0.7
},
"TokenBudget": {
"DefaultDailyLimit": 100000,
"EnforceLimits": true
},
"PromptInjection": {
"Enabled": true,
"BlockSuspiciousPrompts": true
}
}
}
Environment Variables
PRIMUSAI__PROVIDER=AzureOpenAI
PRIMUSAI__AZUREOPENAI__ENDPOINT=https://your-resource.openai.azure.com/
PRIMUSAI__AZUREOPENAI__APIKEY=your-api-key
PRIMUSAI__AZUREOPENAI__DEFAULTDEPLOYMENT=gpt-4o
Features
| Feature | Description |
|---|---|
| Provider Abstraction | Unified API over Azure OpenAI and GitHub Models |
| Tenant Isolation | Automatic context separation for multi-tenant apps |
| Token Budgets | Track and enforce token usage per tenant |
| Prompt Injection Detection | Detect and block malicious prompts |
| Structured Outputs | JSON mode with automatic deserialization |
| Streaming | Async streaming responses |
| Retry Policies | Built-in exponential backoff |
SDK-Only Design
This SDK runs entirely in your application. It does NOT:
- Store any prompts or responses
- Proxy requests through Primus servers
- Collect telemetry or usage data
All API calls go directly to Azure OpenAI or GitHub Models using your credentials.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
-
net6.0
- Azure.AI.OpenAI (>= 2.0.0)
- Azure.Identity (>= 1.12.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- System.Text.Json (>= 8.0.5)
-
net7.0
- Azure.AI.OpenAI (>= 2.0.0)
- Azure.Identity (>= 1.12.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- System.Text.Json (>= 8.0.5)
-
net8.0
- Azure.AI.OpenAI (>= 2.0.0)
- Azure.Identity (>= 1.12.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- 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.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 104 | 1/12/2026 |
v2.0.0:
- Standardized Framework Release.
- Renamed all packages to PrimusSaaS.* namespace.
- Synchronized versions across the entire suite.
- Enhanced metadata and fixed consistency issues.