HuggingFace.Net 1.0.0

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

HuggingFace.Net

HuggingFace.Net is a .NET client library for interacting with HuggingFace's Inference Endpoints API. It provides a robust and easy-to-use interface for managing and calling HuggingFace machine learning models.

Features

  • 🔐 Secure API Authentication
  • 🚀 Inference Endpoint Management
    • Create, delete, and manage endpoints
    • Scale endpoints up/down
    • Monitor endpoint status
  • 🤖 Model Inference
    • Call models with typed responses
    • Raw response handling
    • Automatic retries with exponential backoff
  • ⚡ Performance
    • Connection pooling
    • Configurable timeouts
    • Rate limit handling
  • 🛡️ Error Handling
    • Custom exceptions for different error scenarios
    • Detailed error messages
    • HTTP status code handling

Installation

You can install the package via NuGet:

dotnet add package HuggingFace.Net

Usage

Here's a quick example of how to use the library:

// Create client with API key
var client = HuggingFaceClientFactory.Create("your-api-key-here", "namespace");

try
{
    // Test connection
    var connected = await client.ConnectAsync();
    Console.WriteLine($"Connected: {connected}");

    // Check endpoint status
    var status = await client.GetEndpointStatusAsync("model-name");
    Console.WriteLine($"Endpoint Status: {status.Status}, Available: {status.IsAvailable}");

    // Call model for text generation
    var input = new Models.TextGenerationInput
    {
        Inputs = "Hello, how are you?",
        Parameters = new Models.TextGenerationParameters
        {
            MaxNewTokens = 50,
            Temperature = 0.7
        }
    };

    var response = await client.CallModelAsync<Models.TextGenerationResponse[]>(
        "model-name", input);
}
catch (HuggingFaceException ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}

Configuration

You can configure the client with custom options:

var options = new HuggingFaceClientOptions
{
    ApiKey = "your-api-key",
    Namespace = "your-namespace",
    BaseUrl = "https://api.endpoints.huggingface.cloud/v2",
    Timeout = TimeSpan.FromSeconds(30),
    MaxRetries = 3,
    RetryDelay = TimeSpan.FromSeconds(1),
    UseExponentialBackoff = true
};

var client = HuggingFaceClientFactory.Create(options);

Error Handling

The library includes custom exceptions for different error scenarios:

  • HuggingFaceException: Base exception for all library errors
  • HuggingFaceAuthenticationException: Authentication errors
  • HuggingFaceRateLimitException: Rate limit exceeded errors

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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.
  • net6.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.0 2,803 6/23/2025
1.0.0-beta.2 147 6/30/2025
1.0.0-beta.1 153 6/24/2025