DotnetAi.Sdk 1.0.1

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

DotnetAi.Sdk

Unified and extensible .NET SDK for interacting with LLMs like OpenAI, Claude (Anthropic), and DeepSeek – using a single interface.

Quick Start

using DotentAi.Sdk;
using DotentAi.Sdk.Models;

AiClient client = new("openai", "sk-your-api-key");

ChatRequest request = new()
{
    Model = "gpt-4.1",
    Prompt = "What is the capital of Romania?"
};

string response = await client.SendAsync(request);
Console.WriteLine(response);

ChatRequest Parameters

The ChatRequest object defines how a chat interaction is structured. It supports both simple prompts and multi-turn messages.

Property Type Required Description
Prompt string? Optional Quick prompt (if not using messages)
Messages List<ChatMessage> Optional Structured conversation messages
Model string? Optional Specific model name (gpt-4, claude-3-opus, etc.)
Temperature float (default: 0.7) Optional Controls randomness. Range depends on model (see below).
MaxTokens int (default: 1000) Optional Maximum response token count

Temperature Parameter

The temperature parameter controls how random or creative the AI's response will be. Lower values make the output more focused and deterministic. Higher values increase variability and originality, but can sometimes reduce coherence.

Provider Temperature Range
OpenAI 0.0 - 2.0
Claude 0.0 - 1.0
DeepSeek 0.0 - 1.5

Supported Models

Advanced Usage

With ChatMessage history

The ChatMessage object defines each message within a conversation.

Each message includes:

Property Type Description
Role string The speaker’s role: must be "user" or "assistant"
Content string The message text
List<ChatMessage> messages =
[
    new() { Role = "user", Content = "What is 5 + 3?" },
    new() { Role = "assistant", Content = "5 + 3 = 8" },
    new() { Role = "user", Content = "Add 10" }
];

string response = await client.SendAsync(new ChatRequest
{
    Model = "gpt-4.1",
    Messages = messages,
    Temperature = 0.0f,
    MaxTokens = 20
});

Console.WriteLine(response);

Advanced Prompting: Putting Words in the AI's Mouth

You can guide some AI models to produce tightly constrained output, for example, forcing them to pick a single answer like A, B, or C, by using a crafted assistant message and limiting MaxTokens.

This technique is inspired by Anthropic's example and works well with some openai and claude models. May not work with deepseek in current implementation.

Example
List<ChatMessage> messages =
[
    new() { Role = "user", Content = "What is latin for Ant? (A) Apoidea, (B) Rhopalocera, (C) Formicidae" },
    new() { Role = "assistant", Content = "The answer is (" },
];

ChatRequest request = new()
{
    Model = "gpt-4",
    Messages = messages,
    MaxTokens = 1,
};

string response = await client.SendAsync(request);
Console.WriteLine(response); // Output: C
Using custom HttpClient
var http = new HttpClient();
var client = new AiClient("openai", "your-api-key", http);
Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

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
1.0.1 60 6/21/2025
1.0.0 133 6/18/2025

Refactored 'CharRequest': removed redundant 'provider' parameter; handled internally via model.