{"record":{"id":"06768bc7643dcdbb","repo":"Mintplex-Labs/anything-llm","slug":"koboldcpp-must-have-a-valid-model-set","errorCode":null,"errorMessage":"KoboldCPP must have a valid model set.","messagePattern":"KoboldCPP must have a valid model set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/koboldCPP/index.js","lineNumber":27,"sourceCode":"\nclass KoboldCPPLLM {\n  static contextWindowSize = null;\n\n  constructor(embedder = null, modelPreference = null) {\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    if (!process.env.KOBOLD_CPP_BASE_PATH)\n      throw new Error(\n        \"KoboldCPP must have a valid base path to use for the api.\"\n      );\n\n    this.className = \"KoboldCPPLLM\";\n    this.basePath = process.env.KOBOLD_CPP_BASE_PATH;\n    this.openai = new OpenAIApi({\n      baseURL: this.basePath,\n      apiKey: null,\n    });\n    this.model = modelPreference ?? process.env.KOBOLD_CPP_MODEL_PREF ?? null;\n    if (!this.model) throw new Error(\"KoboldCPP must have a valid model set.\");\n\n    this.embedder = embedder ?? new NativeEmbedder();\n    this.defaultTemp = 0.7;\n    this.maxTokens = process.env.KOBOLD_CPP_MAX_TOKENS\n      ? Number(process.env.KOBOLD_CPP_MAX_TOKENS)\n      : null;\n\n    this.limits = null;\n    KoboldCPPLLM.cacheContextWindow();\n    this.log(\n      `Inference API: ${this.basePath} Model: ${this.model} Context Window: ${this.promptWindowLimit()}`\n    );\n  }\n\n  log(text, ...args) {\n    console.log(`\\x1b[36m[${this.className}]\\x1b[0m ${text}`, ...args);\n  }\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/koboldCPP/index.js#L9-L45","documentation":"KoboldCPPLLM requires an explicit model id: this.model = modelPreference ?? KOBOLD_CPP_MODEL_PREF ?? null, and the constructor throws if that chain yields null. KoboldCPP's OpenAI-compatible API needs a concrete model tag in every request, and — unlike the LMStudio provider — there is no 'fetch from /models' fallback here, so the value must come from the caller or env.","triggerScenarios":"Constructing KoboldCPPLLM with modelPreference null/undefined while KOBOLD_CPP_MODEL_PREF is unset. Note the ?? (nullish) operator: an empty-string modelPreference does NOT fall through to env, so passing \"\" programmatically (e.g., from a workspace config field left blank) also produces this throw.","commonSituations":"KOBOLD_CPP_BASE_PATH set but the model pref line forgotten; a workspace-level model selection stored as empty string; copying env templates for LiteLLM/Ollama and missing the Kobold-specific variable name; using a model tag that exists in the UI but not exposing it via the API's model list.","solutions":["Set KOBOLD_CPP_MODEL_PREF to the exact model tag KoboldCPP loaded (visible in its UI or via curl http://<base>/v1/models).","If constructing programmatically, pass a non-empty modelPreference: new KoboldCPPLLM(embedder, \"koboldcpp/default\").","Avoid empty-string values: because ?? is nullish, treat \"\" as null in calling code before passing it.","Restart the server after editing .env."],"exampleFix":"// before — empty string defeats the ?? fallback\nnew KoboldCPPLLM(embedder, \"\");\n\n// after\nnew KoboldCPPLLM(embedder, \"koboldcpp/default\");\n// or .env: KOBOLD_CPP_MODEL_PREF=koboldcpp/default","handlingStrategy":"validation","validationCode":"// ?? does NOT treat \"\" as missing — normalize first\nconst modelPref = modelPreference || process.env.KOBOLD_CPP_MODEL_PREF || null;\nif (!modelPref) throw new Error(\"KoboldCPP model required\");\nconst llm = new KoboldCPPLLM(embedder, modelPref);","typeGuard":"function hasKoboldModel(pref, env) {\n  const m = pref ?? env ?? null;\n  return typeof m === \"string\" && m.trim().length > 0;\n}","tryCatchPattern":"try {\n  new KoboldCPPLLM(embedder, rawPref);\n} catch (e) {\n  if (/valid model set/i.test(e.message)) throw new Error(\"Set KOBOLD_CPP_MODEL_PREF to a tag from /v1/models\");\n  throw e;\n}","preventionTips":["Normalize empty strings to null before passing modelPreference — ?? only catches null/undefined.","Fetch http://<base>/v1/models once at startup and validate the configured tag against it.","Store the model tag beside the base path in .env so the pair is never half-configured."],"tags":["koboldcpp","anythingllm","model-selection","env-var","nullish-coalescing","configuration"],"backgroundTag":"model-not-configured","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-09-22T02:13:38.154Z","contentChangedAt":"2026-09-22T02:13:38.154Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}