Mintplex-Labs/anything-llm · error · Error
${res.status} - ${res.statusText}. params: ${JSON.stringify(
Error message
${res.status} - ${res.statusText}. params: ${JSON.stringify({ auth: this.middleTruncate(process.env.AGENT_PERPLEXITY_API_KEY, 5), q: query })} What it means
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.
Source
Thrown at server/utils/agents/aibitat/plugins/web-browsing.js:1137
const { response, error } = await fetch(
"https://api.perplexity.ai/search",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.AGENT_PERPLEXITY_API_KEY}`,
},
body: JSON.stringify({
query: query,
max_results: 5,
max_tokens_per_page: 2048,
}),
}
)
.then((res) => {
if (res.ok) return res.json();
throw new Error(
`${res.status} - ${res.statusText}. params: ${JSON.stringify({
auth: this.middleTruncate(
process.env.AGENT_PERPLEXITY_API_KEY,
5
),
q: query,
})}`
);
})
.then((data) => {
return { response: data, error: null };
})
.catch((e) => {
this.super.handlerProps.log(
`Perplexity Search Error: ${e.message}`
);
return { response: null, error: e.message };
});View on GitHub (pinned to 526360e320)
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.
Example fix
// before
headers: { Authorization: `Bearer ${process.env.AGENT_PERPLEXITY_API_KEY}`, ... },
body: JSON.stringify({ query, max_results: 5, max_tokens_per_page: 2048 }),
// throw on non-OK
// caller-side fix
if (!process.env.AGENT_PERPLEXITY_API_KEY) {
return "AGENT_PERPLEXITY_API_KEY is not configured.";
} Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.AGENT_PERPLEXITY_API_KEY) {
throw new Error("AGENT_PERPLEXITY_API_KEY is not set. Configure it to use Perplexity search.");
} Try / catch
try {
const results = await perplexitySearch(query);
return results;
} catch (e) {
if (e.message.startsWith("401")) {
return "Perplexity API key invalid. Check AGENT_PERPLEXITY_API_KEY.";
}
if (e.message.startsWith("429")) {
await new Promise(r => setTimeout(r, 5000));
return await perplexitySearch(query);
}
if (e.message.startsWith("400")) {
// API schema mismatch — check Perplexity docs for current parameters
return "Perplexity API rejected the request. The endpoint or parameters may have changed.";
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ${res.status} - ${res.statusText}. params: ${JSON.stringify(
- ${res.status} - ${res.statusText}. params: ${JSON.stringify(
- ${res.status} - ${res.statusText}. params: ${JSON.stringify(
- ${res.status} - ${res.statusText}. params: ${JSON.stringify(
- ${res.status} - ${res.statusText}. params: ${JSON.stringify(
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/fc9d4d4d6bc788a6.
Report an issue: GitHub.