{"record":{"id":"43e7b0fa256177c8","repo":"mastra-ai/mastra","slug":"perplexity-search-request-failed-with-status-res","errorCode":null,"errorMessage":"Perplexity Search request failed with status ${response.status}${text ? `: ${text}` : ''}","messagePattern":"Perplexity Search request failed with status (.+?)(.+?)` : ''\\}","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integrations/perplexity/src/client.ts","lineNumber":74,"sourceCode":"  const apiKey = resolveApiKey(options?.apiKey);\n  const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;\n  const fetchImpl = options?.fetch ?? fetch;\n\n  const response = await fetchImpl(`${baseUrl.replace(/\\/$/, '')}/search`, {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n      Authorization: `Bearer ${apiKey}`,\n    },\n    body: JSON.stringify(body),\n  });\n\n  if (!response.ok) {\n    const rawText = await response.text().catch(() => '');\n    const MAX_ERROR_BODY = 1000;\n    const text =\n      rawText.length > MAX_ERROR_BODY ? `${rawText.slice(0, MAX_ERROR_BODY)}…` : rawText;\n    throw new Error(\n      `Perplexity Search request failed with status ${response.status}${text ? `: ${text}` : ''}`,\n    );\n  }\n\n  const json = (await response.json()) as Partial<PerplexitySearchResponse>;\n  return {\n    id: json.id,\n    results: Array.isArray(json.results) ? json.results : [],\n  };\n}\n","sourceCodeStart":56,"sourceCodeEnd":85,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/integrations/perplexity/src/client.ts#L56-L85","documentation":"perplexitySearchRequest performs the HTTP call to the Perplexity Search API; when the response is not ok it reads the response body (truncated to 1000 chars) and throws an error embedding the HTTP status and any error text returned by the server.","triggerScenarios":"Any Perplexity Search request receiving a non-2xx response: 401 invalid/expired API key, 400 malformed request body (bad date filters, empty query), 429 rate limit, or 5xx server-side outage.","commonSituations":"Wrong-tier API key lacking search access; malformed search_before_date_filter values; hitting rate limits during bursts; transient Perplexity outages.","solutions":["Read the status and body in the message: 401 → fix the API key; 429 → add backoff/retry; 400 → fix the request payload (query, date filters).","Validate request parameters (query non-empty, ISO-8601 date filter formats) before sending.","Retry on 429/5xx with exponential backoff and a request timeout."],"exampleFix":"// before\nconst res = await search({ query }); // throws on transient 429\n// after\ntry {\n  const res = await search({ query });\n} catch (e) {\n  if (String(e).includes('status 429')) await sleep(backoff);\n  else throw e;\n}","handlingStrategy":"retry","validationCode":"if (!query?.trim()) throw new Error('query must be non-empty before calling Perplexity Search');\nif (search_before_date_filter && !/^\\d{4}-\\d{2}-\\d{2}/.test(search_before_date_filter)) throw new Error('invalid date filter format');","typeGuard":null,"tryCatchPattern":"try {\n  const res = await perplexitySearchRequest(/* ... */);\n} catch (e) {\n  const msg = (e as Error).message;\n  if (/status (429|5\\d\\d)/.test(msg) && attempt < MAX_RETRIES) return retryWithBackoff();\n  if (msg.includes('status 401')) throw new Error('Check PERPLEXITY_API_KEY');\n  throw e;\n}","preventionTips":["Validate query and date-filter formats before each request","Implement exponential backoff for 429/5xx","Log the truncated response body included in the error for diagnostics","Watch Perplexity status for outages"],"tags":["network","http","api","perplexity"],"backgroundTag":"http-error-response","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}