{"record":{"id":"a5016aed08e9c58d","repo":"Mintplex-Labs/anything-llm","slug":"moonshot-ai-model-must-be-set-to-use-agents","errorCode":null,"errorMessage":"Moonshot AI model must be set to use agents.","messagePattern":"Moonshot AI model must be set to use agents\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/index.js","lineNumber":245,"sourceCode":"          throw new Error(\"Novita API Key must be provided to use agents.\");\n        break;\n      case \"nvidia-nim\":\n        if (!process.env.NVIDIA_NIM_LLM_BASE_PATH)\n          throw new Error(\n            \"NVIDIA NIM base path must be provided to use agents.\"\n          );\n        break;\n      case \"ppio\":\n        if (!process.env.PPIO_API_KEY)\n          throw new Error(\"PPIO API Key must be provided to use agents.\");\n        break;\n      case \"gemini\":\n        if (!process.env.GEMINI_API_KEY)\n          throw new Error(\"Gemini API key must be provided to use agents.\");\n        break;\n      case \"moonshotai\":\n        if (!process.env.MOONSHOT_AI_MODEL_PREF)\n          throw new Error(\"Moonshot AI model must be set to use agents.\");\n        break;\n      case \"cometapi\":\n        if (!process.env.COMETAPI_LLM_API_KEY)\n          throw new Error(\"CometAPI API Key must be provided to use agents.\");\n        break;\n      case \"foundry\":\n        if (!process.env.FOUNDRY_BASE_PATH)\n          throw new Error(\"Foundry base path must be provided to use agents.\");\n        break;\n      case \"giteeai\":\n        if (!process.env.GITEE_AI_API_KEY)\n          throw new Error(\"GiteeAI API Key must be provided to use agents.\");\n        break;\n      case \"cohere\":\n        if (!process.env.COHERE_API_KEY)\n          throw new Error(\"Cohere API key must be provided to use agents.\");\n        break;\n      case \"docker-model-runner\":","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/index.js#L227-L263","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (.env)\n// MOONSHOT_AI_MODEL_PREF=\n// MOONSHOT_AI_API_KEY=\n\n// after (.env)\nMOONSHOT_AI_MODEL_PREF=moonshot-v1-8k\nMOONSHOT_AI_API_KEY=sk-...your-key","handlingStrategy":"validation","validationCode":"const model = process.env.MOONSHOT_AI_MODEL_PREF;\nconst allowed = ['moonshot-v1-8k', 'moonshot-v1-32k', 'moonshot-v1-128k'];\nif (!model || !allowed.includes(model)) {\n  throw new Error(\n    'Cannot start Moonshot agent: set MOONSHOT_AI_MODEL_PREF to one of ' + allowed.join(', ')\n  );\n}\n// Guard checks model, not key - also ensure the key is present to avoid a later auth failure:\nif (!process.env.MOONSHOT_AI_API_KEY) {\n  console.warn('MOONSHOT_AI_API_KEY unset - Moonshot auth may fail at inference time');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await agentHandler.start();\n} catch (e) {\n  if (/Moonshot AI model must be set/.test(e.message)) {\n    return respondConfigError('moonshotai', ['MOONSHOT_AI_MODEL_PREF', 'MOONSHOT_AI_API_KEY']);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["agents","llm-provider","moonshotai","model-config","environment-variables","config"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}