{"record":{"id":"9136c828aae889dd","repo":"Mintplex-Labs/anything-llm","slug":"no-z-ai-api-key-was-set","errorCode":null,"errorMessage":"No Z.AI API key was set.","messagePattern":"No Z\\.AI API key was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/zai/index.js","lineNumber":13,"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 ZAiLLM {\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.ZAI_API_KEY) throw new Error(\"No Z.AI API key was set.\");\n    this.className = \"ZAiLLM\";\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n\n    this.openai = new OpenAIApi({\n      baseURL: \"https://api.z.ai/api/paas/v4\",\n      apiKey: process.env.ZAI_API_KEY,\n    });\n    this.model = modelPreference || process.env.ZAI_MODEL_PREF || \"glm-4.5\";\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();\n    this.defaultTemp = 0.7;\n    this.log(\n      `Initialized ${this.model} with context window ${this.promptWindowLimit()}`","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/a145d4d87d086bdb31d50f9bf9cd9c46d311780c/server/utils/AiProviders/zai/index.js#L1-L31","documentation":"Configuration guard thrown by the ZAiLLM constructor: the Z.AI provider was selected but the ZAI_API_KEY environment variable is empty/unset, so requests to api.z.ai cannot be authenticated and the client refuses to construct.","triggerScenarios":"Thrown at provider construction when no Z.AI API key is configured.","commonSituations":"Z.AI selected as LLM provider without an API key.","solutions":["Set the Z.AI API key in provider settings or env."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a145d4d87d086bdb31d50f9bf9cd9c46d311780c","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}