{"record":{"id":"f8727e0e5df1c74e","repo":"Mintplex-Labs/anything-llm","slug":"e-message-f8727e","errorCode":null,"errorMessage":"${e.message}","messagePattern":"\\$\\{e\\.message\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/ppio/index.js","lineNumber":162,"sourceCode":"    };\n    return [prompt, ...chatHistory, { role: \"user\", content: userPrompt }];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `PPIO chat: ${this.model} is not valid for chat completion!`\n      );\n\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      !Object.prototype.hasOwnProperty.call(result.output, \"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: result.output.usage.completion_tokens / result.duration,\n        duration: result.duration,\n        model: this.model,","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/ppio/index.js#L144-L180","documentation":"Re-thrown from the OpenAI SDK rejection inside PPIOLLM.getChatCompletion via `.catch((e) => { throw new Error(e.message); })`. The wrapper discards the SDK error class and HTTP status, leaving only the message string, so a 401, 429, and a 500 look identical to the caller except for wording.","triggerScenarios":"PPIO's endpoint returns non-2xx or the client throws pre-response: 401 invalid key, 403 forbidden, 404 model not found server-side, 429 rate/quota, 5xx, or a transport error (DNS, TLS, abort).","commonSituations":"PPIO_API_KEY was correct at startup but later deactivated; burst traffic tripped the per-minute rate limit; requesting a model the key's plan excludes; cold-start timeout against ppinfra.com; client aborted the request while streaming.","solutions":["Match the message: '401'/'Unauthorized' -> key issue; '429'/'rate' -> throttle; 'model'/'not found' -> model id issue; 'timeout'/'ECONN' -> network.","curl the same payload to https://api.ppintra.com/v3/openai/chat/completions to isolate auth vs model vs quota.","Check the PPIO console for quota/usage.","For transient errors, wrap the call in bounded exponential-backoff retry."],"exampleFix":"// before\nconst out = await llm.getChatCompletion(messages, { temperature: 0.7 });\n\n// after\ntry {\n  const out = await llm.getChatCompletion(messages, { temperature: 0.7 });\n} catch (err) {\n  if (/401|unauthorized/i.test(err.message)) throw new Error(\"PPIO key invalid — reconfigure\", { cause: err });\n  if (/429|rate/i.test(err.message)) throw new Error(\"PPIO rate limited — back off\", { cause: err });\n  throw err;\n}","handlingStrategy":"retry","validationCode":"function classifyPpioError(message) {\n  if (/401|unauthorized|invalid api key/i.test(message)) return \"auth\";\n  if (/429|rate limit|quota/i.test(message)) return \"rate\";\n  if (/5\\d{2}|timeout|ECONN/i.test(message)) return \"transient\";\n  return \"fatal\";\n}","typeGuard":"function isTransientPpioError(message) {\n  return typeof message === \"string\" && /429|5\\d{2}|timeout|ECONNRESET|fetch failed/i.test(message);\n}","tryCatchPattern":"async function ppioCall(llm, messages, opts, retries = 3) {\n  for (let i = 0; i <= retries; i++) {\n    try {\n      return await llm.getChatCompletion(messages, opts);\n    } catch (e) {\n      if (/401|not valid for chat/i.test(e.message) || i === retries) throw e;\n      await new Promise((r) => setTimeout(r, 2 ** i * 500));\n    }\n  }\n}","preventionTips":["Throw `new Error(e.message, { cause: e })` to preserve the SDK status code for diagnosis.","Classify errors so auth failures are not retried.","Set per-provider rate budgets to avoid 429s on PPIO's free tier.","curl the endpoint directly when an ambiguous message appears to confirm auth/quota."],"tags":["runtime","api-error","llm-provider","ppio","network","error-wrapping"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}