Zonit.Extensions.Ai.Infrastructure 1.0.55

dotnet add package Zonit.Extensions.Ai.Infrastructure --version 1.0.55
                    
NuGet\Install-Package Zonit.Extensions.Ai.Infrastructure -Version 1.0.55
                    
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="Zonit.Extensions.Ai.Infrastructure" Version="1.0.55" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zonit.Extensions.Ai.Infrastructure" Version="1.0.55" />
                    
Directory.Packages.props
<PackageReference Include="Zonit.Extensions.Ai.Infrastructure" />
                    
Project file
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 Zonit.Extensions.Ai.Infrastructure --version 1.0.55
                    
#r "nuget: Zonit.Extensions.Ai.Infrastructure, 1.0.55"
                    
#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 Zonit.Extensions.Ai.Infrastructure@1.0.55
                    
#: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=Zonit.Extensions.Ai.Infrastructure&version=1.0.55
                    
Install as a Cake Addin
#tool nuget:?package=Zonit.Extensions.Ai.Infrastructure&version=1.0.55
                    
Install as a Cake Tool

Zonit.Extensions.Ai

A .NET library for integrating with multiple AI providers (OpenAI, Anthropic Claude, X Grok, Google Gemini) with Scriban templating, type-safe prompts, and built-in resilience.

Installation

Install-Package Zonit.Extensions.Ai

Quick Start

// 1. Register services
services.AddAi(options =>
{
    options.OpenAiKey = "your-openai-api-key";
    options.AnthropicKey = "your-anthropic-api-key";
    options.XKey = "your-x-api-key";
    options.GoogleKey = "your-google-api-key";
});

// 2. Create a prompt with Scriban templating
public class TranslatePrompt : PromptBase<TranslateResponse>
{
    public required string Content { get; set; }
    public required string Language { get; set; }

    public override string Prompt => @"
Translate the following text into {{ language }}:
{{ content }}
";
}

// 3. Generate response
var result = await aiClient.GenerateAsync(
    new TranslatePrompt { Content = "Hello!", Language = "Polish" }, 
    new GPT51()
);
Console.WriteLine(result.Value.TranslatedText);

Supported Models

OpenAI

Model Class Features
GPT-5, GPT-5.1 GPT5, GPT51, GPT51Chat Text, Vision, Image output
GPT-5 Mini/Nano GPT5Mini, GPT5Nano Cost-effective
GPT-4.1 GPT41, GPT41Mini, GPT41Nano Latest GPT-4
O3, O4-mini O3, O4Mini Reasoning models
GPT-4o Search GPT4oSearch Web search
DALL�E GPTImage1, GPTImage1Mini Image generation

Anthropic (Claude)

Model Class Features
Sonnet 4.5 Sonnet45 Balanced, prompt caching
Opus 4, 4.1 Opus4, Opus41 Most capable
Haiku 4.5 Haiku45 Fast, cost-effective

X (Grok)

Model Class Features
Grok-4 Grok4 Web search native
Grok-4.1 Grok41FastReasoning, Grok41FastNonReasoning Advanced reasoning
Grok-3 Grok3, Grok3Fast, Grok3Mini, Grok3MiniFast Previous gen
GrokCodeFast1 GrokCodeFast1 Code specialized

Scriban Templating

Properties are automatically available in templates (PascalCase ? snake_case):

public class MyPrompt : PromptBase<MyResponse>
{
    public string Name { get; set; }           // {{ name }}
    public List<string> Items { get; set; }    // {{ items }}
    public bool IsActive { get; set; }         // {{ is_active }}

    public override string Prompt => @"
Hello {{ name }}!

{{~ if is_active ~}}
Your items:
{{~ for item in items ~}}
- {{ item }}
{{~ end ~}}
{{~ end ~}}
";
}

Whitespace control: {{~ removes whitespace before, ~}} removes after.

Excluded properties: Tools, ToolChoice, UserName, Files, ModelType

AI Tools

Web Search (OpenAI)

public class SearchPrompt : PromptBase<SearchResponse>
{
    public required string Query { get; set; }
    public override string Prompt => "Search for: {{ query }}";
    
    public override IReadOnlyList<ITool> Tools => 
        new[] { new WebSearchTool { ContextSize = WebSearchTool.ContextSizeType.High } };
    public override ToolsType ToolChoice => ToolsType.WebSearch;
}
var grok = new Grok4
{
    WebSearch = new Search
    {
        Mode = ModeType.Always,           // Always, Never, Auto
        Citations = true,
        MaxResults = 20,
        FromDate = DateTime.UtcNow.AddMonths(-6),
        ToDate = DateTime.UtcNow,
        Language = "en",                  // ISO 639-1
        Region = "US",                    // ISO 3166-1 alpha-2
        Sources = new ISearchSource[]
        {
            new WebSearchSource
            {
                AllowedWebsites = new[] { "wikipedia.org", "github.com" },
                SafeSearch = true
            },
            new XSearchSource
            {
                IncludedXHandles = new[] { "OpenAI", "anthropaborAI" }
            }
        }
    }
};
public class DocumentPrompt : PromptBase<AnalysisResult>
{
    public override IReadOnlyList<IFile> Files { get; set; }
    public override IReadOnlyList<ITool> Tools => new[] { new FileSearchTool() };
    public override ToolsType ToolChoice => ToolsType.FileSearch;
    
    public override string Prompt => "Analyze the documents";
}

File Management

// Create from path
var file = await FileModel.CreateFromFilePathAsync("image.jpg");

