Mintplex-Labs/anything-llm · error · Error

No Z.AI API key was set.

Error message

No Z.AI API key was set.

What it means

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.

Solutions

  1. Set the Z.AI API key in provider settings or env.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at provider construction when no Z.AI API key is configured.

Common situations: Z.AI selected as LLM provider without an API key.


AI-assisted analysis of Mintplex-Labs/anything-llm@a145d4d87d (2026-08-18). Data as JSON: /api/errors/9136c828aae889dd. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/AiProviders/zai/index.js:13

const { NativeEmbedder } = require("../../EmbeddingEngines/native");
const {
  LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");
const {
  handleDefaultStreamResponseV2,
  formatChatHistory,
} = require("../../helpers/chat/responses");
const { MODEL_MAP } = require("../modelMap");

class ZAiLLM {
  constructor(embedder = null, modelPreference = null) {
    if (!process.env.ZAI_API_KEY) throw new Error("No Z.AI API key was set.");
    this.className = "ZAiLLM";
    const { OpenAI: OpenAIApi } = require("openai");

    this.openai = new OpenAIApi({
      baseURL: "https://api.z.ai/api/paas/v4",
      apiKey: process.env.ZAI_API_KEY,
    });
    this.model = modelPreference || process.env.ZAI_MODEL_PREF || "glm-4.5";
    this.limits = {
      history: this.promptWindowLimit() * 0.15,
      system: this.promptWindowLimit() * 0.15,
      user: this.promptWindowLimit() * 0.7,
    };

    this.embedder = embedder ?? new NativeEmbedder();
    this.defaultTemp = 0.7;
    this.log(
      `Initialized ${this.model} with context window ${this.promptWindowLimit()}`

View on GitHub (pinned to a145d4d87d)