Environment variables
SKU Semantic Search uses environment variables for all configuration. This follows the 12-factor app methodology for portable, secure deployments.Configuration file
Create a.env file in the project root with the following variables:
Configuration reference
Application settings
Application name displayed in API documentation and responses.
API version number, displayed in FastAPI docs.
Database settings
PostgreSQL connection string in the format:Examples:
The Docker Compose configuration uses port 5435 externally but 5432 internally to avoid conflicts with local PostgreSQL installations.
AI provider settings
Google Gemini API key for embeddings and text generation.How to get:
- Visit Google AI Studio
- Sign in with your Google account
- Click “Get API key”
- Copy the key (starts with
AI...)
- 60 requests per minute
- Generous monthly quota for experimentation
Anthropic Claude API key for failover text generation.How to get:
- Visit Anthropic Console
- Sign up or sign in
- Navigate to API Keys
- Generate a new key (starts with
sk-ant-...)
While optional for basic operation, this key is essential for high availability. The system falls back to Claude when Gemini is unavailable.
Authentication settings
Secret key for signing JWT tokens. Must be a strong, random string.Generate a secure secret:
JWT signing algorithm.
HS256 (HMAC with SHA-256) is recommended for symmetric key signing.Other options: HS384, HS512, RS256 (requires RSA keys)JWT token expiration time in minutes.Recommendations:
- Development: 60-480 minutes (longer sessions for testing)
- Production: 15-30 minutes (better security)
- Long-lived API tokens: Consider refresh tokens for extended access
Loading configuration
The application loads environment variables using Pydantic Settings (app/core/config.py:3):
- Type validation: Pydantic ensures variables have correct types
- Required fields: Raises errors if required variables are missing
- Default values: Falls back to defaults for optional settings
- Auto-loading: Automatically reads from
.envfile
Environment-specific configuration
For multiple environments, use separate.env files:
- Development
- Production
- Docker
.env.developmentVerifying configuration
To check if your environment is correctly configured:Verify .env file exists
your_key_here).Security best practices
API key rotation
API key rotation
Rotate API keys regularly:
- Generate new key from provider console
- Update
.envfile - Restart the application
- Delete old key from provider
- Development: Every 90 days
- Production: Every 30-60 days
Secret management
Secret management
For production, use dedicated secret management:
- AWS: Secrets Manager, Parameter Store
- GCP: Secret Manager
- Azure: Key Vault
- HashiCorp: Vault
- Kubernetes: Secrets
Environment variable injection
Environment variable injection
In containerized environments, inject secrets at runtime:This avoids storing secrets in images.
Access control
Access control
Restrict who can access secrets:
- Use IAM roles for cloud secrets
- Implement RBAC for Kubernetes secrets
- Limit file permissions:
chmod 600 .env - Use separate keys per environment/team
Troubleshooting
ValidationError: field required
ValidationError: field required
Cause: Required environment variable is missingSolution:
- Check
.envfile exists in project root - Verify variable name matches exactly (case-sensitive)
- Ensure no quotes around variable names:
GEMINI_API_KEY=value, not"GEMINI_API_KEY"=value
API authentication fails
API authentication fails
Cause: Invalid API key or expired free tierSolution:
- Regenerate API key from provider console
- Check for leading/trailing whitespace in
.env - Verify key hasn’t been revoked
- Check billing status if using paid tier
Database connection refused
Database connection refused
Cause: Incorrect DATABASE_URL or PostgreSQL not runningSolution:
- Verify PostgreSQL is running:
docker ps - Check port matches Docker Compose config (5435 external)
- For Docker, use service name
dbas host, notlocalhost - Test connection:
psql $DATABASE_URL
Environment variables not loading
Environment variables not loading
Cause: Pydantic can’t find
.env fileSolution:- Ensure
.envis in project root (same directory asapp/) - Check file is named exactly
.env(not.env.txt) - Verify UTF-8 encoding:
file .envshould showUTF-8 - Try absolute path in Config:
env_file = "/path/to/.env"
Next steps
Database setup
Configure PostgreSQL with pgvector
Docker deployment
Deploy using Docker Compose
Multi-LLM failover
Configure multiple AI providers
Installation
Complete installation guide