In-app Mode for .NET

Add AI Runtime protection to a .NET application through the ByteHide App runtime SDK. The SDK intercepts your application's model calls in-process and AI Runtime judges them with your policy.


Prerequisites

  • A ByteHide App runtime project and its project token. See Create a App runtime project.
  • AI Runtime access for your organization, and AI Security included in your plan.

1. Install the Package

For ASP.NET Core applications:

Bash
dotnet add package ByteHide.Monitor.AspNetCore

For any other .NET application:

Bash
dotnet add package ByteHide.Monitor

2. Initialize App runtime

ASP.NET Core

C#
// Program.cs
using ByteHide.Monitor.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

// Add ByteHide Monitor
builder.Services.AddByteHideMonitor(options =>
{
    options.ProjectToken = "YOUR_PROJECT_TOKEN";
});

var app = builder.Build();

// Use ByteHide Monitor middleware
app.UseByteHideMonitor();

app.Run();

Other .NET Applications

C#
using ByteHide.Monitor;

// Initialize Monitor
Monitor.Initialize("YOUR_PROJECT_TOKEN");

// Your application code here...

Project Token from the Environment

Instead of hardcoding the token, set an environment variable. The token is resolved in this order:

  1. BYTEHIDE_MONITOR_TOKEN environment variable
  2. BYTEHIDE_API_TOKEN environment variable
  3. The token set in code or in the configuration file
Bash
export BYTEHIDE_MONITOR_TOKEN="YOUR_PROJECT_TOKEN"

3. Enable AI Security

In the console, open the App runtime project, go to Rules, click Add Rule and pick AI Security. Then choose the AI Runtime policy that governs the project's LLM traffic. See Enable AI Security.


4. Run and Verify

Bash
dotnet run

Send a request that reaches your LLM code, then open AI runtime → Incidences. The checks of your application appear there, linked to the project's in-process route.

For the Monitor-side settings of this protection, see LLM Prompt Injection.


Next Steps

Policies

Choose which detectors run on your application's LLM traffic

Incidences

Investigate what AI Runtime caught

Previous
Overview