Reference
Configuration Reference
Complete configuration options and environment variables for CoAI.Dev
Configuration Reference
Complete reference for all CoAI.Dev configuration options, environment variables, and configuration file formats.
Configuration Methods
CoAI.Dev supports multiple configuration methods with the following precedence order:
- Command-line arguments (highest priority)
- Environment variables
- Configuration files (YAML/JSON)
- Default values (lowest priority)
Core Configuration
Database Configuration
# MySQL Database
MYSQL_HOST=localhost # Database host
MYSQL_PORT=3306 # Database port
MYSQL_USER=chatnio # Database username
MYSQL_PASSWORD=secure_password # Database password
MYSQL_DB=chatnio # Database name
MYSQL_CHARSET=utf8mb4 # Character set
MYSQL_SSL=false # Enable SSL connection
# Connection Pool
DB_MAX_OPEN_CONNS=25 # Maximum open connections
DB_MAX_IDLE_CONNS=5 # Maximum idle connections
DB_CONN_MAX_LIFETIME=300 # Connection max lifetime (seconds)
DB_CONN_MAX_IDLE_TIME=300 # Connection max idle time (seconds)
# Performance
DB_SLOW_QUERY_THRESHOLD=2000 # Slow query threshold (ms)
DB_LOG_LEVEL=warn # Database log level (debug, info, warn, error)
Redis Configuration
# Redis Connection
REDIS_HOST=localhost # Redis host
REDIS_PORT=6379 # Redis port
REDIS_PASSWORD= # Redis password (optional)
REDIS_DB=0 # Redis database number
REDIS_PREFIX=chatnio: # Key prefix
# Connection Pool
REDIS_POOL_SIZE=10 # Connection pool size
REDIS_MIN_IDLE_CONNS=5 # Minimum idle connections
REDIS_POOL_TIMEOUT=5 # Pool timeout (seconds)
REDIS_IDLE_TIMEOUT=300 # Idle timeout (seconds)
# Sentinel (for HA setup)
REDIS_SENTINEL_ENABLED=false # Enable Sentinel
REDIS_SENTINEL_HOSTS= # Comma-separated Sentinel hosts
REDIS_SENTINEL_MASTER_NAME=mymaster # Master name
# Cluster (for Redis Cluster)
REDIS_CLUSTER_ENABLED=false # Enable Cluster mode
REDIS_CLUSTER_HOSTS= # Comma-separated cluster hosts
Application Configuration
# Server
SERVER_HOST=0.0.0.0 # Server bind address
SERVER_PORT=8000 # Server port
SERVER_MODE=release # Server mode (debug, release)
SERVER_NAME=CoAI.Dev # Server name
# Security
SECRET=your-jwt-secret-key # JWT secret key (required)
SESSION_SECRET=session-secret # Session secret key
CORS_ORIGINS=* # CORS allowed origins
CORS_CREDENTIALS=true # Allow credentials in CORS
# Rate Limiting
RATE_LIMIT_ENABLED=true # Enable rate limiting
RATE_LIMIT_REQUESTS=100 # Requests per window
RATE_LIMIT_WINDOW=60 # Time window (seconds)
RATE_LIMIT_REDIS_KEY=rate_limit # Redis key prefix
# Request Processing
MAX_REQUEST_SIZE=52428800 # Max request size (50MB)
REQUEST_TIMEOUT=300 # Request timeout (seconds)
WORKER_THREADS=4 # Worker thread count
MAX_CONCURRENT_REQUESTS=100 # Max concurrent requests
Logging Configuration
Log Levels and Formats
# Logging
LOG_LEVEL=info # Log level (debug, info, warn, error)
LOG_FORMAT=json # Log format (json, text)
LOG_OUTPUT=stdout # Log output (stdout, stderr, file)
LOG_FILE=/logs/app.log # Log file path (if LOG_OUTPUT=file)
# Log Rotation
LOG_MAX_SIZE=100 # Max log file size (MB)
LOG_MAX_BACKUPS=30 # Max backup files
LOG_MAX_AGE=7 # Max age (days)
LOG_COMPRESS=true # Compress old logs
# Access Logs
ACCESS_LOG_ENABLED=true # Enable access logs
ACCESS_LOG_FORMAT=combined # Access log format
ACCESS_LOG_FILE=/logs/access.log # Access log file
# Audit Logs
AUDIT_LOG_ENABLED=true # Enable audit logs
AUDIT_LOG_LEVEL=info # Audit log level
AUDIT_LOG_EVENTS=login,logout,admin_action # Events to log
Structured Logging Configuration
# config/logging.yml
logging:
level: info
format: json
output: stdout
fields:
service: chatnio
version: ${APP_VERSION}
environment: ${NODE_ENV:-production}
rotation:
enabled: true
max_size: 100MB
max_backups: 30
max_age: 7d
compress: true
loggers:
app:
level: info
output: /logs/app.log
access:
level: info
output: /logs/access.log
format: combined
audit:
level: info
output: /logs/audit.log
events:
- user_login
- user_logout
- admin_action
- channel_create
- channel_update
- model_access
security:
level: warn
output: /logs/security.log
events:
- failed_login
- rate_limit_exceeded
- suspicious_activity
AI Provider Configuration
OpenAI Configuration
# OpenAI
OPENAI_API_KEY=sk-... # OpenAI API key
OPENAI_BASE_URL=https://api.openai.com/v1 # Base URL
OPENAI_ORGANIZATION=org-... # Organization ID (optional)
OPENAI_TIMEOUT=120 # Request timeout (seconds)
OPENAI_MAX_RETRIES=3 # Max retry attempts
OPENAI_RETRY_DELAY=1 # Retry delay (seconds)
# Model Configuration
OPENAI_MODELS=gpt-4,gpt-3.5-turbo # Available models
OPENAI_DEFAULT_MODEL=gpt-3.5-turbo # Default model
OPENAI_MAX_TOKENS=4096 # Max tokens per request
OPENAI_TEMPERATURE=0.7 # Default temperature
Anthropic Configuration
# Anthropic Claude
ANTHROPIC_API_KEY=sk-ant-... # Anthropic API key
ANTHROPIC_BASE_URL=https://api.anthropic.com # Base URL
ANTHROPIC_VERSION=2023-06-01 # API version
ANTHROPIC_TIMEOUT=120 # Request timeout
ANTHROPIC_MAX_RETRIES=3 # Max retry attempts
# Model Configuration
ANTHROPIC_MODELS=claude-3-opus,claude-3-sonnet # Available models
ANTHROPIC_DEFAULT_MODEL=claude-3-sonnet # Default model
ANTHROPIC_MAX_TOKENS=4096 # Max tokens per request
Local AI Configuration
# Ollama
OLLAMA_ENABLED=false # Enable Ollama
OLLAMA_BASE_URL=http://localhost:11434 # Ollama server URL
OLLAMA_TIMEOUT=300 # Request timeout
OLLAMA_MODELS=llama2,codellama # Available models
# LocalAI
LOCALAI_ENABLED=false # Enable LocalAI
LOCALAI_BASE_URL=http://localhost:8080 # LocalAI server URL
LOCALAI_API_KEY=local-ai-key # API key
LOCALAI_MODELS=gpt-3.5-turbo # Available models
Storage Configuration
File Storage
# Storage Type
STORAGE_TYPE=local # Storage type (local, s3, gcs, azure)
STORAGE_PATH=/storage # Local storage path
MAX_FILE_SIZE=52428800 # Max file size (50MB)
ALLOWED_FILE_TYPES=pdf,docx,txt,png,jpg,jpeg # Allowed file types
# File Processing
FILE_PROCESSING_ENABLED=true # Enable file processing
FILE_PROCESSING_TIMEOUT=300 # Processing timeout (seconds)
OCR_ENABLED=true # Enable OCR for images
OCR_LANGUAGE=eng # OCR language
S3 Storage Configuration
# AWS S3
S3_BUCKET=chatnio-files # S3 bucket name
S3_REGION=us-east-1 # AWS region
S3_ACCESS_KEY=AKIA... # AWS access key
S3_SECRET_KEY=... # AWS secret key
S3_ENDPOINT= # Custom endpoint (for S3-compatible)
S3_FORCE_PATH_STYLE=false # Force path style URLs
S3_SSL=true # Use SSL
# Cloudflare R2
R2_ACCOUNT_ID=... # Cloudflare account ID
R2_ACCESS_KEY=... # R2 access key
R2_SECRET_KEY=... # R2 secret key
R2_BUCKET=chatnio-files # R2 bucket name
R2_ENDPOINT=https://....r2.cloudflarestorage.com
Google Cloud Storage
# Google Cloud Storage
GCS_BUCKET=chatnio-files # GCS bucket name
GCS_PROJECT_ID=my-project # GCP project ID
GCS_CREDENTIALS_FILE=/path/to/credentials.json # Service account key file
GCS_REGION=us-central1 # GCS region
Security Configuration
Authentication & Authorization
# JWT Configuration
JWT_SECRET=your-jwt-secret # JWT signing secret (required)
JWT_EXPIRE=168h # JWT expiration time (168h = 7 days)
JWT_REFRESH_EXPIRE=720h # Refresh token expiration (30 days)
JWT_ISSUER=chatnio # JWT issuer
JWT_AUDIENCE=chatnio-users # JWT audience
# Session Configuration
SESSION_NAME=chatnio_session # Session cookie name
SESSION_SECURE=true # Secure cookie (HTTPS only)
SESSION_HTTP_ONLY=true # HTTP only cookie
SESSION_SAME_SITE=strict # SameSite attribute
SESSION_MAX_AGE=604800 # Session max age (seconds)
# Multi-Factor Authentication
MFA_ENABLED=true # Enable MFA
MFA_ISSUER=CoAI.Dev # TOTP issuer name
MFA_BACKUP_CODES=10 # Number of backup codes
MFA_GRACE_PERIOD=72h # Grace period for MFA setup
Content Security
# Content Moderation
CONTENT_MODERATION_ENABLED=true # Enable content moderation
CONTENT_MODERATION_PROVIDER=openai # Provider (openai, azure, custom)
CONTENT_MODERATION_THRESHOLD=0.8 # Threshold for blocking content
CONTENT_MODERATION_LOG=true # Log moderation results
# DLP (Data Loss Prevention)
DLP_ENABLED=true # Enable DLP scanning
DLP_SCAN_UPLOADS=true # Scan uploaded files
DLP_SCAN_MESSAGES=true # Scan chat messages
DLP_BLOCK_THRESHOLD=0.8 # Threshold for blocking
DLP_RULES_FILE=/config/dlp-rules.yml # DLP rules configuration
# Encryption
ENCRYPTION_KEY=... # Data encryption key
ENCRYPTION_ALGORITHM=AES-256-GCM # Encryption algorithm
ENCRYPTION_AT_REST=true # Encrypt data at rest
ENCRYPTION_IN_TRANSIT=true # Encrypt data in transit
Monitoring Configuration
Metrics and Observability
# Metrics
METRICS_ENABLED=true # Enable metrics collection
METRICS_PORT=9090 # Metrics port
METRICS_PATH=/metrics # Metrics endpoint path
METRICS_NAMESPACE=chatnio # Metrics namespace
# Health Checks
HEALTH_CHECK_ENABLED=true # Enable health checks
HEALTH_CHECK_PORT=8080 # Health check port
HEALTH_CHECK_PATH=/health # Health check path
HEALTH_CHECK_INTERVAL=30 # Check interval (seconds)
# Tracing
TRACING_ENABLED=false # Enable distributed tracing
TRACING_PROVIDER=jaeger # Tracing provider (jaeger, zipkin)
TRACING_ENDPOINT=http://localhost:14268/api/traces
TRACING_SAMPLE_RATE=0.1 # Sample rate (0.0-1.0)
External Monitoring
# Prometheus
PROMETHEUS_ENABLED=true # Enable Prometheus metrics
PROMETHEUS_NAMESPACE=chatnio # Metrics namespace
PROMETHEUS_SCRAPE_INTERVAL=15s # Scrape interval
# DataDog
DATADOG_ENABLED=false # Enable DataDog
DATADOG_API_KEY=... # DataDog API key
DATADOG_SITE=datadoghq.com # DataDog site
DATADOG_ENV=production # Environment tag
DATADOG_SERVICE=chatnio # Service name
# New Relic
NEWRELIC_ENABLED=false # Enable New Relic
NEWRELIC_LICENSE_KEY=... # New Relic license key
NEWRELIC_APP_NAME=CoAI.Dev # Application name
Email Configuration
SMTP Settings
# SMTP Configuration
SMTP_ENABLED=true # Enable email sending
SMTP_HOST=smtp.gmail.com # SMTP host
SMTP_PORT=587 # SMTP port
SMTP_USERNAME=your-email@gmail.com # SMTP username
SMTP_PASSWORD=your-app-password # SMTP password
SMTP_TLS=true # Enable TLS
SMTP_SSL=false # Enable SSL (alternative to TLS)
# Email Settings
EMAIL_FROM=noreply@chatnio.com # From email address
EMAIL_FROM_NAME=CoAI.Dev # From name
EMAIL_REPLY_TO=support@chatnio.com # Reply-to address
EMAIL_TEMPLATE_PATH=/templates # Email template path
# Email Types
EMAIL_VERIFICATION_ENABLED=true # Enable email verification
EMAIL_PASSWORD_RESET_ENABLED=true # Enable password reset emails
EMAIL_NOTIFICATION_ENABLED=true # Enable notification emails
EMAIL_MARKETING_ENABLED=false # Enable marketing emails
Email Templates
# config/email.yml
email:
templates:
verification:
subject: "Verify your CoAI.Dev account"
template: "verification.html"
expiry: 24h
password_reset:
subject: "Reset your CoAI.Dev password"
template: "password_reset.html"
expiry: 1h
welcome:
subject: "Welcome to CoAI.Dev!"
template: "welcome.html"
usage_alert:
subject: "Usage limit alert"
template: "usage_alert.html"
smtp:
host: ${SMTP_HOST}
port: ${SMTP_PORT:-587}
username: ${SMTP_USERNAME}
password: ${SMTP_PASSWORD}
tls: ${SMTP_TLS:-true}
settings:
from: ${EMAIL_FROM}
from_name: ${EMAIL_FROM_NAME}
reply_to: ${EMAIL_REPLY_TO}
Billing Configuration
Payment Providers
# Stripe
STRIPE_ENABLED=false # Enable Stripe
STRIPE_PUBLIC_KEY=pk_... # Stripe public key
STRIPE_SECRET_KEY=sk_... # Stripe secret key
STRIPE_WEBHOOK_SECRET=whsec_... # Webhook secret
STRIPE_CURRENCY=usd # Default currency
# PayPal
PAYPAL_ENABLED=false # Enable PayPal
PAYPAL_CLIENT_ID=... # PayPal client ID
PAYPAL_CLIENT_SECRET=... # PayPal client secret
PAYPAL_SANDBOX=true # Use sandbox environment
# Billing Settings
BILLING_ENABLED=true # Enable billing system
BILLING_CURRENCY=usd # Default currency
BILLING_TAX_RATE=0.08 # Default tax rate
BILLING_GRACE_PERIOD=72h # Payment grace period
Usage Tracking
# Usage Limits
USAGE_TRACKING_ENABLED=true # Enable usage tracking
USAGE_RESET_CYCLE=monthly # Reset cycle (daily, weekly, monthly)
USAGE_ALERT_THRESHOLD=0.8 # Alert threshold (80%)
USAGE_HARD_LIMIT_ENABLED=true # Enable hard limits
# Free Tier Limits
FREE_TIER_REQUESTS=1000 # Free requests per month
FREE_TIER_TOKENS=100000 # Free tokens per month
FREE_TIER_MODELS=gpt-3.5-turbo # Free tier models
FREE_TIER_FEATURES=chat,files # Free tier features
Performance Configuration
Caching
# Cache Configuration
CACHE_ENABLED=true # Enable caching
CACHE_TTL=3600 # Default TTL (seconds)
CACHE_MAX_SIZE=1000 # Max cache entries
CACHE_COMPRESSION=true # Enable compression
# Model Response Caching
MODEL_CACHE_ENABLED=true # Enable model response caching
MODEL_CACHE_TTL=1800 # Model cache TTL (30 minutes)
MODEL_CACHE_MAX_SIZE=5000 # Max cached responses
MODEL_CACHE_PROBABILITY=0.8 # Caching probability
# CDN Configuration
CDN_ENABLED=false # Enable CDN
CDN_BASE_URL=https://cdn.chatnio.com # CDN base URL
CDN_STATIC_ASSETS=true # Cache static assets
CDN_API_RESPONSES=false # Cache API responses
Connection Pooling
# HTTP Client
HTTP_TIMEOUT=30 # HTTP timeout (seconds)
HTTP_KEEP_ALIVE=30 # Keep-alive timeout
HTTP_MAX_IDLE_CONNS=100 # Max idle connections
HTTP_MAX_CONNS_PER_HOST=10 # Max connections per host
HTTP_IDLE_CONN_TIMEOUT=90 # Idle connection timeout
# Database Connection Pool
DB_MAX_OPEN_CONNS=25 # Max open connections
DB_MAX_IDLE_CONNS=5 # Max idle connections
DB_CONN_MAX_LIFETIME=300 # Connection lifetime (seconds)
DB_CONN_MAX_IDLE_TIME=300 # Connection idle time (seconds)
Development Configuration
Debug Settings
# Development
DEBUG=false # Enable debug mode
DEV_MODE=false # Enable development mode
PROFILE=false # Enable profiling
PPROF_ENABLED=false # Enable pprof endpoint
PPROF_PORT=6060 # pprof port
# Hot Reload
HOT_RELOAD=false # Enable hot reload
WATCH_FILES=true # Watch file changes
WATCH_EXTENSIONS=.go,.yaml,.yml # File extensions to watch
# Testing
TEST_MODE=false # Enable test mode
TEST_DATABASE=chatnio_test # Test database name
TEST_CLEANUP=true # Cleanup test data
MOCK_PROVIDERS=false # Use mock AI providers
Environment-Specific Configs
Use different configuration files for different environments:
config/development.yml
- Development settingsconfig/staging.yml
- Staging environmentconfig/production.yml
- Production settingsconfig/testing.yml
- Test configuration
Configuration Validation
Required Settings
The following settings are required for CoAI.Dev to start:
# Mandatory Configuration
SECRET= # JWT secret (REQUIRED)
MYSQL_HOST= # Database host (REQUIRED)
MYSQL_PASSWORD= # Database password (REQUIRED)
Configuration Validation Script
#!/bin/bash
# validate-config.sh
# Check required environment variables
required_vars=(
"SECRET"
"MYSQL_HOST"
"MYSQL_PASSWORD"
)
missing_vars=()
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
missing_vars+=("$var")
fi
done
if [ ${#missing_vars[@]} -gt 0 ]; then
echo "❌ Missing required environment variables:"
printf ' - %s\n' "${missing_vars[@]}"
exit 1
fi
echo "✅ Configuration validation passed"
# Test database connection
if command -v mysql &> /dev/null; then
if mysql -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -e "SELECT 1" &> /dev/null; then
echo "✅ Database connection successful"
else
echo "❌ Database connection failed"
exit 1
fi
fi
# Test Redis connection
if command -v redis-cli &> /dev/null; then
if redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" ping &> /dev/null; then
echo "✅ Redis connection successful"
else
echo "⚠️ Redis connection failed (optional)"
fi
fi
This configuration reference covers all available settings for CoAI.Dev. For environment-specific configurations, create separate config files and use environment variable substitution for sensitive values.