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
Create Account
Sign up at openrouter.ai
Add Credits
Navigate to Credits and add balance ($5-10 recommended for testing)
Generate API Key
Go to Keys and create a new API key
Models Used
Fromserver/config/env.ts:
| Purpose | Model | Why |
|---|---|---|
| Lesson content | google/gemini-3.1-pro-preview | High-quality long-form content |
| Quiz generation | google/gemini-3.1-pro-preview | Strong reasoning for question creation |
| SVG illustrations | google/gemini-3.1-flash-lite-preview | Fast, cost-effective visual generation |
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):| Model | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|
| Gemini 3.1 Pro | $2.50 | $10.00 |
| Gemini 3.1 Flash | $0.075 | $0.30 |
| Claude 3.5 Sonnet | $3.00 | $15.00 |
- 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
Create Account
Sign up at perplexity.ai
Access API
Navigate to API Settings
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
Get API Key
Follow Bittensor documentation for API access
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
| Feature | OpenRouter | Perplexity | Bittensor |
|---|---|---|---|
| Status | ✅ Production | ✅ Production | ⚠️ Experimental |
| Setup Complexity | Low | Low | High |
| Cost | Pay-per-use | Pay-per-use | Variable |
| Response Time | Fast (1-3s) | Fast (1-2s) | Variable (3-10s) |
| Model Selection | 100+ models | Proprietary | Subnet miners |
| Reliability | High | High | Moderate |
| Use Case | Primary LLM | Knowledge enrichment | Decentralized alternative |
Recommended Configuration
Production Setup
Development Setup
Troubleshooting
401 Unauthorized (OpenRouter)
401 Unauthorized (OpenRouter)
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