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:
pip install bytehide-monitor-flaskpip install bytehide-monitor-flaskFor any other Python application:
pip install bytehide-monitorpip install bytehide-monitor2. Initialize App runtime
Flask
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()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
from bytehide_monitor import Monitor
# Initialize Monitor
monitor = Monitor(project_token='YOUR_PROJECT_TOKEN')
monitor.start()
# Your application code here...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:
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
python app.pypython app.pySend 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