OllamaClient 2.1.0

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

OllamaClient

.NET client library for Ollama — run large language models locally and integrate them into your C# applications with minimal boilerplate.

build and test NuGet Downloads License: MIT

Quick Start

Install:

dotnet add package OllamaClient

Use:

using Microsoft.Extensions.DependencyInjection;
using OllamaClient;
using OllamaClient.Extensions;

var services = new ServiceCollection()
    .AddOllamaClient()          // defaults to http://localhost:11434/
    .BuildServiceProvider();

var client = services.GetRequiredService<IOllamaHttpClient>();

// List available models
var models = await client.GetModels(CancellationToken.None);

// Streaming chat
await foreach (var chunk in client.SendChat(new ChatStreamRequest
{
    Model = models.Models[0].Name,
    Messages = [new Message { Role = "user", Content = "Hello!" }]
}, CancellationToken.None))
{
    Console.Write(chunk.Message?.Content);
}

Features

Endpoint Method Streaming
GET /api/tags GetModels() —
POST /api/generate Generate() Generate(GenerateStreamRequest)
POST /api/chat SendChat() SendChat(ChatStreamRequest)
POST /api/create Create() Create(CreateModelStreamRequest)
HEAD /api/blobs/:digest BlobExists() —
POST /api/blobs/:digest PushBlob() —
POST /api/copy Copy() —
DELETE /api/delete Delete() —
POST /api/show Show() —
POST /api/pull Pull() Pull(PullStreamRequest)
POST /api/push Push() Push(PushStreamRequest)
POST /api/embed Embed() —
POST /api/embeddings GetEmbeddings() (obsolete) —
GET /api/ps GetRunningModels() —
GET /api/version GetVersion() —
GET /api/status GetStatus() —

Also covered: tool calling (with tool-call ids), structured outputs, images, thinking (Think = true or an effort level such as ThinkValue.High), token log probabilities (Logprobs, TopLogprobs), done_reason, and cloud-model metadata.

Thinking and log probabilities

var response = await client.SendChat(new ChatRequest
{
    Model = "qwen3",
    Messages = [new() { Role = "user", Content = "Is 9.11 bigger than 9.9?" }],
    Think = ThinkValue.Low,      // or true / false
    Logprobs = true,
    TopLogprobs = 3,
}, ct);

Console.WriteLine(response.Message!.Thinking);  // the reasoning trace
Console.WriteLine(response.Message.Content);    // the answer
Console.WriteLine(response.DoneReason);         // "stop" or "length"

Creating a model

/api/create no longer takes a Modelfile. Derive from an existing model, or upload GGUF/safetensors files as blobs first:

await client.Create(new CreateModelRequest
{
    Model = "mario",
    From = "llama3.2",
    System = "You are Mario from Super Mario Bros.",
    Parameters = new() { ["temperature"] = 0.7 },
}, ct);

Stateful multi-turn chat is available via IStatefulConversationOllamaService, which manages message history automatically across turns.

Configuration

Dependency injection (default endpoint)

services.AddOllamaClient();
// connects to http://localhost:11434/

Custom base URL

services.AddOllamaClient(cfg =>
{
    cfg.OllamaEndpoint = "http://my-ollama-host:11434/";
});

Timeout

Configure the underlying HttpClient via the standard IHttpClientBuilder:

services.AddOllamaClient();
services.AddHttpClient<OllamaHttpClient>()
        .ConfigureHttpClient(c => c.Timeout = TimeSpan.FromMinutes(5));

Examples

See src/OllamaClient.QuickStart/ for a runnable console app demonstrating pull, list, and streaming chat.

Compatibility

OllamaClient .NET Minimum Ollama
2.1.x net9.0, net10.0 API of Ollama 0.40; tested live against 0.34
2.0.x net9.0, net10.0 0.1.x
1.1.x net9.0, net10.0 0.1.x
1.0.x net8.0 0.1.x

Contributing

Pull requests are welcome. Please read CONTRIBUTING.md before opening an issue or PR.

License

MIT — see LICENSE.

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 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

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.1.0 203 10/12/2026
2.0.1 1,872 7/13/2026
2.0.0 168 5/31/2026
1.1.0 148 5/27/2026
1.0.0 1,980 4/21/2024