Provider switching with environment variables
Any provider that speaks the OpenAI chat completions format works here. OpenRouter for cloud models with free tiers, Ollama for fully local, LM Studio for GUI-driven local. You pick by changing the base URL, API key, and model name. The Python code never changes.
Same client, multiple providers
One OpenAI client, many possible backends.
# OpenRouter (cloud, free tier available)
LLM_BASE_URL=https://openrouter.ai/api/v1
LLM_API_KEY=your_openrouter_api_key_here
LLM_MODEL=google/gemini-2.5-flash-lite
# Ollama (local)
# LLM_BASE_URL=http://localhost:11434/v1
# LLM_API_KEY=ollama
# LLM_MODEL=gemma3:4b
# LM Studio (local)
# LLM_BASE_URL=http://localhost:1234/v1
# LLM_API_KEY=lm-studioThree providers, three sets of env vars, zero Python changes. Uncomment the block you want and restart the backend. Ollama uses a placeholder API key because its local server does not check it.
The OpenAI Python client requires an api_key argument and refuses to start without one. Ollama ignores the value on the server side but the client still wants a non-empty string. Passing the literal "ollama" satisfies the client without exposing anything.
AI prompt: Try it: install a local model
Loading practice…
Quiz: Quiz
Loading practice…