{"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":"Error","httpStatus":null,"severity":"critical","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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/mistral/index.js#L1-L31","documentation":"Constructor guard mirroring Minimax: MistralLLM throws at construction if process.env.MISTRAL_API_KEY is absent. The key feeds the OpenAI-compatible client at https://api.mistral.ai/v1. (The later `?? null` on the apiKey is moot since the constructor already guaranteed presence.)","triggerScenarios":"Instantiating `new MistralLLM(...)` when MISTRAL_API_KEY is unset/empty. AnythingLLM hits this when the workspace provider is set to Mistral but credentials are missing.","commonSituations":"Mistral provider selected without configuring the key; .env not reloaded after editing; typo (MISTRAL_APIKEY, MISTRAL_KEY); secret dropped from the deployment env.","solutions":["Add MISTRAL_API_KEY to server/.env with a valid key from console.mistral.ai.","Restart the server to reload env.","Confirm process.env.MISTRAL_API_KEY is populated in the running process.","For containerized deploys, inject the env var into the container spec."],"exampleFix":"// server/.env\nMISTRAL_API_KEY=your_key_here\nMISTRAL_MODEL_PREF=mistral-tiny","handlingStrategy":"validation","validationCode":"if (!process.env.MISTRAL_API_KEY) {\n  throw new Error('MISTRAL_API_KEY missing — set it before enabling Mistral.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const llm = new MistralLLM(embedder, modelPref);\n} catch (e) {\n  if (/No Mistral API key/i.test(e.message)) {\n    // config error — guide user to set MISTRAL_API_KEY\n  }\n}","preventionTips":["Validate Mistral credentials in the provider factory before construction.","Run a startup env check for every enabled provider's key.","Keep the admin credential form and provider selector coupled."],"tags":["mistral","configuration","api-key","env","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}