{"record":{"id":"be52ccb1a53fe7ad","repo":"Mintplex-Labs/anything-llm","slug":"env-no-valid-llm-provider-value-found-in-environm","errorCode":null,"errorMessage":"ENV: No valid LLM_PROVIDER value found in environment! Using ${process.env.LLM_PROVIDER}","messagePattern":"ENV: No valid LLM_PROVIDER value found in environment! Using (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/helpers/index.js","lineNumber":262,"sourceCode":"      const { OMLXLLM } = require(\"../AiProviders/omlx\");\n      return new OMLXLLM(embedder, model);\n    case \"minimax\":\n      const { MinimaxLLM } = require(\"../AiProviders/minimax\");\n      return new MinimaxLLM(embedder, model);\n    case \"cerebras\":\n      const { CerebrasLLM } = require(\"../AiProviders/cerebras\");\n      return new CerebrasLLM(embedder, model);\n    case \"vertex\":\n      const { VertexLLM } = require(\"../AiProviders/vertex\");\n      return new VertexLLM(embedder, model);\n    case \"anythingllm-router\":\n      // Model router is handled separately in stream.js via AnythingLLMModelRouter.\n      // This case should not be hit directly - if it is, throw a descriptive error.\n      throw new Error(\n        \"anythingllm-router provider must be resolved via AnythingLLMModelRouter class, not getLLMProvider directly.\"\n      );\n    default:\n      throw new Error(\n        `ENV: No valid LLM_PROVIDER value found in environment! Using ${process.env.LLM_PROVIDER}`\n      );\n  }\n}\n\n/**\n * Returns the EmbedderProvider by itself to whatever is currently in the system settings.\n * @returns {BaseEmbedderProvider}\n */\nfunction getEmbeddingEngineSelection() {\n  const { NativeEmbedder } = require(\"../EmbeddingEngines/native\");\n  const engineSelection = process.env.EMBEDDING_ENGINE;\n  switch (engineSelection) {\n    case \"openai\":\n      const { OpenAiEmbedder } = require(\"../EmbeddingEngines/openAi\");\n      return new OpenAiEmbedder();\n    case \"azure\":\n      const {","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/helpers/index.js#L244-L280","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","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.","If using docker, verify the variable is actually inside the container: docker exec <container> printenv LLM_PROVIDER.","If LLM_PROVIDER=anythingllm-router, remove it and configure the router through its own settings; it cannot be used with getLLMProvider directly.","Check for stray whitespace/quotes in .env (LLM_PROVIDER='openai' is fine, LLM_PROVIDER=openai\\r is not on Windows-edited files)."],"exampleFix":"// before (.env)\nLLM_PROVIDER=\n\n// after (.env)\nLLM_PROVIDER=openai\nOPEN_AI_KEY=sk-...\n// then restart: docker compose down && docker compose up -d","handlingStrategy":"validation","validationCode":"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'];\nconst provider = process.env.LLM_PROVIDER;\nif (!provider || !SUPPORTED.includes(provider)) {\n  throw new Error(`LLM_PROVIDER '${provider}' is not supported. Set it in .env and restart.`);\n}","typeGuard":"/** @param {string|null|undefined} v */\nfunction isValidLLMProvider(v) {\n  return typeof v === 'string' && v.length > 0 && v !== 'anythingllm-router' && /^[a-z0-9-]+$/.test(v);\n}","tryCatchPattern":null,"preventionTips":["Fail fast at boot: validate LLM_PROVIDER (and other provider envs) during startup, not at first chat.","Add a .env.example checklist and a pre-deploy script that asserts required vars exist.","Always fully restart containers after env changes; verify with printenv inside the container."],"tags":["env","llm","provider-selection","configuration","startup"],"backgroundTag":"missing-env-var","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}