Mintplex-Labs/anything-llm · error · Error

No xAI API key was set.

Error message

No xAI API key was set.

What it means

Configuration guard thrown by the XAiLLM constructor: the xAI (Grok) provider was selected but the XAI_LLM_API_KEY environment variable is empty/unset, so the xAI OpenAI-compatible endpoint cannot be authenticated.

Solutions

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

Strategy: validation

When it happens

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

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


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/95fcad62541b2350. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/AiProviders/xai/index.js:14

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

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

    this.openai = new OpenAIApi({
      baseURL: "https://api.x.ai/v1",
      apiKey: process.env.XAI_LLM_API_KEY,
    });
    this.model =
      modelPreference || process.env.XAI_LLM_MODEL_PREF || "grok-beta";
    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(

View on GitHub (pinned to 3aec848f28)