Mintplex-Labs/anything-llm · error · Error
GenericOpenAI must have a valid base path to use for the…
Error message
GenericOpenAI must have a valid base path to use for the api.
What it means
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.
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
Example fix
# before (.env) # GENERIC_OPEN_AI_BASE_PATH unset # after (.env) GENERIC_OPEN_AI_BASE_PATH=http://localhost:1234/v1 GENERIC_OPEN_AI_API_KEY=sk-... # optional
Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.GENERIC_OPEN_AI_BASE_PATH) {
return setupError("Generic OpenAI needs GENERIC_OPEN_AI_BASE_PATH (e.g. http://localhost:1234/v1).");
}
const llm = new GenericOpenAiLLM(embedder, modelPref); Try / catch
try {
const llm = new GenericOpenAiLLM(embedder, modelPref);
} catch (err) {
if (/must have a valid base path/.test(err.message)) {
return respond("Set GENERIC_OPEN_AI_BASE_PATH in settings first.");
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- e.message
- GenericOpenAI must have a valid base path to use for the…
- No FireworksAI API key was set.
- No Foundry Base Path was set.
- No Gemini API key was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/f73c48ae47b4b127.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/genericOpenAi/index.js:21
const {
LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");
const {
formatChatHistory,
writeResponseChunk,
clientAbortedHandler,
extractReasoningContent,
} = require("../../helpers/chat/responses");
const { v4: uuidv4 } = require("uuid");
const { toValidNumber } = require("../../http");
const { getAnythingLLMUserAgent } = require("../../../endpoints/utils");
const { attachmentToContentBlock } = require("../../helpers/attachments");
class GenericOpenAiLLM {
constructor(embedder = null, modelPreference = null) {
const { OpenAI: OpenAIApi } = require("openai");
if (!process.env.GENERIC_OPEN_AI_BASE_PATH)
throw new Error(
"GenericOpenAI must have a valid base path to use for the api."
);
this.className = "GenericOpenAiLLM";
this.basePath = process.env.GENERIC_OPEN_AI_BASE_PATH;
this.openai = new OpenAIApi({
baseURL: this.basePath,
apiKey: process.env.GENERIC_OPEN_AI_API_KEY ?? null,
defaultHeaders: {
"User-Agent": getAnythingLLMUserAgent(),
...GenericOpenAiLLM.parseCustomHeaders(),
},
});
this.model =
modelPreference ?? process.env.GENERIC_OPEN_AI_MODEL_PREF ?? null;
this.maxTokens = process.env.GENERIC_OPEN_AI_MAX_TOKENS
? toValidNumber(process.env.GENERIC_OPEN_AI_MAX_TOKENS, 1024)
: 1024;View on GitHub (pinned to 3aec848f28)