Skip to Content
Edit on GitHub

AI Setup

LearnHouse includes AI-powered features for learning assistance and content editing. The AI layer is provider-agnostic — point it at any major LLM provider by setting a provider name and an API key. These features are optional and disabled by default.

Under the hood LearnHouse uses Pydantic AI  for generation, and llama-index with pgvector for RAG (Retrieval-Augmented Generation), enabling AI assistants to answer questions using your course content as context.

Supported providers

Google Gemini
Google Gemini
google
OpenAI
OpenAI
openai
Anthropic
Anthropic
anthropic
DeepSeek
DeepSeek
deepseek
Moonshot (Kimi)
Moonshot (Kimi)
moonshot
Mistral
Mistral
mistral
OpenRouter
OpenRouter
openrouter
AWS Bedrock
AWS Bedrock
bedrock
Ollama (local)
Ollama (local)
ollama

Any OpenAI-compatible endpoint (Azure OpenAI, Together, local servers, …) also works via provider: openai plus a custom base_url.

Enabling AI

Set the provider, an API key, and the feature flag in your .env file:

LEARNHOUSE_IS_AI_ENABLED=true
LEARNHOUSE_AI_PROVIDER=google           # google | openai | anthropic | deepseek | moonshot | mistral | openrouter | bedrock | ollama
LEARNHOUSE_AI_API_KEY=your-api-key      # the single key, whatever the provider

After updating your .env file, restart your instance:

learnhouse stop
learnhouse start

Upgrading from a Gemini-only setup. No config changes are required: if you only set LEARNHOUSE_GEMINI_API_KEY, provider defaults to google and that key is used automatically (for generation and embeddings). The one difference is that the default models are now the Gemini 3 family (gemini-3.5-flash, gemini-3.1-flash-lite, gemini-3.1-pro-preview) rather than Gemini 2.5 — so your key/project must have Gemini 3 access (the Pro tier uses a preview model). To stay on the previous models, pin them explicitly:

LEARNHOUSE_AI_MODEL_FAST=gemini-2.0-flash-lite
LEARNHOUSE_AI_MODEL_STANDARD=gemini-2.5-flash
LEARNHOUSE_AI_MODEL_PRO=gemini-2.5-pro

AI usage is billed directly by your chosen provider based on the models and volume used.

Per-provider examples

undefined

Get a key from Google AI Studio . Models default to Gemini, so you don’t need to set them.

LEARNHOUSE_AI_PROVIDER=google
LEARNHOUSE_AI_API_KEY=...

Models & tiers

LearnHouse maps features to three model tiers. Leave them unset to use the built-in Gemini 3 defaults, or override any of them with a model name valid for your provider.

Env variableUsed forDefault (Gemini 3)
LEARNHOUSE_AI_MODEL_FASTChat titles, follow-up suggestions, course migrationgemini-3.1-flash-lite
LEARNHOUSE_AI_MODEL_STANDARDActivity chat, RAG answers, and course planning / MagicBlocks / boards / playgrounds on free & standard plansgemini-3.5-flash
LEARNHOUSE_AI_MODEL_PROCourse planning / MagicBlocks / boards / playgrounds on Pro+ plansgemini-3.1-pro-preview

RAG embeddings

Retrieval-Augmented Generation (course Q&A grounded in your content) needs an embedding model. By default embeddings follow your chosen provider, using a sensible default embedding model:

ProviderDefault embedding model
Googlegemini-embedding-001
OpenAI (and Azure / Together / OpenAI-compatible)text-embedding-3-small
Ollama (local)nomic-embed-text

Override the embedding provider/model independently of generation if you like:

LEARNHOUSE_AI_EMBEDDING_PROVIDER=openai          # default: same as LEARNHOUSE_AI_PROVIDER
LEARNHOUSE_AI_EMBEDDING_MODEL=text-embedding-3-large
LEARNHOUSE_AI_EMBEDDING_DIMENSIONS=768           # default: 768

