Mintplex-Labs/anything-llm · critical · Error
No Moonshot AI API key was set.
Error message
No Moonshot AI API key was set.
What it means
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.
Source
Thrown at server/utils/AiProviders/moonshotAi/index.js:14
const { NativeEmbedder } = require("../../EmbeddingEngines/native");
const {
LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");
const {
handleDefaultStreamResponseV2,
formatChatHistory,
} = require("../../helpers/chat/responses");
const { MODEL_MAP } = require("../modelMap");
class MoonshotAiLLM {
constructor(embedder = null, modelPreference = null) {
if (!process.env.MOONSHOT_AI_API_KEY)
throw new Error("No Moonshot AI API key was set.");
this.className = "MoonshotAiLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.openai = new OpenAIApi({
baseURL: "https://api.moonshot.ai/v1",
apiKey: process.env.MOONSHOT_AI_API_KEY,
});
this.model =
modelPreference ||
process.env.MOONSHOT_AI_MODEL_PREF ||
"moonshot-v1-32k";
this.limits = {
history: this.promptWindowLimit() * 0.15,
system: this.promptWindowLimit() * 0.15,
user: this.promptWindowLimit() * 0.7,
};
this.embedder = embedder ?? new NativeEmbedder();View on GitHub (pinned to 526360e320)
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.
Example fix
// server/.env MOONSHOT_AI_API_KEY=your_key_here MOONSHOT_AI_MODEL_PREF=moonshot-v1-32k
Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.MOONSHOT_AI_API_KEY) {
throw new Error('MOONSHOT_AI_API_KEY missing — set it before enabling Moonshot.');
} Try / catch
try {
const llm = new MoonshotAiLLM(embedder, modelPref);
} catch (e) {
if (/No Moonshot AI API key/i.test(e.message)) {
// config error — note the exact var name MOONSHOT_AI_API_KEY
}
} Prevention
- Mind the exact env name (MOONSHOT_AI_API_KEY, with _AI).
- Validate keys in the provider factory.
- Add startup env checks for enabled providers.
When it happens
Trigger: Instantiating `new MoonshotAiLLM(...)` without MOONSHOT_AI_API_KEY set, e.g. selecting Moonshot as the provider without credentials.
Common situations: Provider switched to Moonshot without setting the key; .env typo (MOONSHOT_API_KEY vs MOONSHOT_AI_API_KEY); secret missing from the deploy environment.
Related errors
- No Minimax API key was set.
- No Mistral API key was set.
- No Novita API key was set.
- No Perplexity API key was set.
- No PPIO API key was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/c81c64920ee94ab0.
Report an issue: GitHub.