{"record":{"id":"5cb3e634a50b4cf2","repo":"Mintplex-Labs/anything-llm","slug":"res-status-res-statustext-params-json-5cb3e6","errorCode":null,"errorMessage":"${res.status} - ${res.statusText}. params: ${JSON.stringify({ auth: this.middleTruncate(process.env.AGENT_SEARCHAPI_API_KEY, 5), q: query })}","messagePattern":"(.+?) - (.+?)\\. params: (.+?)\\)\\}","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/agents/aibitat/plugins/web-browsing.js","lineNumber":462,"sourceCode":"\n            const engine = process.env.AGENT_SEARCHAPI_ENGINE;\n            const params = new URLSearchParams({\n              engine: engine,\n              q: query,\n            });\n\n            const url = `https://www.searchapi.io/api/v1/search?${params.toString()}`;\n            const { response, error } = await fetch(url, {\n              method: \"GET\",\n              headers: {\n                Authorization: `Bearer ${process.env.AGENT_SEARCHAPI_API_KEY}`,\n                \"Content-Type\": \"application/json\",\n                \"X-SearchApi-Source\": \"AnythingLLM\",\n              },\n            })\n              .then((res) => {\n                if (res.ok) return res.json();\n                throw new Error(\n                  `${res.status} - ${res.statusText}. params: ${JSON.stringify({ auth: this.middleTruncate(process.env.AGENT_SEARCHAPI_API_KEY, 5), q: query })}`\n                );\n              })\n              .then((data) => {\n                return { response: data, error: null };\n              })\n              .catch((e) => {\n                this.super.handlerProps.log(`SearchApi Error: ${e.message}`);\n                return { response: null, error: e.message };\n              });\n            if (error)\n              return `There was an error searching for content. ${error}`;\n\n            const data = [];\n            if (response.hasOwnProperty(\"knowledge_graph\"))\n              data.push(response.knowledge_graph?.description);\n            if (response.hasOwnProperty(\"answer_box\"))\n              data.push(response.answer_box?.answer);","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/a145d4d87d086bdb31d50f9bf9cd9c46d311780c/server/utils/agents/aibitat/plugins/web-browsing.js#L444-L480","documentation":"Thrown inside the SearchApi branch of the web-browsing plugin when fetch to https://www.searchapi.io/api/v1/search returns non-ok. The request authenticates with 'Authorization: Bearer <AGENT_SEARCHAPI_API_KEY>' plus an AnythingLLM source header; the error message includes status, statusText, query, and the key middle-truncated to 5 chars. The adjacent .catch converts it to a logged 'SearchApi Error' and an error string for the agent, so it normally appears as 'There was an error searching for content. ...'.","triggerScenarios":"AGENT_SEARCHAPI_API_KEY absent, invalid, or from the wrong provider (401/403); SearchApi.io credits exhausted or rate-limited (429); unsupported engine value in params (400); searchapi.io service errors (5xx).","commonSituations":"Mixing up keys between SerpApi/SearchApi/Serper.dev env vars; expired credits on the SearchApi plan; .env edited without restarting the server.","solutions":["Set AGENT_SEARCHAPI_API_KEY to a valid searchapi.io key and restart the server; unset keys for providers you do not use so the agent cannot pick them.","Map the status: 401/403 -> key problem; 429 -> credits/rate limit, check dashboard; 400 -> invalid engine parameter.","Test the key out-of-band with the same Bearer header to isolate agent config from provider state."],"exampleFix":"# before\nAGENT_SEARCHAPI_API_KEY=  # empty -> 401 - Unauthorized\n\n# after\nAGENT_SEARCHAPI_API_KEY=<searchapi.io key>\nsystemctl restart anythingllm  # or docker restart","handlingStrategy":"validation","validationCode":"const KEY = process.env.AGENT_SEARCHAPI_API_KEY;\nif (!KEY) {\n  throw new Error(\"AGENT_SEARCHAPI_API_KEY not set — add it to the server .env and restart\");\n}\n// optional cheap pre-flight to fail fast with the provider's own status:\nconst probe = await fetch(\"https://www.searchapi.io/api/v1/search?engine=google_q=q_test\", { headers: { Authorization: `Bearer ${KEY}` } });\nif (probe.status === 401 || probe.status === 403) throw new Error(\"SearchApi key rejected\");","typeGuard":null,"tryCatchPattern":"const out = await webSearch(query);\nif (typeof out === \"string\" && out.includes(\"SearchApi Error\")) {\n  if (/40[13]/.test(out)) rotateKey(\"AGENT_SEARCHAPI_API_KEY\");\n  else if (out.includes(\"429\")) scheduleRetry(query, 60_000); // credits/rate limit\n  else inspectParams(out);\n}","preventionTips":["Use a dedicated searchapi.io key and monitor its credit balance.","Never reuse another provider's key in AGENT_SEARCHAPI_API_KEY.","Restart after key rotation; validate engine params against searchapi.io docs."],"tags":["web-search","searchapi","http-error","api-key","agent-tools"],"backgroundTag":"search-api-http-error","analyzedSha":"a145d4d87d086bdb31d50f9bf9cd9c46d311780c","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}