{"record":{"id":"95fcad62541b2350","repo":"Mintplex-Labs/anything-llm","slug":"no-xai-api-key-was-set","errorCode":null,"errorMessage":"No xAI API key was set.","messagePattern":"No xAI API key was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/xai/index.js","lineNumber":14,"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 XAiLLM {\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.XAI_LLM_API_KEY)\n      throw new Error(\"No xAI API key was set.\");\n    this.className = \"XAiLLM\";\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n\n    this.openai = new OpenAIApi({\n      baseURL: \"https://api.x.ai/v1\",\n      apiKey: process.env.XAI_LLM_API_KEY,\n    });\n    this.model =\n      modelPreference || process.env.XAI_LLM_MODEL_PREF || \"grok-beta\";\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(","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/xai/index.js#L1-L32","documentation":"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.","triggerScenarios":"Thrown at provider construction when no xAI API key is configured.","commonSituations":"xAI selected as LLM provider without an API key.","solutions":["Set the xAI API key in provider settings or env."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}