{"record":{"id":"c81c64920ee94ab0","repo":"Mintplex-Labs/anything-llm","slug":"no-moonshot-ai-api-key-was-set","errorCode":null,"errorMessage":"No Moonshot AI API key was set.","messagePattern":"No Moonshot AI API key was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/utils/AiProviders/moonshotAi/index.js","lineNumber":14,"sourceCode":"const { NativeEmbedder } = require(\"../../EmbeddingEngines/native\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\nconst {\n  handleDefaultStreamResponseV2,\n  formatChatHistory,\n} = require(\"../../helpers/chat/responses\");\nconst { MODEL_MAP } = require(\"../modelMap\");\n\nclass MoonshotAiLLM {\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.MOONSHOT_AI_API_KEY)\n      throw new Error(\"No Moonshot AI API key was set.\");\n    this.className = \"MoonshotAiLLM\";\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n\n    this.openai = new OpenAIApi({\n      baseURL: \"https://api.moonshot.ai/v1\",\n      apiKey: process.env.MOONSHOT_AI_API_KEY,\n    });\n    this.model =\n      modelPreference ||\n      process.env.MOONSHOT_AI_MODEL_PREF ||\n      \"moonshot-v1-32k\";\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();","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/moonshotAi/index.js#L1-L32","documentation":"Constructor guard for MoonshotAiLLM: throws if process.env.MOONSHOT_AI_API_KEY is absent. The key builds the OpenAI-compatible client at https://api.moonshot.ai/v1. Default model is moonshot-v1-32k.","triggerScenarios":"Instantiating `new MoonshotAiLLM(...)` without MOONSHOT_AI_API_KEY set, e.g. selecting Moonshot as the provider without credentials.","commonSituations":"Provider switched to Moonshot without setting the key; .env typo (MOONSHOT_API_KEY vs MOONSHOT_AI_API_KEY); secret missing from the deploy environment.","solutions":["Set MOONSHOT_AI_API_KEY in server/.env to a valid Moonshot key.","Restart the server to reload env.","Double-check the exact env var name (MOONSHOT_AI_API_KEY, with _AI).","Inject the secret into the container/CI environment."],"exampleFix":"// server/.env\nMOONSHOT_AI_API_KEY=your_key_here\nMOONSHOT_AI_MODEL_PREF=moonshot-v1-32k","handlingStrategy":"validation","validationCode":"if (!process.env.MOONSHOT_AI_API_KEY) {\n  throw new Error('MOONSHOT_AI_API_KEY missing — set it before enabling Moonshot.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const llm = new MoonshotAiLLM(embedder, modelPref);\n} catch (e) {\n  if (/No Moonshot AI API key/i.test(e.message)) {\n    // config error — note the exact var name MOONSHOT_AI_API_KEY\n  }\n}","preventionTips":["Mind the exact env name (MOONSHOT_AI_API_KEY, with _AI).","Validate keys in the provider factory.","Add startup env checks for enabled providers."],"tags":["moonshot","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"}