Website AI Assistant Minimal API

March 11, 2026 ยท View on GitHub

This is a minimal API for a website AI assistant. It provides an endpoint for generating responses based on visitor's input.

The response can be a Prediction or your own custom response (eg. data from database or other source) based on the Prediction.

PackagesVersionDownloads
WebsiteAIAssistantNuget VersionDownloads count
WebsiteAIAssistant.MinimalAPINuget VersionDownloads count

Endpoint

Out of the box, the Minimal API provides a single endpoint:

GET /ai/{input}

MinimalAPI endpoint

Response

The API returns a Prediction by default.

Prediction response

But, you can also implement a Post Prediction Service, in which you can return any response you want.

Eg. you can return information about the predicted category from database or other source.

Just implement the IPostPredictionService interface and register it in the DI container as Scoped.


public interface IPostPredictionService
{
    Task<object> HandlePredictionAsync(HttpRequest request, ModelInput input, Prediction prediction);
}

For example, you can return a Response object with database results (for eg.) or just a string message.

Post Prediction Service response

Negative

Negative

Integration

You create your model and save it as a .zip file, and then just provide the path to load the model in the Minimal API settings.

Add the Nuget package or a reference to the WebsiteAIAssistant.MinimalAPI project in your ASP.NET Core application.

Then, in your Program.cs, add the following lines to register the minimal API:

//Website AI Assistant
builder.Services.AddRouting();
//Optional: register a custom post-prediction service to handle the prediction results
builder.Services.AddScoped<IPostPredictionService, PostPredictionService>();
//Optional: register a custom logger to log the assistant's operations
builder.Services.AddSingleton<IWebsiteAIAssistantLogger, WebsiteAIAssistantLogger>();
builder.Services.AddWebsiteAIAssistant(settings =>
{
    // Path to load model
    string modelPath = Path.Combine(Environment.CurrentDirectory, "SampleWebsite-AI-Model.zip");
    settings.AIModelLoadFilePath = modelPath;

    settings.NegativeConfidenceThreshold = 0.70f;
    settings.NegativeLabel = -1f;
});

Then, add the following lines to map the minimal API endpoint:

//Website AI Assistant
app.UseRouting();
app.MapWebsiteAIAssistant();

where app is WebApplication.

Or you can also add below lines to do the same thing:

//Website AI Assistant
app.UseRouting();
app.UseEndpoints(endpoints =>
{
    endpoints.MapWebsiteAIAssistant();
});

where app is IApplicationBuilder.

Tests

You can browse the Tests to see how to call the Minimal API.

Sample

You can find a sample Minimal API App using the library here.