{"record":{"id":"8ab6312ac794389b","repo":"Mintplex-Labs/anything-llm","slug":"genericopenai-must-have-a-valid-model-set","errorCode":null,"errorMessage":"GenericOpenAI must have a valid model set.","messagePattern":"GenericOpenAI must have a valid model set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/genericOpenAi/index.js","lineNumber":41,"sourceCode":"      );\n\n    this.className = \"GenericOpenAiLLM\";\n    this.basePath = process.env.GENERIC_OPEN_AI_BASE_PATH;\n    this.openai = new OpenAIApi({\n      baseURL: this.basePath,\n      apiKey: process.env.GENERIC_OPEN_AI_API_KEY ?? null,\n      defaultHeaders: {\n        \"User-Agent\": getAnythingLLMUserAgent(),\n        ...GenericOpenAiLLM.parseCustomHeaders(),\n      },\n    });\n    this.model =\n      modelPreference ?? process.env.GENERIC_OPEN_AI_MODEL_PREF ?? null;\n    this.maxTokens = process.env.GENERIC_OPEN_AI_MAX_TOKENS\n      ? toValidNumber(process.env.GENERIC_OPEN_AI_MAX_TOKENS, 1024)\n      : 1024;\n    if (!this.model)\n      throw new Error(\"GenericOpenAI must have a valid model set.\");\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(`Inference API: ${this.basePath} Model: ${this.model}`);\n  }\n\n  log(text, ...args) {\n    console.log(`\\x1b[36m[${this.className}]\\x1b[0m ${text}`, ...args);\n  }\n\n  /**\n   * Parses custom headers from a CSV-formatted environment variable.\n   * Format: \"Header-Name:value,Another-Header:value2\"","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/genericOpenAi/index.js#L23-L59","documentation":"Thrown after the constructor resolves this.model from modelPreference ?? process.env.GENERIC_OPEN_AI_MODEL_PREF ?? null. If all three are nullish, this.model is null and the constructor aborts. Unlike the base path, a default cannot be invented because Generic OpenAI has no idea what models the arbitrary endpoint serves.","triggerScenarios":"Constructing GenericOpenAiLLM with no modelPreference while GENERIC_OPEN_AI_MODEL_PREF is also unset. The provider must be told which model id the target endpoint expects.","commonSituations":"User set the base path but forgot the model id; the endpoint serves models under different names than expected; copying a config template that omitted the model pref line.","solutions":["Query the endpoint's model list (curl $BASE_PATH/models) and set GENERIC_OPEN_AI_MODEL_PREF to a returned id","Pass modelPreference explicitly when constructing from code","Fill the model field in the Generic OpenAI provider UI","Restart the server after updating .env"],"exampleFix":"// before\n// .env: GENERIC_OPEN_AI_BASE_PATH=http://localhost:1234/v1  // no model\n\n// after\n// .env:\n//   GENERIC_OPEN_AI_BASE_PATH=http://localhost:1234/v1\n//   GENERIC_OPEN_AI_MODEL_PREF=llama-3.1-8b-instruct","handlingStrategy":"validation","validationCode":"const model = modelPreference ?? process.env.GENERIC_OPEN_AI_MODEL_PREF;\nif (!model) {\n  throw new ConfigError('GenericOpenAI needs GENERIC_OPEN_AI_MODEL_PREF.');\n}\n// optionally cross-check against GET $BASE_PATH/models","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fetch the endpoint's /models list and let the user pick from it in the UI","Persist the chosen model id alongside the base path so neither is forgotten","Validate model presence before construction"],"tags":["generic-openai","configuration","model-selection","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}