{"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":null,"httpStatus":null,"severity":"error","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/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/moonshotAi/index.js#L1-L32","documentation":"MoonshotAiLLM's constructor throws when process.env.MOONSHOT_AI_API_KEY is falsy, before the OpenAI-compatible client for https://api.moonshot.ai/v1 is created. Any code path that instantiates the provider (selecting Moonshot as the LLM, sending a chat) fails until the key is set.","triggerScenarios":"Selecting Moonshot/Kimi as the provider with MOONSHOT_AI_API_KEY unset, misspelled, or empty; editing .env without restarting; container deployments missing the variable.","commonSituations":"Typo'd variable name (MOONSHOT_API_KEY, MOONSHOT_KEY); forgetting to restart after .env edits; docker-compose without the env entry.","solutions":["Add MOONSHOT_AI_API_KEY=<key from platform.moonshot.ai> to the server's .env","Restart the AnythingLLM server or container","Verify the variable name reaches the container (name check only)","Remove quotes/whitespace around the value in compose/.env files"],"exampleFix":"# before\n# (MOONSHOT_AI_API_KEY not set)\n# after\nMOONSHOT_AI_API_KEY=sk-...your-key","handlingStrategy":"validation","validationCode":"if (!process.env.MOONSHOT_AI_API_KEY)\n  throw new Error('Moonshot provider selected but MOONSHOT_AI_API_KEY is not configured');\nconst llm = new MoonshotAiLLM(embedder);","typeGuard":null,"tryCatchPattern":"try {\n  const llm = new MoonshotAiLLM(embedder);\n} catch (e) {\n  if (e.message === 'No Moonshot AI API key was set.')\n    return respondConfigError(e); // configure key, restart, do not retry\n  throw e;\n}","preventionTips":["Set MOONSHOT_AI_API_KEY before selecting Moonshot in the UI","Restart the server after .env changes","Double-check the exact variable name (MOONSHOT_AI_API_KEY, not MOONSHOT_API_KEY)"],"tags":["moonshot","kimi","anythingllm","api-key","environment-variables","configuration"],"backgroundTag":"missing-api-key","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}