Overview
Guardian API can be configured using environment variables in a.env file located in the backend/ directory.
Configuration File
Createbackend/.env:
Environment Variables
CORS Configuration
Comma-separated list of allowed frontend origins for CORSFormat: Comma-separated URLs (no spaces)Required: Recommended for productionExample:
https://guardian.korymsmith.dev,http://localhost:5173,http://127.0.0.1:5173When deploying to production, ensure your frontend URL is included in this list.
Rate Limiting
Redis connection URL for rate limiting (Upstash compatible)Format:
rediss://default:<token>@<host>:<port>Required: No (rate limiting disabled if not set)Example: rediss://default:abc123@redis-12345.upstash.io:6379Logging
Logging level for the applicationOptions:
DEBUG, INFO, WARNING, ERROR, CRITICALRecommended: INFO for production, DEBUG for developmentModel Configuration
Threshold for sexism classifierRange: 0.0 to 1.0Default: 0.400 (optimized for F1 score)Higher values: Fewer false positives, more false negatives
Lower values: More false positives, fewer false negatives
HuggingFace model name for toxicity detectionOptions: Any HuggingFace toxicity modelDefault:
unitary/unbiased-toxic-robertaSeverity Thresholds
Threshold for “high” severity classificationRange: 0.0 to 1.0Scores >= this value are considered “high” severity
Threshold for “moderate” severity classificationRange: 0.0 to 1.0Scores >= this value (but < SEVERITY_HIGH) are considered “moderate” severity
Threshold for “low” severity classificationRange: 0.0 to 1.0Scores >= this value (but < SEVERITY_MODERATE) are considered “low” severity
Example Configurations
- Development
- Production
- Strict Moderation
Loading Configuration
The API automatically loads the.env file on startup:
See Also
- Rate Limiting - Configure rate limits
- Installation - Setup guide
- Quickstart - Getting started