Mintplex-Labs/anything-llm · error · Error
Moonshot AI model must be set to use agents.
Error message
Moonshot AI model must be set to use agents.
What it means
Thrown by AgentHandler.checkSetup() (server/utils/agents/index.js:244) when the workspace agent provider is 'moonshotai' but MOONSHOT_AI_MODEL_PREF is unset/empty. Unusually, this guard validates a MODEL PREFERENCE rather than an API key, because the Moonshot provider needs an explicit model id (e.g. moonshot-v1-8k) selected before it can run. A missing key will surface separately as a provider auth error.
Source
Thrown at server/utils/agents/index.js:245
throw new Error("Novita API Key must be provided to use agents.");
break;
case "nvidia-nim":
if (!process.env.NVIDIA_NIM_LLM_BASE_PATH)
throw new Error(
"NVIDIA NIM base path must be provided to use agents."
);
break;
case "ppio":
if (!process.env.PPIO_API_KEY)
throw new Error("PPIO API Key must be provided to use agents.");
break;
case "gemini":
if (!process.env.GEMINI_API_KEY)
throw new Error("Gemini API key must be provided to use agents.");
break;
case "moonshotai":
if (!process.env.MOONSHOT_AI_MODEL_PREF)
throw new Error("Moonshot AI model must be set to use agents.");
break;
case "cometapi":
if (!process.env.COMETAPI_LLM_API_KEY)
throw new Error("CometAPI API Key must be provided to use agents.");
break;
case "foundry":
if (!process.env.FOUNDRY_BASE_PATH)
throw new Error("Foundry base path must be provided to use agents.");
break;
case "giteeai":
if (!process.env.GITEE_AI_API_KEY)
throw new Error("GiteeAI API Key must be provided to use agents.");
break;
case "cohere":
if (!process.env.COHERE_API_KEY)
throw new Error("Cohere API key must be provided to use agents.");
break;
case "docker-model-runner":View on GitHub (pinned to 526360e320)
Solutions
- Set MOONSHOT_AI_MODEL_PREF in .env to a valid Moonshot model id (e.g. moonshot-v1-8k, moonshot-v1-32k, moonshot-v1-128k).
- Also set MOONSHOT_AI_API_KEY with your key from platform.moonshot.cn.
- Restart AnythingLLM to reload process.env.
- Re-pick the model in System > LLM Preference > Moonshot AI so the preference persists.
Example fix
// before (.env) // MOONSHOT_AI_MODEL_PREF= // MOONSHOT_AI_API_KEY= // after (.env) MOONSHOT_AI_MODEL_PREF=moonshot-v1-8k MOONSHOT_AI_API_KEY=sk-...your-key
Defensive patterns
Strategy: validation
Validate before calling
const model = process.env.MOONSHOT_AI_MODEL_PREF;
const allowed = ['moonshot-v1-8k', 'moonshot-v1-32k', 'moonshot-v1-128k'];
if (!model || !allowed.includes(model)) {
throw new Error(
'Cannot start Moonshot agent: set MOONSHOT_AI_MODEL_PREF to one of ' + allowed.join(', ')
);
}
// Guard checks model, not key - also ensure the key is present to avoid a later auth failure:
if (!process.env.MOONSHOT_AI_API_KEY) {
console.warn('MOONSHOT_AI_API_KEY unset - Moonshot auth may fail at inference time');
} Try / catch
try {
await agentHandler.start();
} catch (e) {
if (/Moonshot AI model must be set/.test(e.message)) {
return respondConfigError('moonshotai', ['MOONSHOT_AI_MODEL_PREF', 'MOONSHOT_AI_API_KEY']);
}
throw e;
} Prevention
- This guard checks the MODEL preference, not a key - also set MOONSHOT_AI_API_KEY to avoid a follow-up auth error.
- Pick the model in System > LLM Preference so MOONSHOT_AI_MODEL_PREF persists across restarts.
- Restart AnythingLLM after .env edits.
- Add a startup provider->env-var validator that knows Moonshot's requirement is the model id.
When it happens
Trigger: An agent invocation runs with workspace.agentProvider === 'moonshotai' while MOONSHOT_AI_MODEL_PREF is absent from process.env. Path: #providerSetupAndCheck() -> checkSetup() at index.js:476.
Common situations: Moonshot AI selected in System > LLM Preference but no model chosen/saved; .env has the key but not the model preference line; model id typo; .env edited but AnythingLLM not restarted.
Related errors
- Azure OpenAI API endpoint and key must be provided to use ag
- KoboldCPP must have a valid base path to use for the api.
- LocalAI must have a valid base path to use for the api.
- OpenRouter API key must be provided to use agents.
- Mistral API key must be provided to use agents.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/a5016aed08e9c58d.
Report an issue: GitHub.