{"record":{"id":"39c1df17b138f45f","repo":"Mintplex-Labs/anything-llm","slug":"e-message-39c1df","errorCode":null,"errorMessage":"e.message","messagePattern":"e\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/liteLLM/index.js","lineNumber":137,"sourceCode":"      prompt,\n      ...formatChatHistory(chatHistory, this.#generateContent),\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\n      },\n    ];\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        })\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: result.output.choices[0].message.content,\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":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/liteLLM/index.js#L119-L155","documentation":"A catch-and-rethrow wrapper around the OpenAI SDK call in LiteLLM's getChatCompletion. The `.catch((e) => { throw new Error(e.message); })` discards the original SDK error's type, HTTP status, and cause, preserving only the message text. Any failure from the LiteLLM proxy (network, auth, upstream backend failure, rate limit) surfaces here.","triggerScenarios":"Calling `litellmProvider.getChatCompletion(messages, { temperature })` when the LiteLLM proxy returns an error. This includes: proxy unreachable, invalid API key (LITE_LLM_API_KEY), upstream model failure (e.g. the backend provider returns an error through LiteLLM), rate limiting, or a malformed model name that LiteLLM cannot route.","commonSituations":"The LiteLLM proxy is down or restarted. The upstream API key configured in LiteLLM expired or hit its quota. The model name in LITE_LLM_MODEL_PREF doesn't match any route configured in the LiteLLM proxy's config.yaml. Network issues between AnythingLLM and the proxy.","solutions":["Check the error message text for status codes or upstream provider details (e.g. '401 Unauthorized', 'model not found').","Verify the LiteLLM proxy is running and its config.yaml routes the requested model.","Check LITE_LLM_API_KEY is correct if the proxy requires authentication.","Look at the LiteLLM proxy logs for the upstream error, since AnythingLLM only shows the re-wrapped message.","Refactor the catch to preserve the original error if structured error handling is needed upstream."],"exampleFix":"// before — structured error data lost\n.catch((e) => {\n  throw new Error(e.message);\n})\n\n// after — preserve original error\n.catch((e) => {\n  throw e;\n})","handlingStrategy":"try-catch","validationCode":"async function checkLiteLLMHealth(basePath, apiKey) {\n  const headers = apiKey ? { Authorization: `Bearer ${apiKey}` } : {};\n  const res = await fetch(`${basePath}/v1/models`, { headers });\n  if (!res.ok) throw new Error(`LiteLLM proxy at ${basePath} returned ${res.status}`);\n  return true;\n}\n\nawait checkLiteLLMHealth(process.env.LITE_LLM_BASE_PATH, process.env.LITE_LLM_API_KEY);","typeGuard":null,"tryCatchPattern":"try {\n  const result = await litellmProvider.getChatCompletion(messages, { temperature: 0.7 });\n} catch (e) {\n  // The wrapper preserves only e.message from the SDK error.\n  if (e.message.includes('ECONNREFUSED') || e.message.includes('fetch failed')) {\n    console.error('LiteLLM proxy unreachable at', process.env.LITE_LLM_BASE_PATH);\n  } else if (e.message.includes('401') || e.message.includes('Unauthorized')) {\n    console.error('LiteLLM API key invalid — check LITE_LLM_API_KEY.');\n  } else {\n    console.error('LiteLLM chat failed:', e.message);\n    // Check LiteLLM proxy logs for upstream provider errors.\n  }\n}","preventionTips":["Implement a health check that queries the LiteLLM proxy's /v1/models endpoint before chat requests.","Monitor the LiteLLM proxy's own logs for upstream provider failures.","Consider refactoring the catch to preserve the original SDK error for better error classification upstream."],"tags":["litellm","api-error","openai-sdk","error-wrapping","runtime"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}