Two constraints to know:

  1. Dimensions are pinned to 768 to match the pgvector column. The defaults above all produce 768-dim vectors. If you set LEARNHOUSE_AI_EMBEDDING_DIMENSIONS to another value (or use a model with a fixed, different size), you must migrate the course_embedding column and re-index existing courses.
  2. Some providers have no embeddings API — Anthropic, DeepSeek, Moonshot, Mistral, OpenRouter, and Bedrock. With one of those selected for generation, embeddings automatically fall back to Google when LEARNHOUSE_GEMINI_API_KEY is set; otherwise set LEARNHOUSE_AI_EMBEDDING_PROVIDER to google, openai, or ollama.

Non-RAG features (activity chat, course planning, MagicBlocks, the editor assistant) don’t need embeddings and work on any provider.

File & video context (course planning)

Course planning can take images, PDFs, and YouTube links as reference material. LearnHouse converts each attachment into the right format for your provider; what actually works depends on the provider’s own capabilities:

AttachmentGoogle GeminiOpenAIAnthropic (Claude)DeepSeek / Mistral / others
Images✅ on vision models
PDFs✅ (document-capable models)⚠️ model-dependent
YouTube URLs

Images and PDFs are widely supported across vision/document-capable models. YouTube links are a Gemini-only capability — Gemini fetches the video directly, while other providers have no equivalent. When an attachment type isn’t supported, the request fails with a clear error rather than silently dropping it — so if you rely on YouTube course context, keep provider: google.

Per-organization AI configuration

Once AI is enabled on the instance, each organization can toggle AI on or off and set usage limits from its admin settings. The provider and API key are set once at deployment and shared across organizations.

Media generation (images & audio)

Image generation and audio / podcast generation (text-to-speech) are Google-only paths: they always use the Google GenAI SDK regardless of LEARNHOUSE_AI_PROVIDER, resolving their key from LEARNHOUSE_AI_API_KEY (when provider=google) or LEARNHOUSE_GEMINI_API_KEY. So if you already run on Gemini, they work with no extra configuration.

Both model ids default to sensible values and only need overriding to opt into a newer/allowlisted model:

# AI image generation ("nano banana"). Default: gemini-2.5-flash-image
LEARNHOUSE_AI_IMAGE_MODEL=gemini-2.5-flash-image
 
# AI audio / podcast generation (Gemini TTS). Default: gemini-2.5-flash-preview-tts
# All Gemini TTS models are currently preview, so this is kept configurable.
LEARNHOUSE_AI_TTS_MODEL=gemini-2.5-flash-preview-tts

The audio feature powers the editor’s Generate audio tab (text-to-speech, a two-voice podcast, or a single-voice “Speak” talk). The spoken script for the podcast/Speak modes is written by the standard text model (LEARNHOUSE_AI_MODEL_STANDARD); the narration uses the TTS model above. All of it is metered by AI credits.

Usage limits

You can configure a per-organization request limit to control API costs. When a user exceeds the limit, further AI requests are rejected until the window resets.

Environment variables reference

VariableDescription
LEARNHOUSE_IS_AI_ENABLEDMaster switch for all AI features (true/false).
LEARNHOUSE_AI_PROVIDERgoogle, openai, anthropic, deepseek, moonshot, mistral, openrouter, bedrock, or ollama. Defaults to google.
LEARNHOUSE_AI_API_KEYAPI key for the chosen provider. Not required for ollama or bedrock.
LEARNHOUSE_AI_BASE_URLOptional. Custom endpoint for OpenAI-compatible / local providers (e.g. Ollama). Auto-set for OpenRouter.
LEARNHOUSE_AI_MODEL_FAST / _STANDARD / _PROPer-tier model overrides (see table above).
LEARNHOUSE_AI_EMBEDDING_PROVIDER / _MODEL / _DIMENSIONSOptional RAG embedding overrides. Default: same provider, per-provider model, 768 dims.
LEARNHOUSE_AI_IMAGE_MODELGoogle image-generation model. Default gemini-2.5-flash-image. Google-only path.
LEARNHOUSE_AI_TTS_MODELGoogle text-to-speech model for audio/podcast generation. Default gemini-2.5-flash-preview-tts (all Gemini TTS models are preview). Google-only path.
LEARNHOUSE_GEMINI_API_KEYGoogle/Gemini key. Also the embeddings fallback for providers without an embeddings API, and the key used for image/TTS generation on non-Google providers.
AWS_REGION / AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEYStandard AWS credentials, used only when provider=bedrock.