{"record":{"id":"7855e8773127e57b","repo":"Mintplex-Labs/anything-llm","slug":"xai-chat-this-model-is-not-valid-for-chat-comp","errorCode":null,"errorMessage":"xAI chat: ${this.model} is not valid for chat completion!","messagePattern":"xAI chat: (.+?) is not valid for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/xai/index.js","lineNumber":120,"sourceCode":"    attachments = [], // This is the specific attachment for only this prompt\n  }) {\n    const prompt = {\n      role: \"system\",\n      content: `${systemPrompt}${this.#appendContext(contextTexts)}`,\n    };\n    return [\n      prompt,\n      ...formatChatHistory(chatHistory, this.#generateContent),\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\n      },\n    ];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!this.isValidChatCompletionModel(this.model))\n      throw new Error(\n        `xAI chat: ${this.model} is not valid for chat completion!`\n      );\n\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","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/xai/index.js#L102-L138","documentation":"Sentinel guard in getChatCompletion: this.model failed isValidChatCompletionModel, meaning the configured xAI model identifier is not in the list of models known to support chat completions (e.g. an embedding-only or misspelled model name was selected).","triggerScenarios":"Thrown when the configured xAI model is not a chat model.","commonSituations":"Model preference set to an invalid model.","solutions":["Select an xAI model valid for chat completion."],"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"}