Configuration & LLM Providers
llm_provider.py's get_llm(model_override=None) reads LLM_PROVIDER and dispatches to one _get_<provider>_llm() per provider — each validates only its own requirements and fails fast with an actionable message if something's missing.
Environment variables
| Variable | Description |
|---|---|
| LLM_PROVIDER | gemini (default), openai, anthropic, or ollama — chat model backend. |
| GEMINI_API_KEY | Required when LLM_PROVIDER=gemini — Google AI Studio API key. |
| GEMINI_LLM_MODEL | Required when LLM_PROVIDER=gemini, unless --model is passed. |
| OPENAI_API_KEY | Required when LLM_PROVIDER=openai or EMBEDDINGS_PROVIDER=openai — same key covers both. |
| ANTHROPIC_API_KEY | Required when LLM_PROVIDER=anthropic. |
| EMBEDDINGS_PROVIDER | ollama (default) or openai — embeddings backend for --rag (unrelated to LLM_PROVIDER). |
| API_SECRET | REST API only — pre-shared secret exchanged for a JWT via POST /auth/token. |
| JWT_SECRET_KEY | REST API only — signs issued JWTs (HS256); must differ from API_SECRET. |
| CORS_ORIGINS | REST API only — comma-separated allowed origins; unset/empty = none allowed (fail closed). |
GEMINI_API_KEY/GEMINI_LLM_MODEL are only required while LLM_PROVIDER is unset or gemini. RAG variables are only needed with --rag (or the REST API, which builds the RAG store at startup regardless of a flag). Generate API_SECRET/JWT_SECRET_KEY independently with openssl rand -hex 32 — never reuse one as the other.Provider dispatch
Each provider is a functionally separate concern from the RAG embeddings provider below — they are not interchangeable or merged, even though the dispatch pattern is structurally similar.
| Provider | Chat class | Requires | Default model |
|---|---|---|---|
| gemini | ChatGoogleGenerativeAI | GEMINI_API_KEY + (--model or GEMINI_LLM_MODEL) | none — must be set explicitly |
| openai | ChatOpenAI | OPENAI_API_KEY (reused from RAG embeddings) | gpt-4o-mini |
| anthropic | ChatAnthropic | ANTHROPIC_API_KEY (adds langchain-anthropic) | claude-3-5-haiku-latest |
| ollama | ChatOllama | local server reachable + model pulled | llama3.2:3b |
The ollama provider has no cloud key, but checks that Ollama is reachable and the model is pulled before starting, failing fast with the exact ollama pull <model> fix if not. At invocation time, ollama/langchain_ollama raise a builtin ConnectionError on an unreachable server and ollama.ResponseError on other API errors — both are caught explicitly in main.py/api/main.py alongside openai.OpenAIError/anthropic.AnthropicError, next to the pre-existing Gemini-specific catches.
--model overrides the model name for whichever provider is active. --llm-provider overrides LLM_PROVIDER for the process. chain_builder.py never constructs the chat model directly — llm_provider.get_llm() is the single code path for building it, called from both main.py's build_chain()/build_agent_graph() and api/main.py's lifespan().
Next steps
- Ground answers in documents — see RAG Pipeline for
EMBEDDINGS_PROVIDERand the retrieval flow. - Wire this into the REST API — see REST API Reference.
- Switch providers at runtime — see CLI Reference for
--llm-providerand--model.