In-app Mode for Python

Add AI Runtime protection to a Python 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. Create the project in the console under App runtime; the setup screen shows the token.
  • AI Runtime access for your organization, and AI Security included in your plan.

1. Install the Package

For Flask applications:

Bash
pip install bytehide-monitor-flask

For any other Python application:

Bash
pip install bytehide-monitor

2. Initialize App runtime

Flask

Python
from flask import Flask
from bytehide_monitor_flask import ByteHideMonitor

app = Flask(__name__)

# Initialize ByteHide Monitor
monitor = ByteHideMonitor(app, project_token='YOUR_PROJECT_TOKEN')

@app.route('/')
def hello():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()

Other Python Applications

Python
from bytehide_monitor import Monitor

# Initialize Monitor
monitor = Monitor(project_token='YOUR_PROJECT_TOKEN')
monitor.start()

# Your application code here...

Initialize App runtime before your application creates its LLM clients, so their calls are intercepted from the first request.

Project Token from the Environment

Instead of hardcoding the token, set it in the environment:

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
python app.py

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.


Next Steps

Policies

Choose which detectors run on your application's LLM traffic

Incidences

Investigate what AI Runtime caught

Previous
.NET