{"record":{"id":"fc9d4d4d6bc788a6","repo":"Mintplex-Labs/anything-llm","slug":"res-status-res-statustext-params-json-fc9d4d","errorCode":null,"errorMessage":"${res.status} - ${res.statusText}. params: ${JSON.stringify({ auth: this.middleTruncate(process.env.AGENT_PERPLEXITY_API_KEY, 5), q: query })}","messagePattern":"(.+?) - (.+?)\\. params: (.+?)\\)\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/aibitat/plugins/web-browsing.js","lineNumber":1137,"sourceCode":"\n            const { response, error } = await fetch(\n              \"https://api.perplexity.ai/search\",\n              {\n                method: \"POST\",\n                headers: {\n                  \"Content-Type\": \"application/json\",\n                  Authorization: `Bearer ${process.env.AGENT_PERPLEXITY_API_KEY}`,\n                },\n                body: JSON.stringify({\n                  query: query,\n                  max_results: 5,\n                  max_tokens_per_page: 2048,\n                }),\n              }\n            )\n              .then((res) => {\n                if (res.ok) return res.json();\n                throw new Error(\n                  `${res.status} - ${res.statusText}. params: ${JSON.stringify({\n                    auth: this.middleTruncate(\n                      process.env.AGENT_PERPLEXITY_API_KEY,\n                      5\n                    ),\n                    q: query,\n                  })}`\n                );\n              })\n              .then((data) => {\n                return { response: data, error: null };\n              })\n              .catch((e) => {\n                this.super.handlerProps.log(\n                  `Perplexity Search Error: ${e.message}`\n                );\n                return { response: null, error: e.message };\n              });","sourceCodeStart":1119,"sourceCodeEnd":1155,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/aibitat/plugins/web-browsing.js#L1119-L1155","documentation":"Thrown by the Perplexity (Sonar) search provider when a POST to the Perplexity API returns a non-OK status. Authentication uses AGENT_PERPLEXITY_API_KEY as a Bearer token. The request body includes query, max_results, and max_tokens_per_page. The error captures status, statusText, a truncated key, and the query. Unlike other providers, the multi-line formatting makes the error object span more lines.","triggerScenarios":"Perplexity returns 401 (invalid/missing Bearer token), 429 (rate limit — Perplexity enforces per-minute caps by plan), 400 (malformed body — wrong endpoint or unsupported parameters like max_tokens_per_page on a model that doesn't support it), 402 (billing issue), or 5xx.","commonSituations":"AGENT_PERPLEXITY_API_KEY not set; key from a free trial that expired; API credits depleted; using the wrong endpoint (search vs chat vs sonar); Perplexity API schema changed and max_results/max_tokens_per_page are no longer valid parameters.","solutions":["Confirm AGENT_PERPLEXITY_API_KEY is set to a valid key from perplexity.ai settings.","A 401 means the Bearer token is wrong — check the truncated value.","A 429 means the rate limit is exceeded — upgrade the plan or space out requests.","For 400 errors, verify the request body and endpoint match Perplexity's current API documentation — the search endpoint and parameters may have changed."],"exampleFix":"// before\nheaders: { Authorization: `Bearer ${process.env.AGENT_PERPLEXITY_API_KEY}`, ... },\nbody: JSON.stringify({ query, max_results: 5, max_tokens_per_page: 2048 }),\n// throw on non-OK\n\n// caller-side fix\nif (!process.env.AGENT_PERPLEXITY_API_KEY) {\n  return \"AGENT_PERPLEXITY_API_KEY is not configured.\";\n}","handlingStrategy":"validation","validationCode":"if (!process.env.AGENT_PERPLEXITY_API_KEY) {\n  throw new Error(\"AGENT_PERPLEXITY_API_KEY is not set. Configure it to use Perplexity search.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  const results = await perplexitySearch(query);\n  return results;\n} catch (e) {\n  if (e.message.startsWith(\"401\")) {\n    return \"Perplexity API key invalid. Check AGENT_PERPLEXITY_API_KEY.\";\n  }\n  if (e.message.startsWith(\"429\")) {\n    await new Promise(r => setTimeout(r, 5000));\n    return await perplexitySearch(query);\n  }\n  if (e.message.startsWith(\"400\")) {\n    // API schema mismatch — check Perplexity docs for current parameters\n    return \"Perplexity API rejected the request. The endpoint or parameters may have changed.\";\n  }\n  throw e;\n}","preventionTips":["Verify AGENT_PERPLEXITY_API_KEY is set and the account has active credits.","Check Perplexity's current API documentation for endpoint and parameter changes.","Handle 429 with backoff — Perplexity enforces strict per-minute limits.","Distinguish 400 (schema error) from 401 (auth) for correct remediation."],"tags":["perplexity","web-search","http","api-key","rate-limit","agent-tool"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}