Overview
Sunschool supports multiple AI providers with automatic fallback chains. Fromserver/services/ai.ts:
Provider Selection
Fromserver/services/ai.ts:
OpenRouter (Primary)
OpenRouter is the recommended primary provider. It provides access to multiple models including GPT-4, Claude, and Gemini.
Setup
1
Create Account
Sign up at openrouter.ai
2
Add Credits
Navigate to Credits and add balance ($5-10 recommended for testing)
3
Generate API Key
Go to Keys and create a new API key
4
Configure Environment
Models Used
Fromserver/config/env.ts:
Model Customization
Override default models:Fallback Chains
Fromserver/config/env.ts:
ENGINEERING.md:
Model fallback chain: primary model → fallbacks from SVG_MODEL_FALLBACKS env → built-in defaults. Models returning 402 (insufficient credits) or 404 are automatically skipped.
Rate Limits & Costs
Approximate costs (as of 2026):
Typical lesson generation:
- Input: ~2,000 tokens (prompts + context)
- Output: ~3,000 tokens (lesson content)
- Cost per lesson: ~$0.05-0.10
Perplexity (Knowledge Enrichment)
Perplexity enhances lessons with up-to-date information and context. Optional but recommended.
Setup
1
Create Account
Sign up at perplexity.ai
2
Access API
Navigate to API Settings
3
Generate Key
Create API key (starts with
pplx-)4
Configure
Use Cases
FromENGINEERING.md:
Perplexity - Knowledge context enrichmentPerplexity is used to:
- Add current events to history lessons
- Provide real-world examples for math/science
- Enrich content with recent research
Bittensor Subnet 1 (Experimental)
FromENGINEERING.md:
Status: Client and config implemented (Phases 1-3 complete). Testing/validation (Phase 4) and production deployment (Phase 5) pending.
What is Bittensor?
Bittensor is a decentralized AI network where miners compete to provide LLM inference. Subnet 1 specializes in text generation. Benefits:- Decentralized (no single point of failure)
- Competitive pricing
- Open and auditable
- Still experimental for production
- Variable response times
- Requires wallet setup
Setup
1
Install Bittensor
2
Create Wallet
3
Get API Key
Follow Bittensor documentation for API access
4
Configure Environment
Enable as Primary Provider
Fromserver/config/env.ts:
ENGINEERING.md:
Automatic Fallback
Fromserver/services/ai.ts:
server/config/flags.ts:
Feature Flags
Global AI Toggle
Fromserver/config/flags.ts:
- Testing without API costs
- Offline development
- Debugging non-AI features
Image Generation Controls
Image Provider Selection
Fromserver/config/env.ts:
- svg-llm (Default)
- openrouter
- stability
- Generates clean SVG illustrations
- Small file sizes (~10-50 KB)
- Works offline after generation
- Best for diagrams and educational graphics
Image Generation Timeouts
Provider Comparison
Recommended Configuration
Production Setup
Development Setup
Troubleshooting
402 Insufficient Credits
402 Insufficient Credits
Cause: OpenRouter account balance is zero.Fix:
- Add credits at openrouter.ai/credits
- Fallback model will be tried automatically
404 Model Not Found
404 Model Not Found
Cause: Model name typo or model no longer available.Fix:
Bittensor Connection Timeout
Bittensor Connection Timeout
Cause: Subnet unreachable or wallet misconfigured.Fix:
Next Steps
Security
Secure your AI provider API keys
Monitoring
Monitor AI usage and costs
Troubleshooting
Debug AI provider issues