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:
dotnet add package ByteHide.Monitor.AspNetCoredotnet add package ByteHide.Monitor.AspNetCoreFor any other .NET application:
dotnet add package ByteHide.Monitordotnet add package ByteHide.Monitor2. Initialize App runtime
ASP.NET Core
// 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();// 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
using ByteHide.Monitor;
// Initialize Monitor
Monitor.Initialize("YOUR_PROJECT_TOKEN");
// Your application code here...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:
BYTEHIDE_MONITOR_TOKENenvironment variableBYTEHIDE_API_TOKENenvironment variable- The token set in code or in the configuration file
export BYTEHIDE_MONITOR_TOKEN="YOUR_PROJECT_TOKEN"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
dotnet rundotnet runSend 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