{"record":{"id":"83cd3cb2c036bc25","repo":"Mintplex-Labs/anything-llm","slug":"e-message-83cd3c","errorCode":null,"errorMessage":"${e.message}","messagePattern":"\\$\\{e\\.message\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/cerebras/index.js","lineNumber":210,"sourceCode":"   */\n  #parseReasoningFromResponse({ message }) {\n    let textResponse = message?.content ?? \"\";\n    if (!!message?.reasoning && message.reasoning.trim().length > 0)\n      textResponse = `<think>${message.reasoning}</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        })\n        .catch((e) => {\n          console.error(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 /\n          result.output.time_info.completion_time,","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/cerebras/index.js#L192-L228","documentation":"Re-throws the raw `e.message` from the OpenAI SDK's `chat.completions.create` rejection inside CerebrasLLM.getChatCompletion. The SDK call goes to https://api.cerebras.ai/v1/chat/completions; on rejection the .catch console.errors and throws a fresh Error with just the message. parseReasoningFromResponse is never reached.","triggerScenarios":"Calling getChatCompletion and the Cerebras API rejects: 401 invalid key, 429 rate limit, 400 unsupported model or bad temperature, 404 unknown model id, or a transport-level error (timeout/reset).","commonSituations":"Key expired or rotated; selected a model not enabled for the account; rate-limited; passed an unsupported parameter; network blip; Cerebras API briefly unavailable.","solutions":["Inspect e.message (console.error'd) for the Cerebras status text and fix the named cause.","On 401, update CEREBRAS_API_KEY in .env and restart.","On 429, reduce concurrency / add backoff; on 400 verify the model supports the params.","On transport errors, retry once with backoff, then surface to the user."],"exampleFix":"// before\n.catch((e) => {\n  console.error(e);\n  throw new Error(e.message);\n})\n\n// after - preserve status/retryability\n.catch((e) => {\n  console.error(e);\n  const err = new Error(e.message);\n  err.status = e.status ?? e.response?.status;\n  throw err;\n})","handlingStrategy":"try-catch","validationCode":"// Cheap pre-flight checks\nif (!this.model) throw new Error(\"No Cerebras model selected.\");\nif (!Array.isArray(messages) || messages.length === 0)\n  throw new Error(\"Messages must be a non-empty array.\");","typeGuard":"/** @param {unknown} e @returns {boolean} */\nfunction isOpenAiCompatError(e) {\n  return e != null && typeof e === \"object\" &&\n    typeof e.message === \"string\" &&\n    (typeof e.status === \"number\" || typeof e.response?.status === \"number\");\n}","tryCatchPattern":"try {\n  const res = await llm.getChatCompletion(messages, { temperature });\n} catch (e) {\n  const status = e.status ?? e.response?.status;\n  if (status === 401) await refreshCerebrasKey();\n  else if (status === 429) await backoffRetry(fn);\n  else if (status >= 500) await backoffRetry(fn);\n  else throw e;\n}","preventionTips":["Preserve the upstream status code on rethrow, not just the message.","Branch recovery on status (401/429/5xx) instead of generic handling.","Add bounded retries for transient (429/5xx/transport) failures only.","Log the full SDK error once at the boundary for diagnostics."],"tags":["network","api","cerebras","try-catch","runtime"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}