# AI setup Synapse uses an LLM for two features: exercise generation from your course material, and OCR of scanned documents. AI is always opt-in: nothing is configured out of the box, nothing leaves your device until you set up a provider yourself, and the app works fully without one. You bring your own API key or point it at a model running on your own machine. The default provider is OpenAI with the `gpt-4o-mini` model, which is available on OpenAI's free usage tier: a fresh install works with a free key, no paid plan needed. ## 1. Quick start (OpenAI free tier) 1. Create an account at https://platform.openai.com and generate an API key (Dashboard > API keys > Create new secret key). 2. In Synapse, open Settings > AI, keep the provider on OpenAI and the model on `gpt-4o-mini`, paste your key and save. The key is stored server-side and never sent back to the browser. 3. Enable AI for a course from that course's settings page, then use "Generate exercises" on any document. The free tier allows a few requests per minute and a daily cap (see https://developers.openai.com/api/docs/guides/rate-limits#usage-tiers for the current numbers). Synapse is tuned for this: generation requests run one at a time and rate limit responses are retried automatically with a growing delay. If you still hit the limit, wait a minute and try again; generating for many documents in a row simply takes longer on the free tier. Adding a small prepaid balance moves the account to tier 1 and removes most of the friction. Instead of the settings screen, the key can also come from the environment (`OPENAI_API_KEY` in `apps/api/.env`); values saved in Settings take precedence. ## 2. Other providers - Local model: set the provider to Local with any OpenAI-compatible endpoint. See the Ollama walkthrough below. No API key needed, nothing leaves your machine. - Anthropic: set the provider to Claude in Settings > AI with a key from https://console.anthropic.com. ### Ollama, step by step Install Ollama from https://ollama.com, then pull a model and start the server: ```bash ollama pull llama3.1 # text only, generates exercises ollama serve # or: brew services start ollama curl http://localhost:11434/v1/models ``` In Synapse, open Settings > AI, enable AI, set the provider to Local, leave the base URL at `http://localhost:11434/v1`, and set the model to exactly the name `ollama list` reports (`llama3.1`, not `llama-3.1`). Then enable AI for a course in that course's settings. Two things that catch people out: - Settings saved on this page win over the `OPENAI_API_KEY` and `ANTHROPIC_API_KEY` values in `apps/api/.env`. If the page still reports a different provider than you expect, an environment key is being used because nothing was saved here yet. - The API appends `/chat/completions` to the base URL itself, so keep the `/v1` and do not add the rest of the path. The base URL must be a loopback address (`localhost` or `127.0.0.1`) unless it is https: the server refuses plain http to anything else, so that a stolen admin session cannot point it at an internal service. Ollama on another machine on the LAN is rejected for that reason, and so is `host.docker.internal` when the API runs in a container. Not every model that downloads will run. `ollama pull` accepts a model whose architecture the installed Ollama cannot load, and the failure only appears on the first request, as `unknown model architecture`. If that happens, pull a different model rather than reinstalling anything. ## 3. What uses which key Settings > AI holds two providers, and the difference matters when you are working out which one answered: - Server AI provider, set by an administrator and shared by everyone on that server. It answers whenever the server is reachable, which is the normal case. - Your AI provider, saved on your device and never sent to the server. It answers when no server is reachable, and for any course you pin to it in the course settings. Both features follow whichever of those applies, so on the default setup the OpenAI key on the server covers everything. | Feature | Providers | Notes | | ------------------- | ------------------------ | ---------------------------------------- | | Exercise generation | OpenAI, Claude, or Local | Per-course toggle in the course settings | | OCR (scanned PDFs) | OpenAI or Claude | Not available on a local model | OCR sends the whole PDF to the model as a file attachment, which OpenAI and Claude accept and a local runtime does not: Ollama's API takes images, not PDFs. A scanned document still imports on a local provider, just without a text layer, which means exercise generation has nothing to read from it. Pulling a vision model does not change this on its own. ## 4. Your AI provider (no server) When the app cannot reach a server (the desktop app in standalone mode, or a browser that lost its connection), AI runs against the provider you configure yourself in `Settings > AI > Your AI provider`: - A local runtime through any OpenAI-compatible API. The default expects [Ollama](https://ollama.com) on `http://localhost:11434/v1` with the `llama3.2` model pulled (`ollama pull llama3.2`). Set the model field to whatever you actually pulled: this default and the server's own default (`llama3.1`) are separate settings and do not follow each other. - Or your own OpenAI / Anthropic key, stored on the device only. This also enables the transcription of scanned PDFs on import, which a local runtime cannot do. With a server connected, the server's AI settings apply by default, and a course's settings page shows the server provider. A single course can opt out: set "AI used for this course" to "Always your AI provider" in its settings, and its generations run against your own provider even while the server is reachable. That needs the document's extracted text on this device, so a document whose text has never been downloaded here fails with a clear message instead of generating nothing. Generated exercises are written straight into the local workspace and sync to your other devices like any other change.