Mintplex-Labs/anything-llm · error

No Mistral API key was set.

Error message

No Mistral API key was set.

What it means

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.

Solutions

  1. Add MISTRAL_API_KEY=<key from console.mistral.ai> to the server's .env
  2. Restart the AnythingLLM server or container
  3. In Docker, confirm the variable name reaches the container (name only, never the value)
  4. Check for whitespace/quotes around the value in compose files

Example fix

# before
# (MISTRAL_API_KEY not set)
# after
MISTRAL_API_KEY=your-mistral-key
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.MISTRAL_API_KEY)
  throw new Error('Mistral provider selected but MISTRAL_API_KEY is not configured');
const llm = new MistralLLM(embedder);

Try / catch

try {
  const llm = new MistralLLM(embedder);
} catch (e) {
  if (e.message === 'No Mistral API key was set.')
    return respondConfigError(e); // configure key, restart, do not retry
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/4bf492818fd73cb0. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/AiProviders/mistral/index.js:13

const { NativeEmbedder } = require("../../EmbeddingEngines/native");
const {
  LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");
const {
  handleDefaultStreamResponseV2,
  formatChatHistory,
} = require("../../helpers/chat/responses");

class MistralLLM {
  constructor(embedder = null, modelPreference = null) {
    if (!process.env.MISTRAL_API_KEY)
      throw new Error("No Mistral API key was set.");

    this.className = "MistralLLM";
    const { OpenAI: OpenAIApi } = require("openai");
    this.openai = new OpenAIApi({
      baseURL: "https://api.mistral.ai/v1",
      apiKey: process.env.MISTRAL_API_KEY ?? null,
    });
    this.model =
      modelPreference || process.env.MISTRAL_MODEL_PREF || "mistral-tiny";
    this.limits = {
      history: this.promptWindowLimit() * 0.15,
      system: this.promptWindowLimit() * 0.15,
      user: this.promptWindowLimit() * 0.7,
    };

    this.embedder = embedder ?? new NativeEmbedder();
    this.defaultTemp = 0.0;
    this.log("Initialized with model:", this.model);

View on GitHub (pinned to 3aec848f28)