InferHub.Client 0.2.0

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

InferHub.Client

A small, typed .NET client for InferHub — a self-hosted, Ollama-compatible inference mesh.

Point it at a coordinator, pass a Bearer token, and call chat, generate, model listing and status from C# with typed requests, dependency injection, and no heavy dependencies.

v0.2.0 — blocking + streaming inference. Embeddings, vector data plane, RAG retrieval and admin follow in later phases.

Install

dotnet add package InferHub.Client

Targets net9.0 and net10.0.

Quick start

using InferHub.Client;
using InferHub.Client.Configuration;
using InferHub.Client.Models.Ollama;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddInferHubClient(o =>
{
    o.BaseAddress = new Uri("http://localhost:5080");
    o.ApiKey = "<your-client-api-key>";
});

var provider = services.BuildServiceProvider();
var client = provider.GetRequiredService<IInferHubClient>();

var chat = await client.ChatAsync(new ChatRequest
{
    Model = "llama3",
    Messages = new[]
    {
        new ChatMessage { Role = "user", Content = "Say hi in one word." }
    },
    Stream = false
}, CancellationToken.None);

Console.WriteLine(chat.Message?.Content);

What ships in v0.2.0

Method Endpoint
ListModelsAsync GET /api/tags
GenerateAsync (blocking) POST /api/generate with stream:false
ChatAsync (blocking) POST /api/chat with stream:false
ChatStreamAsync POST /api/chat with stream:true (NDJSON → IAsyncEnumerable<ChatResponse>)
GenerateStreamAsync POST /api/generate with stream:true (NDJSON → IAsyncEnumerable<GenerateResponse>)
GetStatusAsync GET /api/status
PingAsync GET /health

Streaming

await foreach (var chunk in client.ChatStreamAsync(new ChatRequest
{
    Model = "llama3",
    Messages = new[] { new ChatMessage { Role = "user", Content = "Stream me a haiku." } }
}, cancellationToken))
{
    Console.Write(chunk.Message?.Content);
}

The enumerator stops as soon as a chunk arrives with done:true. A terminal error chunk ({ "error": …, "done": true }) is surfaced as InferHubException — the client never retries mid-stream, so a partial answer plus a clean exception is the contract. Cancelling the token throws promptly out of the await foreach.

Request models carry an extension bag (AdditionalProperties), so any unknown fields from the Ollama contract pass through untouched — you can hand-set options, format, tool definitions, etc. without waiting on the client to type them.

Auth

  • Non-loopback calls need ApiKey (attached as Authorization: Bearer <key> by a DelegatingHandler).
  • Loopback calls to the coordinator skip auth by default (unless the coordinator sets Auth:RequireAuthForLoopback=true).
  • /health is always open.
  • Admin routes require a separate AdminApiKey and land on a dedicated interface in a later phase; a client key alone never surfaces admin methods.

Errors

Any non-success HTTP response is surfaced as InferHubException, carrying:

  • StatusCode — the HTTP status
  • Message — the coordinator's { "error": "…" } body if present

The client treats 404 (model missing) and 424 Failed Dependency (retrieval unavailable, added in a later phase) as distinct signals worth checking with StatusCode.

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
1.0.0 98 7/9/2026
0.6.0 100 7/8/2026
0.5.0 90 7/7/2026
0.4.0 95 7/6/2026
0.3.0 97 7/5/2026
0.2.0 94 7/4/2026
0.1.0 90 7/3/2026