Skip to main content

Overview

Sunschool supports multiple AI providers with automatic fallback chains. From server/services/ai.ts:

Provider Selection

From server/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

From server/config/env.ts:
Default models:

Model Customization

Override default models:
Available models at openrouter.ai/models.

Fallback Chains

From server/config/env.ts:
Configure fallbacks:
From 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

Monitor your OpenRouter usage at openrouter.ai/activity to avoid unexpected charges.
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

From ENGINEERING.md:
Perplexity - Knowledge context enrichment
Perplexity is used to:
  • Add current events to history lessons
  • Provide real-world examples for math/science
  • Enrich content with recent research
Example integration:

Bittensor Subnet 1 (Experimental)

Bittensor integration is experimental. Use OpenRouter for production deployments.
From ENGINEERING.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
Limitations:
  • 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

From server/config/env.ts:
Set as primary:
From ENGINEERING.md:

Automatic Fallback

From server/services/ai.ts:
Enable fallback:
From server/config/flags.ts:

Feature Flags

Global AI Toggle

From server/config/flags.ts:
Disable all AI features:
This uses static fallback content instead of AI generation. Useful for:
  • Testing without API costs
  • Offline development
  • Debugging non-AI features

Image Generation Controls

Configuration:

Image Provider Selection

From server/config/env.ts:
Options:
  • Generates clean SVG illustrations
  • Small file sizes (~10-50 KB)
  • Works offline after generation
  • Best for diagrams and educational graphics

Image Generation Timeouts

Configuration:

Provider Comparison

Production Setup

Development Setup

Troubleshooting

Cause: Invalid API key or expired credits.Fix:
Cause: OpenRouter account balance is zero.Fix:
  1. Add credits at openrouter.ai/credits
  2. Fallback model will be tried automatically
Cause: Model name typo or model no longer available.Fix:
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