{"record":{"id":"f73c48ae47b4b127","repo":"Mintplex-Labs/anything-llm","slug":"genericopenai-must-have-a-valid-base-path-to-use-f","errorCode":null,"errorMessage":"GenericOpenAI must have a valid base path to use for the api.","messagePattern":"GenericOpenAI must have a valid base path to use for the api\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/genericOpenAi/index.js","lineNumber":21,"sourceCode":"const {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\nconst {\n  formatChatHistory,\n  writeResponseChunk,\n  clientAbortedHandler,\n  extractReasoningContent,\n} = require(\"../../helpers/chat/responses\");\nconst { v4: uuidv4 } = require(\"uuid\");\nconst { toValidNumber } = require(\"../../http\");\nconst { getAnythingLLMUserAgent } = require(\"../../../endpoints/utils\");\nconst { attachmentToContentBlock } = require(\"../../helpers/attachments\");\n\nclass GenericOpenAiLLM {\n  constructor(embedder = null, modelPreference = null) {\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    if (!process.env.GENERIC_OPEN_AI_BASE_PATH)\n      throw new Error(\n        \"GenericOpenAI must have a valid base path to use for the api.\"\n      );\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;","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/genericOpenAi/index.js#L3-L39","documentation":"The GenericOpenAiLLM constructor throws when GENERIC_OPEN_AI_BASE_PATH is unset. This provider is the 'OpenAI-compatible' connector for arbitrary endpoints (LM Studio, Ollama's compat layer, vLLM, OpenRouter, etc.), and the base path is the one mandatory setting — the API key (GENERIC_OPEN_AI_API_KEY) is optional and defaults to null. The constructor also attaches a custom User-Agent and parsed custom headers to every request.","triggerScenarios":"Selecting the 'Generic OpenAI' provider without setting GENERIC_OPEN_AI_BASE_PATH, e.g. intending http://localhost:1234/v1 (LM Studio), http://localhost:11434/v1 (Ollama), or a hosted compat URL. Any chat request instantiates the class and fails here.","commonSituations":"User assumed the provider defaults to api.openai.com (it does not — use the dedicated OpenAI provider for that); forgot /v1 suffix so later requests 404; base path set under a misspelled var name; local service not running when the path was configured.","solutions":["Set GENERIC_OPEN_AI_BASE_PATH to your endpoint including the version segment, e.g. http://localhost:1234/v1, and restart","If the endpoint needs auth, also set GENERIC_OPEN_AI_API_KEY","Verify the target service is up: curl http://localhost:1234/v1/models","For the real OpenAI API, use the native OpenAI provider instead of the generic one"],"exampleFix":"# before (.env)\n# GENERIC_OPEN_AI_BASE_PATH unset\n\n# after (.env)\nGENERIC_OPEN_AI_BASE_PATH=http://localhost:1234/v1\nGENERIC_OPEN_AI_API_KEY=sk-...   # optional","handlingStrategy":"validation","validationCode":"if (!process.env.GENERIC_OPEN_AI_BASE_PATH) {\n  return setupError(\"Generic OpenAI needs GENERIC_OPEN_AI_BASE_PATH (e.g. http://localhost:1234/v1).\");\n}\nconst llm = new GenericOpenAiLLM(embedder, modelPref);","typeGuard":null,"tryCatchPattern":"try {\n  const llm = new GenericOpenAiLLM(embedder, modelPref);\n} catch (err) {\n  if (/must have a valid base path/.test(err.message)) {\n    return respond(\"Set GENERIC_OPEN_AI_BASE_PATH in settings first.\");\n  }\n  throw err;\n}","preventionTips":["Health-check the base path with a /models request when the user saves provider settings","Always include the version segment (/v1) in the configured URL","For real OpenAI, use the dedicated OpenAI provider instead of the generic one"],"tags":["generic-openai","missing-env-var","constructor","openai-compat"],"backgroundTag":"missing-env-var","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"}