Mintplex-Labs/anything-llm · error · Error

ENV: No valid LLM_PROVIDER value found in environment! Using

Error message

ENV: No valid LLM_PROVIDER value found in environment! Using ${process.env.LLM_PROVIDER}

What it means

Thrown by getLLMProvider() in server/utils/helpers/index.js when the LLM_PROVIDER environment variable does not match any switch case (anthropic, openai, azure, lanciai, ... minimax, cerebras). The message interpolates the raw value so 'Using undefined' means the variable is not set at all. Note that 'anythingllm-router' is deliberately rejected here because it must be resolved through the AnythingLLMModelRouter class in stream.js.

Solutions

  1. Set LLM_PROVIDER in the server/.env file to a supported value exactly as cased in the switch (e.g. LLM_PROVIDER=openai, LLM_PROVIDER=anthropic, LLM_PROVIDER=ollama).
  2. Fully restart the Node process (or docker compose down/up) so the new env is loaded - process.env is read at call time but is only populated from .env at boot.
  3. If using docker, verify the variable is actually inside the container: docker exec <container> printenv LLM_PROVIDER.
  4. If LLM_PROVIDER=anythingllm-router, remove it and configure the router through its own settings; it cannot be used with getLLMProvider directly.
  5. Check for stray whitespace/quotes in .env (LLM_PROVIDER='openai' is fine, LLM_PROVIDER=openai\r is not on Windows-edited files).

Example fix

// before (.env)
LLM_PROVIDER=

// after (.env)
LLM_PROVIDER=openai
OPEN_AI_KEY=sk-...
// then restart: docker compose down && docker compose up -d
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = ['anthropic','openai','azure','lanciai','gemini','lmstudio','localai','ollama','togetherai','mistral','groq','perplexity','openrouter','nvidia','apipie','deepseek','docker-model-runner','privatemode','sambanova','lemonade','omlx','minimax','cerebras'];
const provider = process.env.LLM_PROVIDER;
if (!provider || !SUPPORTED.includes(provider)) {
  throw new Error(`LLM_PROVIDER '${provider}' is not supported. Set it in .env and restart.`);
}

Type guard

/** @param {string|null|undefined} v */
function isValidLLMProvider(v) {
  return typeof v === 'string' && v.length > 0 && v !== 'anythingllm-router' && /^[a-z0-9-]+$/.test(v);
}

Prevention

When it happens

Trigger: Any chat, embed, or agent flow that calls getLLMProvider() while LLM_PROVIDER is unset, misspelled ('open_ai'), wrong case ('OpenAI'), or set to a value the installed version does not support (e.g. an older build that lacks 'cerebras'). Also hit when LLM_PROVIDER=anythingllm-router is resolved outside the model-router path.

Common situations: Fresh clone without completing .env setup; .env edited but the server/container was never restarted so process.env still holds the old value; docker-compose .env not passed into the container; upgrading or downgrading AnythingLLM where the provider list changed; CI runs that never copy .env.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/be52ccb1a53fe7ad. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/helpers/index.js:262

      const { OMLXLLM } = require("../AiProviders/omlx");
      return new OMLXLLM(embedder, model);
    case "minimax":
      const { MinimaxLLM } = require("../AiProviders/minimax");
      return new MinimaxLLM(embedder, model);
    case "cerebras":
      const { CerebrasLLM } = require("../AiProviders/cerebras");
      return new CerebrasLLM(embedder, model);
    case "vertex":
      const { VertexLLM } = require("../AiProviders/vertex");
      return new VertexLLM(embedder, model);
    case "anythingllm-router":
      // Model router is handled separately in stream.js via AnythingLLMModelRouter.
      // This case should not be hit directly - if it is, throw a descriptive error.
      throw new Error(
        "anythingllm-router provider must be resolved via AnythingLLMModelRouter class, not getLLMProvider directly."
      );
    default:
      throw new Error(
        `ENV: No valid LLM_PROVIDER value found in environment! Using ${process.env.LLM_PROVIDER}`
      );
  }
}

/**
 * Returns the EmbedderProvider by itself to whatever is currently in the system settings.
 * @returns {BaseEmbedderProvider}
 */
function getEmbeddingEngineSelection() {
  const { NativeEmbedder } = require("../EmbeddingEngines/native");
  const engineSelection = process.env.EMBEDDING_ENGINE;
  switch (engineSelection) {
    case "openai":
      const { OpenAiEmbedder } = require("../EmbeddingEngines/openAi");
      return new OpenAiEmbedder();
    case "azure":
      const {

View on GitHub (pinned to 20f6d3546c)