Skip to content

LLM (optional)

Pagelore can use an LLM for its own internal work:

It never uses the LLM to answer questions. That stays with your app. Without an LLM, those features are off and everything else works the same.

Set it up

Set LLM_PROVIDER (and usually LLM_MODEL and LLM_API_KEY), install the provider's extra, then restart.

LLM_PROVIDER="OLLAMA"
LLM_MODEL="llama3.2"
uv sync --extra ollama
ollama pull llama3.2
LLM_PROVIDER="OPENAI"
LLM_MODEL="gpt-5-mini"
LLM_API_KEY="sk-..."
uv sync --extra openai
LLM_PROVIDER="ANTHROPIC"
LLM_MODEL="claude-haiku-5-5"
LLM_API_KEY="sk-ant-..."
uv sync --extra anthropic
LLM_PROVIDER="OPENAI_COMPATIBLE"
LLM_URL="http://localhost:30000/v1"
LLM_MODEL="my-model"
uv sync --extra openai

Then check the connection:

curl -X POST localhost:8000/api/v1/llm/check
{"provider": "OLLAMA", "model": "llama3.2", "max_tokens": 4096,
 "structured_output": "schema", "ok": true, "latency_ms": 812.4,
 "attempts": 1, "input_tokens": 61, "output_tokens": 9, "finish_reason": "stop"}

The check sends a one-line JSON request. A failure is reported in error with ok: false, not as an HTTP error. GET /api/v1/llm/model shows the configured provider, model, max_tokens, temperature and structured_output. Both return 409 when no LLM is configured.

Providers

LLM_PROVIDER Extra Default model Notes
OPENAI openai gpt-5-mini
AZURE_OPENAI openai LLM_URL is the resource endpoint and LLM_MODEL the deployment; AZURE_OPENAI_API_VERSION
ANTHROPIC anthropic claude-haiku-5-5 LLM_URL for an Anthropic-compatible gateway
GEMINI gemini gemini-2.5-flash LLM_API_KEY, or GOOGLE_CLOUD_PROJECT (and GOOGLE_CLOUD_LOCATION) for Vertex AI
MISTRAL mistral mistral-small-latest
COHERE cohere command-a-03-2025
BEDROCK bedrock amazon.nova-lite-v1:0 AWS credentials and AWS_REGION. Uses the Converse API, so any Bedrock chat model works
DEEPSEEK openai deepseek-chat
OPENROUTER, GROQ, XAI, TOGETHER, FIREWORKS, CEREBRAS, DEEPINFRA, NVIDIA openai Hosted OpenAI-compatible APIs at their default URLs; need LLM_API_KEY. NVIDIA with LLM_URL is a self-hosted NIM
HUGGINGFACE huggingface Inference Providers (HUGGINGFACE_INFERENCE_PROVIDER), or a TGI server / Inference Endpoint at LLM_URL
OLLAMA ollama llama3.2 Pull the model first
VLLM, LLAMA_CPP, LOCALAI, LMSTUDIO, LEMONADE, LITELLM openai Local servers at their default URLs unless LLM_URL is set
OPENAI_COMPATIBLE openai Any other /v1/chat/completions server (SGLang, Xinference, KoboldCpp, Jan, ...); LLM_URL is required

SENTENCE_TRANSFORMERS, FASTEMBED, VOYAGE and JINA have no chat models, so those values are refused at startup.

Structured output

Both features ask the LLM for JSON. LLM_STRUCTURED_OUTPUT sets how that is enforced. Leave it empty to use the best mode the provider supports.

Mode How Default for
schema The API constrains the reply to the JSON schema OpenAI, Anthropic, Gemini, Mistral, Cohere, Ollama, vLLM, llama.cpp, ...
json JSON mode, with the schema in the prompt Groq, DeepSeek, Together, DeepInfra, NVIDIA, LocalAI
prompt Instructions only; works with every model Bedrock, Hugging Face, Lemonade
  • Every reply is parsed and validated against the schema.
  • An invalid reply is sent back once with the validation error, so the model can fix it.
  • Reasoning sections (<think>...</think>) are removed before parsing.
  • If a server rejects schema, set json or prompt.

Settings

Setting Default
LLM_PROVIDER empty Empty: no LLM
LLM_MODEL the provider's default
LLM_API_KEY For hosted providers
LLM_URL the provider's default Custom endpoint or gateway
LLM_TEMPERATURE empty Sent only when set, because some recent models reject it
LLM_MAX_TOKENS 4096 Most tokens per reply. Reasoning models spend part of it thinking
LLM_STRUCTURED_OUTPUT empty schema, json or prompt (see above)
LLM_TIMEOUT 120 Seconds per request
LLM_MAX_RETRIES 2 Retries of failed requests, for clients that retry
LLM_CONCURRENCY 4 Parallel requests of one job (the chunk contexts of a document, the evaluation questions)
LLM_CONTEXT_MAX_DOCUMENT_CHARS 60000 For llm_context: the most document text sent with each chunk. Longer documents send the part around the chunk
HUGGINGFACE_INFERENCE_PROVIDER empty For HUGGINGFACE, e.g. hf-inference
AZURE_OPENAI_API_VERSION 2024-10-21 For AZURE_OPENAI

Tips for local models

  • Reasoning models can think for minutes and use thousands of tokens before they reply. If replies time out or get cut off, raise LLM_TIMEOUT and LLM_MAX_TOKENS. The server log says which limit was hit.
  • Ollama's context window also caps the reply. If the log still says the reply was cut, set OLLAMA_CONTEXT_LENGTH on the Ollama server.
  • Small models work for chunk contexts and questions, but read the generated questions before you trust an evaluation built on them.
  • Cost: llm_context makes one call per chunk at ingestion, and question generation one call per question. Try them on a few documents first.