Skip to main content

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 string
Format: 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 connections
Set to false for local development without SSL.
number
default:"5000"
Port for the Express server
Most hosting platforms provide $PORT automatically.
string
default:"development"
Environment mode
Values: development, production

Authentication

string
required
Secret key for signing JWT tokens
Generate securely:
From server/config/env.ts:41:
string
default:"7d"
JWT token expiration time
Format: [number][unit] where unit is s, m, h, dExamples: 30m, 12h, 7d, 90d
string
required
Secret key for session management
Generate securely:

AI Provider Configuration

Sunschool supports multiple AI providers with automatic fallback chains.

OpenRouter (Primary)

string
required
API key for OpenRouter
Get your key: openrouter.ai/keysFrom server/config/env.ts:48:
Used for:
  • Lesson content generation
  • Quiz question creation
  • SVG illustration generation
string
default:"openrouter"
Primary LLM provider
Options: openrouter, bittensor, perplexityFrom server/config/env.ts:45:

Bittensor (Experimental)

Bittensor Subnet 1 integration is experimental. OpenRouter is recommended for production.
boolean
default:"false"
Enable Bittensor Subnet 1 provider
From server/config/flags.ts:12:
string
API key for Bittensor Archive
string
default:"https://archive.opentensor.ai/graphql"
GraphQL endpoint for Bittensor Subnet 1
From 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 fails
From server/config/flags.ts:13:

Perplexity

string
API key for Perplexity AI
Get your key: perplexity.ai/settings/apiFrom server/config/env.ts:57:

Image Generation

Provider Selection

string
default:"svg-llm"
Image generation provider
Options:
  • svg-llm: LLM-generated SVG graphics (recommended)
  • openrouter: Raster images via OpenRouter
  • stability: Stability AI models
From server/config/env.ts:60:

OpenRouter Image Models

string
default:"google/gemini-3.1-pro-preview"
Primary model for image generation
From server/config/env.ts:61:
string
default:"google/gemini-3.1-pro-preview"
Primary model for SVG generation
From server/config/env.ts:62:
string
Comma-separated list of fallback models for image generation
Tried 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 generation
From server/config/env.ts:67-68:
Default fallbacks from server/config/env.ts:73-76:

Image Generation Limits

number
default:"15000"
Timeout for image generation in milliseconds
From server/config/env.ts:63:
number
default:"4"
Maximum number of images to generate per lesson
From server/config/env.ts:64:

Feature Flags

Feature flags control optional functionality. See server/config/flags.ts for implementation.

AI Controls

boolean
default:"true"
Enable AI-generated content
Set to 0 to disable all AI features (lessons use placeholder content).From server/config/flags.ts:9:
boolean
default:"true"
Enable OpenRouter image generation
From server/config/flags.ts:19:
boolean
default:"true"
Enable LLM-based SVG generation
From server/config/flags.ts:20:
boolean
default:"false"
Enable Stability AI as fallback for image generation
From server/config/flags.ts:21:

Analytics

boolean
default:"true"
Enable statistics collection
Set to 0 to disable analytics tracking (performance data, usage metrics).From server/config/flags.ts:16:

Example Configurations

Minimal (Development)

Bittensor Experimental


Advanced Configuration

Database Connection Pooling

Sunschool uses pg 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, edit server/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:
  1. Database connection is tested
  2. Migrations are run automatically
  3. 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

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
Symptoms: Feature still enabled/disabled after changing flagSolutions:
  • Restart the server: npm start
  • Check .env file has no typos in variable names
  • Verify the flag is read correctly: add console.log(USE_AI) in server/config/flags.ts
  • Clear any cached environment variables
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_LESSON to 2-3
  • Check OpenRouter model availability at openrouter.ai/models
Symptoms: Error: self signed certificate, SSL SYSCALL errorSolutions:
  • For local dev, set DATABASE_SSL=false
  • For production, ensure the database supports SSL
  • Add ?sslmode=require to DATABASE_URL
  • Check the database provider’s SSL documentation