{"record":{"id":"ff336ddc416c4a87","repo":"Mintplex-Labs/anything-llm","slug":"e-message-index","errorCode":null,"errorMessage":"${e.message}","messagePattern":"\\$\\{e\\.message\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/koboldCPP/index.js","lineNumber":180,"sourceCode":"    if (\n      !!message?.reasoning_content &&\n      message.reasoning_content.trim().length > 0\n    )\n      textResponse = `<think>${message.reasoning_content}</think>${textResponse}`;\n    return textResponse;\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature,\n          ...(this.maxTokens ? { max_tokens: this.maxTokens } : {}),\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\n    )\n      return null;\n\n    return {\n      textResponse: this.#parseReasoningFromResponse(result.output.choices[0]),\n      metrics: {\n        prompt_tokens: result.output.usage?.prompt_tokens || 0,\n        completion_tokens: result.output.usage?.completion_tokens || 0,\n        total_tokens: result.output.usage?.total_tokens || 0,\n        outputTps:\n          (result.output.usage?.completion_tokens || 0) / result.duration,\n        duration: result.duration,","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/koboldCPP/index.js#L162-L198","documentation":"KoboldCPP's chat completion wrapper re-throws any error from the underlying HTTP client (OpenAI SDK pointed at the KoboldCPP endpoint) while calling the /v1/chat/completions route. The message is the raw client error, so it can be a network failure, a non-JSON response, or an API error like an invalid model. After the call, the code also expects result.output.choices to exist; a malformed provider response surfaces here first as this thrown error.","triggerScenarios":"Calling getChatCompletion when the KoboldCPP server is unreachable, returns a non-200 or non-JSON response, rejects the model name, or the request payload (temperature/max_tokens) is rejected by the backend.","commonSituations":"KoboldCPP not running or wrong KoboldCPP base URL configured; model loaded in KoboldCPP does not match the configured model; KoboldCPP version whose OpenAI-compatible API differs (older builds lacking /v1 routes); reverse proxy returning HTML error pages the SDK cannot parse.","solutions":["Verify KoboldCPP is running and its base URL (e.g. http://127.0.0.1:5001/v1) is correct in the AI provider settings.","Check that the configured model matches a model actually loaded in KoboldCPP.","Curl the endpoint manually (curl http://host:5001/v1/chat/completions) to see the raw error/response.","Upgrade KoboldCPP if its OpenAI-compatible API is missing or outdated.","Inspect the wrapped e.message in the logs for the root cause (ECONNREFUSED vs 404 vs parse error)."],"exampleFix":"// before\n.catch((e) => {\n  throw new Error(e.message);\n})\n// after\n.catch((e) => {\n  throw new Error(`KoboldCPP::getChatCompletion failed: ${e.message}`);\n})","handlingStrategy":"try-catch","validationCode":"// health check before calling\nconst res = await fetch(`${koboldBaseURL}/v1/models`);\nif (!res.ok) throw new Error(`KoboldCPP unreachable: ${res.status}`);","typeGuard":"function hasChoices(output) {\n  return output && typeof output === 'object' &&\n    Array.isArray(output.choices) && output.choices.length > 0;\n}","tryCatchPattern":"try {\n  const text = await provider.getChatCompletion(messages);\n} catch (e) {\n  if (/ECONNREFUSED|fetch failed/i.test(e.message)) {\n    // provider offline: check KoboldCPP server/base URL\n  } else if (/40[13]|model/i.test(e.message)) {\n    // wrong model or auth: verify loaded model\n  } else {\n    throw e; // unknown: surface to user\n  }\n}","preventionTips":["Health-check the KoboldCPP endpoint at startup and before long jobs.","Keep the configured model name in sync with the model loaded in KoboldCPP.","Pin and test your KoboldCPP version against its OpenAI-compatible API.","Log the underlying client error, not just the re-thrown message."],"tags":["network","llm","http","provider"],"backgroundTag":"api-request-failed","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"}