CommunityToolkit.Aspire.OllamaSharp 13.1.1

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package CommunityToolkit.Aspire.OllamaSharp --version 13.1.1
                    
NuGet\Install-Package CommunityToolkit.Aspire.OllamaSharp -Version 13.1.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="CommunityToolkit.Aspire.OllamaSharp" Version="13.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommunityToolkit.Aspire.OllamaSharp" Version="13.1.1" />
                    
Directory.Packages.props
<PackageReference Include="CommunityToolkit.Aspire.OllamaSharp" />
                    
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 CommunityToolkit.Aspire.OllamaSharp --version 13.1.1
                    
#r "nuget: CommunityToolkit.Aspire.OllamaSharp, 13.1.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.
#:package CommunityToolkit.Aspire.OllamaSharp@13.1.1
                    
#: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=CommunityToolkit.Aspire.OllamaSharp&version=13.1.1
                    
Install as a Cake Addin
#tool nuget:?package=CommunityToolkit.Aspire.OllamaSharp&version=13.1.1
                    
Install as a Cake Tool

CommunityToolkit.Aspire.OllamaSharp library

Registers IOllamaApiClient in the DI container to interact with the Ollama API and optionally supports registering an IChatClient or IEmbeddingGenerator from Microsoft.Extensions.AI.

Getting Started

Prerequisites

  • Ollama HTTP(S) endpoint

Install the package

Install the .NET Aspire OllamaSharp library using the following command:

dotnet add package CommunityToolkit.Aspire.OllamaSharp

Example usage

In the Program.cs file of your project, call the AddOllamaApiClient extension method to register the IOllamaApiClient in the DI container. This method takes the connection name as a parameter:

builder.AddOllamaApiClient("ollama");

Then, in your service, inject IOllamaApiClient and use it to interact with the Ollama API:

public class MyService(IOllamaApiClient ollamaApiClient)
{
    // ...
}
Integration with Microsoft.Extensions.AI

To use the integration with Microsoft.Extensions.AI, call the AddOllamaSharpChatClient or AddOllamaSharpEmbeddingGenerator extension method in the Program.cs file of your project. These methods take the connection name as a parameter, just as AddOllamaApiClient does, and will register the IOllamaApiClient, as well as the IChatClient or IEmbeddingGenerator in the DI container. The IEmbeddingsGenerator is registered with the generic arguments of <string, Embedding<float>>.

Configuring OpenTelemetry

When using the chat client integration, you can optionally configure the OpenTelemetry chat client to control telemetry behavior such as enabling sensitive data:

builder.AddOllamaApiClient("ollama")
    .AddChatClient(otel => otel.EnableSensitiveData = true);

The integration automatically registers the Microsoft.Extensions.AI telemetry source (Experimental.Microsoft.Extensions.AI) with OpenTelemetry for distributed tracing.

Native AOT Support

OllamaSharp supports .NET Native AOT when you provide a custom JsonSerializerContext. This is especially important when working with custom types in chat messages or using libraries like Semantic Kernel with complex vector store results.

First, create a custom JsonSerializerContext that includes all types that will be serialized:

using System.Text.Json.Serialization;
using OllamaSharp.Models;

[JsonSerializable(typeof(ChatRequest))]
[JsonSerializable(typeof(ChatResponseStream))]
[JsonSerializable(typeof(ChatDoneResponseStream))]
// Add your custom types here
public partial class MyCustomJsonContext : JsonSerializerContext
{
}

Then pass it when configuring the client:

builder.AddOllamaApiClient("ollama", settings => 
{
    settings.JsonSerializerContext = MyCustomJsonContext.Default;
});

For more information on Native AOT support with OllamaSharp, see the OllamaSharp Native AOT documentation.

Additional documentation

Feedback & contributing

https://github.com/CommunityToolkit/Aspire

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

This package is not used by any NuGet packages.

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on CommunityToolkit.Aspire.OllamaSharp:

Repository Stars
dotnet/eShop
A reference .NET application implementing an eCommerce site
dotnet/extensions
This repository contains a suite of libraries that provide facilities commonly needed when creating production-ready applications.
foxminchan/BookWorm
The practical implementation of Aspire using Microservices, AI-Agents
davidfowl/aspire-ai-chat-demo
Aspire AI Chat is a full-stack chat sample that combines modern technologies to deliver a ChatGPT-like experience.
Version Downloads Last Updated
13.1.2-beta.518 30 2/17/2026
13.1.2-beta.516 71 2/9/2026
13.1.2-beta.515 72 2/2/2026
13.1.2-beta.514 52 1/30/2026
13.1.2-beta.513 95 1/29/2026
13.1.2-beta.512 47 1/29/2026
13.1.2-beta.511 43 1/28/2026
13.1.2-beta.509 66 1/20/2026
13.1.2-beta.508 46 1/19/2026
13.1.2-beta.507 44 1/19/2026
13.1.2-beta.506 75 1/16/2026
13.1.2-beta.505 46 1/16/2026
13.1.2-beta.504 45 1/16/2026
13.1.1 3,054 1/16/2026
13.1.1-beta.502 44 1/16/2026
13.1.0 392 1/14/2026
13.1.0-beta.499 43 1/14/2026
13.0.1-beta.498 49 1/14/2026
13.0.1-beta.486 74 1/12/2026
13.0.1-beta.468 1,635 12/3/2025
Loading failed