Configuration Object
The KoruAI middleware accepts a configuration object with the following parameters:Required Parameters
Your KoruAI API key for authentication with KoruAI servers. Example:
"koru_api_1234567890abcdef"
Keep this secret and never expose it in client-side code.
Your application ID for identifying your app in the KoruAI system.
Example:
"app_9876543210fedcba"
Optional Parameters
Whether to check for anomalies in real-time and block suspicious requests.
true
: Middleware will check for anomalies in real-time and block requests if anomalies are detectedfalse
: Middleware will send request data to KoruAI servers for analysis and dashboard reporting only
Environment Variables
Required Environment Variables
Optional Environment Variables
Configuration Examples
Basic Configuration
The minimal configuration required to get started:Production Configuration
Recommended configuration for production environments:Environment-Specific Configuration
Different settings for different environments:Conditional Integration
Enable KoruAI only when needed:Security Configuration
API Key Management
Development Keys
Use separate API keys for development environments with limited permissions
Production Keys
Use production keys only in production with full security features enabled
Key Rotation Strategy
Real-time Blocking Configuration
Understanding Real-time Blocking
WhenblockRealtime
is enabled:
- Request Analysis: Each request is analyzed against your custom AI-generated policies
- Instant Decision: Anomalies are detected in real-time (< 1ms)
- Automatic Blocking: Suspicious requests receive a 403 response
- Zero Latency: Normal requests pass through with 0ms added latency
Blocking Response Format
When a request is blocked, KoruAI returns:403 Forbidden
Custom Blocking Responses
Currently, KoruAI uses a standard blocking response. For custom responses, you can implement additional middleware:Performance Configuration
High Traffic Optimization
KoruAI is optimized for high-traffic applications:Memory Management
KoruAI automatically manages memory efficiently:- Minimal footprint: < 1MB memory usage
- No request queuing: Asynchronous processing prevents memory buildup
- Automatic cleanup: Request data is processed and released immediately
Monitoring and Debugging
Debug Configuration
Enable detailed logging for troubleshooting:Health Check Integration
Monitor KoruAI status in your health checks:Configuration Validation
Runtime Validation
Validate your configuration at startup:TypeScript Configuration
For TypeScript projects, ensure proper typing:Best Practices
Configuration Management
Use environment-specific configurations
Use environment-specific configurations
Different environments should have different settings. Development should
focus on monitoring, while production should enable real-time blocking.
Validate configuration at startup
Validate configuration at startup
Always validate your KoruAI configuration during application startup to
catch issues early.
Implement graceful degradation
Implement graceful degradation
If KoruAI configuration is missing or invalid, decide whether to fail fast
or continue without protection.
Monitor configuration changes
Monitor configuration changes
Log configuration changes and monitor for unexpected behavior after updates.
Security Considerations
- Never log API keys: Ensure API keys are never written to logs or error messages
- Use secure storage: Store API keys in secure configuration management systems
- Regular rotation: Rotate API keys regularly and have a process for emergency rotation
- Principle of least privilege: Use different keys with appropriate permissions for different environments
Troubleshooting
Common Configuration Issues
Invalid API key format
Invalid API key format
Error: API key validation failed Solution: Ensure your API key
starts with
koru_
and matches the format from your dashboardMissing environment variables
Missing environment variables
Error: Configuration missing or undefined Solution: Check that
KORUAI_API_KEY
and KORUAI_APP_ID
are set in your environmentReal-time blocking not working
Real-time blocking not working
Error: Requests not being blocked despite
blockRealtime: true
Solution: Ensure you have created policies in your dashboard and have
sufficient training data