// Create from bytes
var file = new FileModel("doc.pdf", "application/pdf", bytes);

// Save
await file.SaveToFileAsync("output.jpg");

Supported formats: JPG, PNG, GIF, WebP, PDF, DOC/DOCX, XLS/XLSX, PPT/PPTX, TXT, JSON, CSV, XML

Image Generation

public class ImagePrompt : PromptBase<IFile>
{
    public required string Description { get; set; }
    public override string Prompt => "Generate: {{ description }}";
}

var result = await aiClient.GenerateAsync(
    new ImagePrompt { Description = "A sunset over mountains" },
    new GPTImage1
    {
        Quality = GPTImage1.QualityType.High,    // Standard, High
        Size = GPTImage1.SizeType.Landscape,      // Square, Portrait, Landscape
        Style = GPTImage1.StyleType.Natural       // Natural, Vivid
    }
);
await result.Value.SaveToFileAsync("sunset.png");

Model Configuration

// Text models
var model = new GPT51
{
    MaxTokens = 4000,
    Temperature = 0.7,
    TopP = 0.9,
    StoreLogs = true
};

// Reasoning models
var reasoning = new O3
{
    Reason = OpenAiReasoningBase.ReasonType.High,
    ReasonSummary = OpenAiReasoningBase.ReasonSummaryType.Detailed
};

// Check capabilities
if (model.SupportedTools.HasFlag(ToolsType.WebSearch)) { /* ... */ }
if (model.SupportedFeatures.HasFlag(FeaturesType.Streaming)) { /* ... */ }

Metadata & Costs

var result = await aiClient.GenerateAsync(prompt, model);

Console.WriteLine($"Tokens: {result.MetaData.InputTokenCount} in / {result.MetaData.OutputTokenCount} out");
Console.WriteLine($"Cost: ${result.MetaData.PriceTotal:F6}");
Console.WriteLine($"Duration: {result.MetaData.Duration.TotalSeconds:F2}s");

JSON Schema Responses

The library auto-generates JSON Schema from response classes:

[Description("Translation result")]
public class TranslateResponse
{
    [Description("Translated text")]
    public string TranslatedText { get; set; }
    
    [Description("Detected source language")]
    public string DetectedLanguage { get; set; }
}

Resilience Configuration

Uses Microsoft.Extensions.Http.Resilience with unified config for all providers:

{
  "Ai": {
    "Resilience": {
      "HttpClientTimeout": "00:30:00",
      "TotalRequestTimeout": "00:25:00",
      "AttemptTimeout": "00:20:00",
      "Retry": {
        "MaxRetryAttempts": 3,
        "BaseDelay": "00:00:02",
        "MaxDelay": "00:00:30",
        "UseJitter": true
      },
      "CircuitBreaker": {
        "FailureRatio": 0.5,
        "MinimumThroughput": 10,
        "SamplingDuration": "00:02:00",
        "BreakDuration": "00:00:30"
      }
    }
  }
}

Error Handling

try
{
    var result = await aiClient.GenerateAsync(prompt, model);
}
catch (JsonException ex)
{
    // JSON parsing error
}
catch (InvalidOperationException ex)
{
    // API error (after retries exhausted)
}

Architecture

Clean Architecture with layered separation:

  • Abstractions - Interfaces and contracts
  • Domain - Models and business logic
  • Application - Services, configuration, Scriban prompt service
  • Infrastructure - Provider implementations (OpenAI, Anthropic, X, Google)
  • LLM - Model definitions and tools
  • Prompts - Example templates
Product 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 is compatible.  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 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Zonit.Extensions.Ai.Infrastructure:

Package Downloads
Zonit.Extensions.Ai

A powerful and versatile library for integrating AI models like OpenAI, DeepSeek, Claude, Grok, and Gemini. Easily build chatbots, generate text and images, and enhance your applications with cutting-edge AI capabilities.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.55 36 1/15/2026
1.0.54 461 12/8/2025
1.0.53 207 11/24/2025
1.0.52 245 11/22/2025
1.0.51 423 11/20/2025
1.0.50 427 11/18/2025
1.0.26 225 8/27/2025
1.0.25 229 8/7/2025
1.0.24 220 8/7/2025
1.0.23 134 7/28/2025
1.0.22 145 7/28/2025
1.0.21 149 7/27/2025
1.0.20 113 7/12/2025
1.0.19 121 7/11/2025
1.0.18 160 7/10/2025
1.0.17 147 7/10/2025
1.0.16 145 7/10/2025
1.0.15 147 7/10/2025
1.0.14 151 7/8/2025
1.0.13 147 7/8/2025
1.0.12 144 7/7/2025
1.0.11 112 7/4/2025
1.0.10 106 7/4/2025
1.0.9 113 7/4/2025
1.0.8 144 7/4/2025
1.0.7 150 7/4/2025
1.0.6 150 7/3/2025
1.0.5 145 7/3/2025
1.0.4 149 7/3/2025
1.0.3 143 7/3/2025
1.0.2 148 7/3/2025
1.0.1 153 7/3/2025
1.0.0 155 7/3/2025
0.0.9 178 6/3/2025
0.0.8 143 6/3/2025
0.0.7 183 5/20/2025
0.0.6 148 5/20/2025
0.0.5 150 5/20/2025
0.0.4 156 5/19/2025
0.0.3 153 5/19/2025
0.0.2 154 5/19/2025
0.0.1 176 5/2/2025