{"record":{"id":"4bf492818fd73cb0","repo":"Mintplex-Labs/anything-llm","slug":"no-mistral-api-key-was-set","errorCode":null,"errorMessage":"No Mistral API key was set.","messagePattern":"No Mistral API key was set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/mistral/index.js","lineNumber":13,"sourceCode":"const { NativeEmbedder } = require(\"../../EmbeddingEngines/native\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\nconst {\n  handleDefaultStreamResponseV2,\n  formatChatHistory,\n} = require(\"../../helpers/chat/responses\");\n\nclass MistralLLM {\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.MISTRAL_API_KEY)\n      throw new Error(\"No Mistral API key was set.\");\n\n    this.className = \"MistralLLM\";\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    this.openai = new OpenAIApi({\n      baseURL: \"https://api.mistral.ai/v1\",\n      apiKey: process.env.MISTRAL_API_KEY ?? null,\n    });\n    this.model =\n      modelPreference || process.env.MISTRAL_MODEL_PREF || \"mistral-tiny\";\n    this.limits = {\n      history: this.promptWindowLimit() * 0.15,\n      system: this.promptWindowLimit() * 0.15,\n      user: this.promptWindowLimit() * 0.7,\n    };\n\n    this.embedder = embedder ?? new NativeEmbedder();\n    this.defaultTemp = 0.0;\n    this.log(\"Initialized with model:\", this.model);","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/mistral/index.js#L1-L31","documentation":"MistralLLM's constructor throws when process.env.MISTRAL_API_KEY is falsy, before the OpenAI-compatible client for https://api.mistral.ai/v1 is built. Any attempt to instantiate the provider (selecting Mistral, sending a chat, embedding-adjacent flows that construct LLMs) fails until the key is set.","triggerScenarios":"Choosing Mistral as the LLM provider with MISTRAL_API_KEY unset, misspelled, or empty; editing .env without restarting; containerized deployments where the variable was not injected.","commonSituations":"Typo'd variable name (MISTRAL_KEY, MISTRALAPI_KEY); .env edited but process not restarted; docker run without -e/--env-file; CI environments without the key.","solutions":["Add MISTRAL_API_KEY=<key from console.mistral.ai> to the server's .env","Restart the AnythingLLM server or container","In Docker, confirm the variable name reaches the container (name only, never the value)","Check for whitespace/quotes around the value in compose files"],"exampleFix":"# before\n# (MISTRAL_API_KEY not set)\n# after\nMISTRAL_API_KEY=your-mistral-key","handlingStrategy":"validation","validationCode":"if (!process.env.MISTRAL_API_KEY)\n  throw new Error('Mistral provider selected but MISTRAL_API_KEY is not configured');\nconst llm = new MistralLLM(embedder);","typeGuard":null,"tryCatchPattern":"try {\n  const llm = new MistralLLM(embedder);\n} catch (e) {\n  if (e.message === 'No Mistral API key was set.')\n    return respondConfigError(e); // configure key, restart, do not retry\n  throw e;\n}","preventionTips":["Set MISTRAL_API_KEY before selecting Mistral in the UI","Restart after .env edits","Use --env-file in Docker rather than ad-hoc -e flags","Add a preflight config check per selected provider"],"tags":["mistral","anythingllm","api-key","environment-variables","configuration"],"backgroundTag":"missing-api-key","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}