Deployment Configuration¶
Configure Apiary for production deployment.
Production Settings¶
Using Inline Keys¶
{
"api_keys": "strong-random-key-1,strong-random-key-2",
"enable_landing_page": true,
"enable_docs": true,
"enable_redoc": true,
"enable_openapi": true,
"enabled_routers": ["health", "metrics", "auth", "endpoints"],
"rate_limit_enabled": true,
"rate_limit_per_minute": 60,
"rate_limit_per_minute_authenticated": 300
}
Using File-Based Keys (Recommended for Production)¶
{
"api_keys": "config/api_keys.txt",
"enable_landing_page": true,
"enable_docs": false,
"enable_redoc": false,
"enable_openapi": false,
"enabled_routers": ["health", "metrics", "auth", "endpoints"],
"rate_limit_enabled": true,
"rate_limit_per_minute": 60,
"rate_limit_per_minute_authenticated": 300
}
Create config/api_keys.txt:
Environment Variables¶
export API_KEYS="prod-key-1,prod-key-2"
export RATE_LIMIT_ENABLED=true
export ENABLE_DOCS=false
export ENABLE_REDOC=false
Security¶
- Use strong API keys (32+ characters, random)
- Use file-based keys in production for easier rotation
- Enable HTTPS with SSL/TLS
- Restrict file permissions:
- Disable API docs in production (
enable_docs,enable_redoc,enable_openapi) - Enable rate limiting
- Use environment variables for sensitive configuration
Performance Tuning¶
Gunicorn Workers¶
Workers = (2 x CPU cores) + 1
Multi-Worker Consideration
Rate limiting and metrics use in-memory storage that is not shared between
workers. With 4 workers, clients effectively get 4x the configured rate
limit and /metrics shows per-worker data. Use a single worker if accurate
rate limiting is critical, or use Redis for shared state.
nginx¶
Next Steps¶
- Server Setup - Initial setup
- Updating - Update workflow and strategies
- Monitoring - Set up monitoring