Overview
Scribe Backend uses Pydantic Settings for type-safe configuration management. All settings are loaded from environment variables defined in a.env file.
The settings module (
config/settings.py) validates all configuration at startup. Missing required variables will cause the application to fail fast with clear error messages.Step 1: Create .env File
Copy the example environment file and customize it:
.env in your preferred text editor:
Step 2: Configure Required Variables
Application Settings
Database Configuration
Scribe uses Supabase’s transaction pooler for PostgreSQL connections:Transaction Pooler (Port 6543): Recommended for production. Supabase’s Supavisor handles connection pooling server-side. Use NullPool on the client side to avoid stale connections.
Alternative: Session Pooler (Port 5432)
Alternative: Session Pooler (Port 5432)
If you need session-based pooling for long-running transactions:Not recommended for Scribe’s stateless architecture.
Supabase Authentication
- Go to your Supabase project dashboard
- Navigate to Settings → API
- Copy Project URL and service_role key
External API Keys
Anthropic (Required)
- Purpose: Claude AI models for template parsing and email composition
- Get your key: console.anthropic.com
- Models used: Claude Haiku 4.5, Claude Sonnet 4.5
Exa Search (Required)
- Purpose: Web search for recipient information
- Get your key: exa.ai
- Replaces: Google Custom Search API (better for academic content)
Fireworks AI (Optional)
- Purpose: Alternative LLM provider (cost-effective)
- Get your key: fireworks.ai
- Models: Kimi K2p5 (hot-swappable via model config)
LLM Model Configuration (Hot-Swappable)
Scribe supports multiple LLM providers via environment variables:{provider}:{model-identifier}
Change models without code modifications. Ideal for A/B testing or cost optimization.
Redis Configuration
Production Redis (Upstash, Redis Cloud)
Production Redis (Upstash, Redis Cloud)
For managed Redis in production:
Observability (Optional)
- Logfire: Built by Pydantic team, provides automatic instrumentation
- Get your token: logfire.pydantic.dev
- Features: LLM call tracking, distributed tracing, cost monitoring
Logfire is optional but highly recommended for production deployments. It provides deep visibility into pipeline performance and LLM usage.
Pydantic Settings Explained
Scribe usespydantic-settings for configuration management (config/settings.py):
Key Features
- Type Validation: Environment variables are validated at startup
- Default Values: Missing optional variables use sensible defaults
- Computed Properties: Dynamic values like
database_urlare auto-generated - Field Validators: Custom validation logic (e.g., port validation)
Example: Database URL Construction
- No need to manually construct connection strings
- Automatic SSL enforcement (
sslmode=require) - Type-safe access throughout the codebase
Configuration Validation
Port Validation
The settings module validates thatDB_PORT matches the connection type:
Environment-Specific Configuration
Development
Production
Use
settings.is_production or settings.is_development in code to conditionally enable features.Usage Limits
Accessing Settings in Code
Import the singletonsettings instance:
Complete .env Example
Next Steps
- Set up the database → Database Setup Guide
- Run the application → Running Locally Guide
Troubleshooting
Missing required environment variable
Missing required environment variable
Error:
Field required [type=missing]Solution: Ensure all required variables are set in .env. Check the error message for the specific field name.Invalid database port
Invalid database port
Error:
Invalid database port: 5433Solution: Use port 6543 (transaction pooler) or 5432 (session pooler).Settings not loading
Settings not loading
Issue: Changes to
.env not reflectedSolution:- Ensure
.envis in the project root (same directory asmain.py) - Restart the application (settings are loaded at startup)
- Check file permissions:
chmod 600 .env
CORS errors in browser
CORS errors in browser
Issue: Frontend requests blocked by CORSSolution: Add your frontend URL to Restart the server after changes.
ALLOWED_ORIGINS: