Configuration
Sunschool is highly configurable through environment variables and feature flags. This guide covers all configuration options.Environment Variables
All configuration is managed through environment variables in the.env file.
Core Settings
string
required
PostgreSQL connection stringFormat:
postgresql://[user]:[password]@[host]:[port]/[database]Examples:- Local:
postgresql://postgres:postgres@localhost:5432/sunschool - Neon:
postgresql://user:pass@ep-xyz.us-east-2.aws.neon.tech/sunschool?sslmode=require - Railway: Automatically provided via
$DATABASE_URL
boolean
default:"true"
Enable SSL for database connectionsSet to
false for local development without SSL.number
default:"5000"
Port for the Express serverMost hosting platforms provide
$PORT automatically.string
default:"development"
Environment modeValues:
development, productionAuthentication
string
required
Secret key for signing JWT tokensGenerate securely:From
server/config/env.ts:41:string
default:"7d"
JWT token expiration timeFormat:
[number][unit] where unit is s, m, h, dExamples: 30m, 12h, 7d, 90dstring
required
Secret key for session managementGenerate securely:
AI Provider Configuration
Sunschool supports multiple AI providers with automatic fallback chains.OpenRouter (Primary)
string
required
API key for OpenRouterGet your key: openrouter.ai/keysFrom Used for:
server/config/env.ts:48:- Lesson content generation
- Quiz question creation
- SVG illustration generation
string
default:"openrouter"
Primary LLM providerOptions:
openrouter, bittensor, perplexityFrom server/config/env.ts:45:Bittensor (Experimental)
boolean
default:"false"
Enable Bittensor Subnet 1 providerFrom
server/config/flags.ts:12:string
API key for Bittensor Archive
string
default:"https://archive.opentensor.ai/graphql"
GraphQL endpoint for Bittensor Subnet 1From
server/config/env.ts:52:string
Bittensor wallet name for authentication
string
Bittensor wallet hotkey
boolean
default:"true"
Enable automatic fallback to OpenRouter when Bittensor failsFrom
server/config/flags.ts:13:Perplexity
string
Image Generation
Provider Selection
string
default:"svg-llm"
Image generation providerOptions:
svg-llm: LLM-generated SVG graphics (recommended)openrouter: Raster images via OpenRouterstability: Stability AI models
server/config/env.ts:60:OpenRouter Image Models
string
default:"google/gemini-3.1-pro-preview"
Primary model for image generationFrom
server/config/env.ts:61:string
default:"google/gemini-3.1-pro-preview"
Primary model for SVG generationFrom
server/config/env.ts:62:string
Comma-separated list of fallback models for image generationTried in order when the primary model returns 404 or fails.From
server/config/env.ts:69-70:string
Comma-separated list of fallback models for SVG generationFrom Default fallbacks from
server/config/env.ts:67-68:server/config/env.ts:73-76:Image Generation Limits
number
default:"15000"
Timeout for image generation in millisecondsFrom
server/config/env.ts:63:number
default:"4"
Maximum number of images to generate per lessonFrom
server/config/env.ts:64:Feature Flags
Feature flags control optional functionality. Seeserver/config/flags.ts for implementation.
AI Controls
boolean
default:"true"
Enable AI-generated contentSet to
0 to disable all AI features (lessons use placeholder content).From server/config/flags.ts:9:boolean
default:"true"
Enable OpenRouter image generationFrom
server/config/flags.ts:19:boolean
default:"true"
Enable LLM-based SVG generationFrom
server/config/flags.ts:20:boolean
default:"false"
Enable Stability AI as fallback for image generationFrom
server/config/flags.ts:21:Analytics
boolean
default:"true"
Enable statistics collectionSet to
0 to disable analytics tracking (performance data, usage metrics).From server/config/flags.ts:16:Example Configurations
Minimal (Development)
Production (Recommended)
Bittensor Experimental
Advanced Configuration
Database Connection Pooling
Sunschool usespg with Neon serverless driver. Connection pooling is handled automatically.
For high-traffic deployments, configure external pooling (e.g., PgBouncer):
CORS Configuration
CORS is enabled by default for all origins in development. For production, editserver/index.ts:
Rate Limiting
Sunschool does not include built-in rate limiting. Use a reverse proxy (nginx, Caddy) or middleware:Configuration Validation
Sunschool validates critical environment variables on startup. Missing required variables throw errors:Startup Checks
When the server starts:- Database connection is tested
- Migrations are run automatically
- Missing API keys log warnings (not errors) for optional providers
Next Steps
First Steps
Navigate the interface and manage learners
Installation
Self-host Sunschool on your infrastructure
API Reference
Integrate with the Sunschool API
Quickstart
Complete walkthrough from signup to first lesson
Troubleshooting
API key not working
API key not working
Symptoms:
Failed to generate lesson content, 401 errorsSolutions:- Verify the API key is correct (no extra spaces or quotes)
- Check the provider’s dashboard for key status
- Test the key with a curl request
- Ensure the account has sufficient credits/quota
Feature flag not taking effect
Feature flag not taking effect
Symptoms: Feature still enabled/disabled after changing flagSolutions:
- Restart the server:
npm start - Check
.envfile has no typos in variable names - Verify the flag is read correctly: add
console.log(USE_AI)inserver/config/flags.ts - Clear any cached environment variables
Image generation is slow
Image generation is slow
Symptoms: Lessons load but images take 20+ secondsSolutions:
- Increase
IMAGE_GENERATION_TIMEOUT(default: 15000ms) - Use faster models in fallback chain (e.g.,
gemini-3-flash-preview) - Reduce
MAX_IMAGES_PER_LESSONto 2-3 - Check OpenRouter model availability at openrouter.ai/models
Database SSL error
Database SSL error
Symptoms:
Error: self signed certificate, SSL SYSCALL errorSolutions:- For local dev, set
DATABASE_SSL=false - For production, ensure the database supports SSL
- Add
?sslmode=requiretoDATABASE_URL - Check the database provider’s SSL documentation