{"record":{"id":"327f9f47a58cb530","repo":"Mintplex-Labs/anything-llm","slug":"e-message-327f9f","errorCode":null,"errorMessage":"${e.message}","messagePattern":"\\$\\{e\\.message\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/zai/index.js","lineNumber":121,"sourceCode":"      prompt,\n      ...chatHistory,\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\n      },\n    ];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature,\n        })\n        .catch((e) => {\n          throw new Error(e.message);\n        })\n    );\n\n    if (\n      !result.output.hasOwnProperty(\"choices\") ||\n      result.output.choices.length === 0\n    )\n      return null;\n\n    return {\n      textResponse: result.output.choices[0].message.content,\n      metrics: {\n        prompt_tokens: result.output.usage?.prompt_tokens || 0,\n        completion_tokens: result.output.usage?.completion_tokens || 0,\n        total_tokens: result.output.usage?.total_tokens || 0,\n        outputTps: result.output.usage?.completion_tokens / result.duration,\n        duration: result.duration,\n        model: this.model,","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/zai/index.js#L103-L139","documentation":"Re-thrown from the .catch on this.openai.chat.completions.create inside ZAiLLM.getChatCompletion. Z.AI does not pre-validate the model in getChatCompletion (no isValidChatCompletionModel guard here), so the request is sent directly to https://api.z.ai/api/paas/v4 and any rejection is flattened to a new Error carrying only e.message, discarding status/type/stack.","triggerScenarios":"401 invalid ZAI_API_KEY; 404 unknown ZAI_MODEL_PREF; 429 rate limit; 400 from unsupported message format or context exceeding the model window; 5xx from the Z.AI PaaS; network errors.","commonSituations":"Setting ZAI_MODEL_PREF to a model not enabled for the account; exceeding GLM token limits; revoked key after rotation; intermittent upstream outages; sending tool/function payloads the model rejects.","solutions":["Inspect e.message to classify: auth -> rotate ZAI_API_KEY; model_not_found -> fix ZAI_MODEL_PREF; rate/context -> reduce input or back off.","Wrap the call in try/catch and branch on message substrings since the structured error is lost.","For richer handling, call this.openai.chat.completions.create directly and inspect e.status/e.error before rethrowing.","Retry idempotent reads on transient 5xx/429 with exponential backoff."],"exampleFix":"// before\n.catch((e) => { throw new Error(e.message); })\n\n// after\n.catch((e) => {\n  const err = new Error(e.message);\n  err.status = e.status;\n  err.upstream = \"zai\";\n  err.cause = e;\n  throw err;\n})","handlingStrategy":"try-catch","validationCode":"// Z.AI does not validate the model in getChatCompletion — pre-flight auth/endpoint:\ntry {\n  await llm.openai.models.list();\n} catch (e) {\n  throw new Error(`Z.AI preflight failed: ${e.message}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await llm.getChatCompletion(messages, { temperature });\n} catch (e) {\n  const msg = e.message;\n  if (/401|unauthorized|api.key/i.test(msg)) handleAuth();\n  else if (/model_not_found|404/i.test(msg)) handleBadModel();\n  else if (/rate.limit|429|quota/i.test(msg)) backoff();\n  else throw e;\n}","preventionTips":["Z.AI sends the request without a local model check — validate ZAI_MODEL_PREF against the account's enabled models yourself.","Classify failures by message substring (status/type is lost by the .catch wrapper).","Pre-flight openai.models.list() to catch auth/endpoint errors early."],"tags":["zai","zhipu","glm","error-wrapping","network","auth"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}